This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Decompiled Code different from Acutual Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Decompiled Code different from Acutual Code" Watch "Decompiled Code different from Acutual Code" New topic
Author

Decompiled Code different from Acutual Code

Arjun Bajaj
Greenhorn

Joined: Apr 21, 2010
Posts: 13
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Arjun Bajaj
Greenhorn

Joined: Apr 21, 2010
Posts: 13
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Arjun Bajaj
Greenhorn

Joined: Apr 21, 2010
Posts: 13
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
 
 
subject: Decompiled Code different from Acutual Code
 
Similar Threads
To which class, object is refering to?
Moving from A of beginning to B of beginning
Is it "Exception at runtime" or "Compile Fails" for this one?
how to accept an instance of a class as a parameter
what is the problem with my java code