This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decompiled Code different from Acutual Code

 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey People, I just joined the forum,
I'm learning Java from Head First Java. It told me to join the forum and I think that suggestion was very helpful.

I just wanted to know I made a small program in which i created 3 objects and defined their sizes. Then I made a method which they had to follow. But when i decompiled the class i got something different.

I made :



and when i decompiled i got :




I just wanted to ask why did and similar code to that change to ???

I just wanted to ask this for my knowledge.

Thanks.......

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you compile with the "g" flag (for debug info), the local variable names are not stored in the .class file. When Java decompiles, it doesn't know what the original names were and makes some up.
 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne, Now I understood it. Its like my reference variable has a different name but it refers to the correct objects.

Thanks
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note also that the Java compiler does some optimizations etc., and it's not always possible to get the exact same code back when you decompile a compiled class file. The decompiled source will ofcourse function the same way as the original source, but it's not always possible to get the exact statements that were in the original source code.

The transformation that the compiler does from source code to byte code is not completely reversible.
 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper......now i understood whats the reason behind the jvm changing the source code......

And today was my first day at java ranch.....I just want to tell that

Java Ranch simply rocks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic