• Post Reply Bookmark Topic Watch Topic
  • New Topic

best practice in naming convention in java programming  RSS feed

 
Ranch Hand
Posts: 588
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Sheriff
Posts: 16083
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 21291
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob, please Show Some Effort.
 
Marshal
Posts: 58470
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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"
 
Rob Spoor
Sheriff
Posts: 21291
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I hope celebrities never start programming. Apple Martin indeed...
 
Ranch Hand
Posts: 49
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 58470
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

That only applies to public static final fields.
 
Rob Spoor
Sheriff
Posts: 21291
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Campbell Ritchie
Marshal
Posts: 58470
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right, Rob. Private constant FIELDS too.
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as your names are meaningful and are consistent with your convention, it doesn't really matter what convention you use.
 
Author and ninkuma
Marshal
Posts: 66542
160
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
lowercase baba
Bartender
Posts: 12613
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!