• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Java coding standard

 
Siva gurun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Joe Ess
Bartender
Posts: 9298
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit's right. Have a look at the Code Conventions for the Java Programming Language:
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without the braces you can get this kind of misleading code



This code will actually behave like this

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic