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 Doubt in Java coding standard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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: 9291
    
  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: 8843
    
    7

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: 9291
    
  17

Without the braces you can get this kind of misleading code



This code will actually behave like this

 
jQuery in Action, 2nd edition
 
subject: Doubt in Java coding standard
 
Similar Threads
servlet mapping acting differently after deploying to server
Are the inline conditionals to tough for a junior programmer ?
HFSJ Mock Exam question on error-page tag
getting NullPointerException
NullPointerException...