You can omit curly braces when there is only one statement:
if (condition) statement;
coincides with
if (condition) { statement; }
This is determined by grammar in JLS Chapter 14: Blocks and Statementments . Appropriate production conditions:
IfThenStatement: if ( Expression ) Statement ... Statement: StatementWithoutTrailingSubstatement ... StatementWithoutTrailingSubstatement: Block EmptyStatement ExpressionStatement ...
Lastly, an ExpressionStatement is something like a destination or method call, but not a variable declaration. Variable declarations require a block .
JLS 14.2: Blocks :
A block is a sequence of operators, local class declarations, and local variable operators in braces .
and JLS 14.4: Local variable declaration statements :
Each local variable declaration statement is immediately contained in a block.
Since you are declaring double usuage = ... , you need curly braces in this case:
if(idelTimeStr != null) { double usuage=temp - Double.parseDouble(idelTimeStr); }
not identical
if(idelTimeStr != null) double usuage=temp - Double.parseDouble(idelTimeStr);
With curly braces, your program is syntactically thin, but then you need to consider that the usuage variable is visible only inside the block, so you will need to add more of your code inside the curly braces (or declare and initialize usuage with a default value outside the if block).
In any case, I suggest always using curly braces, even if there is only one statement .