aspose file tools*
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 Spring in Action this week in the Spring 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: 9305
    
  17

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: 8927
    
    9

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


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Without the braces you can get this kind of misleading code



This code will actually behave like this

 
Don't get me started about those stupid light bulbs.
 
subject: Doubt in Java coding standard