File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best practice in naming convention in java programming

 
jacob deiter
Ranch Hand
Posts: 580
  • 0
  • 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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob, please Show Some Effort.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47270
52
  • 0
  • 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().
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • 0
  • 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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I hope celebrities never start programming. Apple Martin indeed...
 
Jilesh Lakhani
Ranch Hand
Posts: 49
Java Python Ubuntu
  • 0
  • 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
 
Victor Ewert
Greenhorn
Posts: 17
  • 0
  • 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
Sheriff
Pie
Posts: 47270
52
  • 0
  • 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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • 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
Sheriff
Pie
Posts: 47270
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right, Rob. Private constant FIELDS too.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • 0
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic