• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

best practice in naming convention in java programming

 
Ranch Hand
Posts: 594
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jacob, please Show Some Effort.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then I hope celebrities never start programming. Apple Martin indeed...
 
Ranch Hand
Posts: 49
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right, Rob. Private constant FIELDS too.
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic