File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes best practice in naming convention in java programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "best practice in naming convention in java programming " Watch "best practice in naming convention in java programming " New topic
Author

best practice in naming convention in java programming

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
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

Joined: Aug 16, 2005
Posts: 13880
    
  10

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

Jacob, please Show Some Effort.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
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

Joined: Apr 12, 2009
Posts: 449

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"


http://muhammadkhojaye.blogspot.com/
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

Then I hope celebrities never start programming. Apple Martin indeed...
Jilesh Lakhani
Ranch Hand

Joined: Jul 26, 2006
Posts: 49

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


-Jilesh
Universe and Knowledge has no bounderies
Victor Ewert
Greenhorn

Joined: May 28, 2009
Posts: 17
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

Joined: Oct 13, 2005
Posts: 36514
    
  16
Jilesh Lakhani wrote: . . . you can keep static variable in caps . . .
That only applies to public static final fields.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

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

Joined: Oct 13, 2005
Posts: 36514
    
  16
All right, Rob. Private constant FIELDS too.
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
As long as your names are meaningful and are consistent with your convention, it doesn't really matter what convention you use.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best practice in naming convention in java programming
 
Similar Threads
jsp:useBean problem
calling java files from java script
Java Package
Variables declared in upper case
Package naming convention