aspose file tools*
The moose likes Java in General and the fly likes Statement Vs Block Level variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Statement Vs Block Level variable" Watch "Statement Vs Block Level variable" New topic

Statement Vs Block Level variable

Chandra shekar M
Ranch Hand

Joined: Dec 20, 2006
Posts: 135
In java Statement level variable means

for(int i=0;i<10;i++) "i" as in this for loop. Block level variable means some thing like { int j; } which is inside the braces.

Is this the difference between Block and Statement level variable in java

Greg Brannon

Joined: Oct 24, 2010
Posts: 557
I've not heard the term "statement-" or "block-level variables" in Java, but I'm always learning.

Here is the authoritative discussion of variables in Java. I believe that 'i' and 'j' in both of your examples would be called 'local variables.' The 'i' is local to the for loop; the 'j' is local to the block of code in which it is contained. Neither are visible outside their respective localities.

Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38363
The Java Language Specification is more authorative than the tutorials, and here there is no mention of block- or statement-level variables. For the purposes of that definition, a for statement and a block are regarded as the same, so you cannot distinguish block or statement variables.
I agree. Here's the link:
subject: Statement Vs Block Level variable