I just had a look into the grammar of Java found on oracle.com: Chapter 18. Syntax.
(I hope it is the correct version which applies to the question.)
Statement:
Block
;
Identifier : Statement
StatementExpression ;
if ParExpression Statement [else Statement]
assert Expression [: Expression] ;
switch ParExpression { SwitchBlockStatementGroups }
while ParExpression Statement
do Statement while ParExpression ;
for ( ForControl ) Statement
break [Identifier] ;
continue [Identifier] ;
return [Expression] ;
throw Expression ;
synchronized ParExpression Block
try Block (Catches | [Catches] Finally)
try ResourceSpecification Block [Catches] [Finally]
Thus, you can see while
is followed by ParExpression
(expression in parentheses) and Statement
.
For
while(true){
int u =89;
}
the Statement
after of while
s body expands to Block
which in turn may expand to a LocalVariableDeclarationStatement
.
For
while(true)
int u =89; // compile time error
the Statement
of while
s body cannot expand to LocalVariableDeclarationStatement
as there is no Block
.
Thus, the 2nd simply isn't part of the Java language (based on its grammar).