Forums Register Login

best practice in naming convention in java programming

+Pie Number of slices to send: Send
Anyone please share best practice in naming convention in java programming such as

1) Class Name
2) Method name
3) Parameter Name
4) Interface Name
5) Helper Class
6) Wrapper Class
7) Exception class

If I missed any things please address those also
+Pie Number of slices to send: Send
Have a look at Code Conventions for the Java Programming Language - this seems to be the de facto coding standard for Java, almost all projects that I've worked on use the conventions from that document.
+Pie Number of slices to send: Send
Jacob, please Show Some Effort.
+Pie Number of slices to send: Send
The names of identifiers should make their meanings obvious.

Find the conventions for JavaBeans about get and set methods.
Methods with a boolean return type usually start with "is" or "has".
Exception classes should end with Exception, similarly Listeners should have XXXListener at the end of their names.
Methods which return an instance are usually called getInstance().
+Pie Number of slices to send: Send
 

jacob deiter wrote:Anyone please share best practice in naming convention in java programming such as

1) Class Name
2) Method name
3) Parameter Name
4) Interface Name
5) Helper Class
6) Wrapper Class
7) Exception class

If I missed any things please address those also



See Robert C. Martin "Clean Code" (Chap 2 & 3) where at one point it says "You should name a variable using the same care with which you name a first-born child"
+Pie Number of slices to send: Send
Then I hope celebrities never start programming. Apple Martin indeed...
+Pie Number of slices to send: Send
Well, naming convention is upto the developers
to keep this very simple and straight, write the name of the methods / classes readable.

you can keep static variable in caps
Classes starting with capital alphabet.

you can figure our more, once you start coding.
Best of Luck
+Pie Number of slices to send: Send
Another thing I do with Lists and Iterator is append List to List objects and ListItr to the Iterator for the list.

e.g.




One of the main things is, that once you have got your convention, stick to it religiously. You'll be glad you did later on when looking back at you code, trying to debug some issue

Victor Ewert
Ewert Technologies
+Pie Number of slices to send: Send
 

Jilesh Lakhani wrote: . . . you can keep static variable in caps . . .

That only applies to public static final fields.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:

Jilesh Lakhani wrote: . . . you can keep static variable in caps . . .

That only applies to public static final fields.


I'd say "static final fields", sans the "public". Private constants should be capitalized as well.
+Pie Number of slices to send: Send
All right, Rob. Private constant FIELDS too.
+Pie Number of slices to send: Send
As long as your names are meaningful and are consistent with your convention, it doesn't really matter what convention you use.
+Pie Number of slices to send: Send
 

Rusty Shackleford wrote:As long as your names are meaningful and are consistent with your convention, it doesn't really matter what convention you use.


I disagree. You're not the only one that's ever going to look at your code. Using pretty much the same conventions that the majority of Java developers use is important for working as part of a team or for any other type of collaboration.
+Pie Number of slices to send: Send
I would say that the single most important thing is to follow whatever standard your company has. Even if it's the most borked up convention in the world, at least everything in the codebase will be consistantly borked up. If it's all the same, a developer can get their head wrapped around it easier than if everyone writes their code a little different.

If your company doesn't have a standard, then the Sun convention is the de facto one to use.
Don't MAKE me come back there with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7212 times.
Similar Threads
Package naming convention
calling java files from java script
jsp:useBean problem
Java Package
Variables declared in upper case
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:34:58.