This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Confusion With Refernce To Local Variables

 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21386
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic