• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java coding convensions

 
Ravi Danum
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

What is a good source for: 1) Java naming convenTions, and 2) Java coding conventions. So far, I have seen one dated 1999 from Sun. Is there anything newer and something which contains coding conventions such as Exception handling?

Thanks.

Ravi
 
Vikas Kapoor
Ranch Hand
Posts: 1374
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know of no more recent coding conventions, but there is a style guide on JavaRanch here. Beware: It is much more restrictive than the Sun guide. Until somebody (teacher or employer) imposes a style guide on you, you can use your own. But make sure to be consistent.

Campbell's rule about Exceptions: the number of different opinions is equal to the number of different people asked You will find a different opinion in the Java Tutorials, and maybe in the links at the bottom of the article quoted earlier.
 
Ravi Danum
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help.

Ravi
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Tage Nielsen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done some google searches, and found about 4 or 5 style guides, all of them have similar rules, though the placement of the opening bracket { after classes, methods, loops, etc appear contentions.

Since I am new to Java and it appears that this 'ranch' is a great resource I'm going to use the JavaRanch's style guide for self-study, and for posting here.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Tage Nielsen.

Many of use prefer to put the opening brace (better term than bracket for {) { on its own line because the { and } are then aligned vertically like thisThat makes them easier to read. I heard that the style where the opening brace is not on its own line (on Wikipedia they called that K&R indentation after Kernighan and Ritchie [not me]) was devised to save space when printing on paper. People who are used to K&R seem to find no difficulty reading their code.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic