aspose file tools*
The moose likes Java in General and the fly likes Uninitialized local variables - do they exist in the bytecode? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Uninitialized local variables - do they exist in the bytecode?" Watch "Uninitialized local variables - do they exist in the bytecode?" New topic
Author

Uninitialized local variables - do they exist in the bytecode?

Sigrid Kajdan
Ranch Hand

Joined: Jan 14, 2007
Posts: 72
Hi,

the "TimeTravel" example in K&B (page 198, assignments chapter)made me curious to look how unitialized method-local variables appear in bytecode (I'm using jclasslib bytecode viewer to view it).

In fact, I see that the int variable day, which is never initialized, does not appear in main's code. Inspecting the local variable table, I see it is not listed either. Yet adding further variables shows that even for such uninitialized variables, slots are reserved (numbering takes them into account), even though, as I said, they are not listed.

Now my question is, are they "still there" somewhere in the bytecode?
Or are they optimized away?

Thanks for your help,
Sigrid
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Although this topic is based on a question in the K&B SCJP book the information you require is beyond the scope of SCJP.

Moving to Java In General (Intermediate).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
 
subject: Uninitialized local variables - do they exist in the bytecode?