File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30753
    
156

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: 14268
    
  21

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 8 API documentation
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decompiled Code different from Acutual Code