*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 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: 8836
    
    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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
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...