1

I have extracted a .class file from the rt.jar file in jre1.7, and have attempted to open it using notepad++, however it is unreadable. How can I decompile the .class file into a .java file so I can view the code?

Please note that I am interested in the decompilation of the code, not viewing the source code provided in the JDK downloads.

Chris O'Kelly
  • 1,863
  • 2
  • 18
  • 35
love with java
  • 123
  • 2
  • 10
  • 4
    Why don't you use the source zip file which comes with the JDK? – Jon Skeet Apr 12 '12 at 12:43
  • 1
    Refer to this question: http://stackoverflow.com/questions/4379050/where-to-get-full-source-code-for-rt-jar-jre-6-update-22 – alxbrd Apr 12 '12 at 12:46
  • @Mr.Skeet with all due respect you provide an alternative to the solution.But what i am asking ,is there any way to decomplile the .class file into .java file – love with java Apr 12 '12 at 12:49
  • Why would you want to decompile the .class file when you can just open the original .java file that was used to build it, as @JonSkeet suggested? – wattostudios Apr 12 '12 at 12:55
  • @saurabhRai: In most cases, if you don't have *access* to the source code for a class file, you get into tricky legal territory if you start to decompile it, depending on your legal jurisdiction. Why would you want to get into that if you *really* only want access to source code which is already available? Note that the real source will be easier to read than decompiled code, due to comments etc. – Jon Skeet Apr 12 '12 at 12:58
  • @WATTO just for curiosity ,i want to know to the process for decompiling .class file into .java file – love with java Apr 12 '12 at 12:59
  • @Mr. Skeet as i am beginner in java so i was just curious to know the decompilation process,nothing else. Now i think i should stop thinking in this direction and focus on other necessary java related things.Anyways ,thanks for your response and suggestion – love with java Apr 12 '12 at 13:06

4 Answers4

2

As @Jon Skeet said, don't use JRE but JDK, which contains the entire source code. If you for some reason insist on your approach, then I recommend JD-GUI for decompilation.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
0

.class files are the compiled binary files. You can't read the Java code from them, but you can run them. If you want to see the source you usually need .java files. These are either packed in the same jar but then the src folder, or they can be downloaded in a seperate package.

Joost
  • 3,169
  • 2
  • 22
  • 40
0

You can use any decompiler tool like cavaj for decompiling a class file to source code (java file). I'm using it, and it works perfectly.

Kamal Nayan
  • 1,890
  • 21
  • 34
0

Try any of the decompilers listed here:

Or use online decompiler - http://www.javadecompilers.com/

Andrew Rukin
  • 959
  • 11
  • 16