aspose file tools*
The moose likes Beginning Java and the fly likes A Confusion With Refernce To Local Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A Confusion With Refernce To Local Variables" Watch "A Confusion With Refernce To Local Variables" New topic
Author

A Confusion With Refernce To Local Variables

Ranji Sura
Ranch Hand

Joined: Oct 28, 2012
Posts: 84

4.12.3 Kinds of Variables (7) Local Variables - JLS
The local variable with an initializing expression is not
initialized, however, until the local variable declaration statement that declares
it is executed.


What does this mean ? Please help me to understand this ?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4363
    
    8

I think it just means:


I have to say, though, that if you're a beginner I'd recommend steering well clear of the Java Language Specification. It's not written for beginners. It's useful as a reference for the exact behaviour of parts of the language if you've already got a good understanding. But it's terrible as a learning resource. Stick to the tutorials and books until you feel very confident with the language.

Parts of the JLS are OK, and parts will give even an expert developer a serious headache.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18715
    
  40

Ranjith Suranga wrote:

4.12.3 Kinds of Variables (7) Local Variables - JLS
The local variable with an initializing expression is not
initialized, however, until the local variable declaration statement that declares
it is executed.


What does this mean ? Please help me to understand this ?



It is generally a good idea to not take stuff out of context.

7. Local variables are declared by local variable declaration statements (§14.4).
Whenever the flow of control enters a block (§14.2) or for statement
(§14.14), a new variable is created for each local variable declared in a local
variable declaration statement immediately contained within that block or for
statement.
A local variable declaration statement may contain an expression which
initializes the variable. The local variable with an initializing expression is not
initialized, however, until the local variable declaration statement that declares
it is executed. (The rules of definite assignment (§16) prevent the value of
a local variable from being used before it has been initialized or otherwise
assigned a value.)
The local variable effectively ceases to exist when the
execution of the block or for statement is complete.


The sentence before it kinda qualifies it a bit. And the sentence after it kinda explains why. Basically, it is saying that the local variable can't be used until initialization is complete.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Consider Paul's rocket mass heater.
 
subject: A Confusion With Refernce To Local Variables