This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Doubt in Java coding standard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt in Java coding standard" Watch "Doubt in Java coding standard" New topic
Author

Doubt in Java coding standard

Siva gurun
Greenhorn

Joined: Dec 15, 2008
Posts: 19
Hi All,

Is there any standard like, we need to use braces for if-else statement, even, "if" or "else" statement contains a single line?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9327
    
  19

Siva it is a good practice to use braces even if you have only single statement inside if else block. It makes the code more readable...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 9072
    
    9

Ankit's right. Have a look at the Code Conventions for the Java Programming Language:


[How To Ask Questions On JavaRanch]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9327
    
  19

Without the braces you can get this kind of misleading code



This code will actually behave like this

 
 
subject: Doubt in Java coding standard