AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-compiler: How to convert class file in java source code?

I have one .class file, i want to see the java source code for that file. Please give me an example to convert that class file in java source code.

java x 211
compiler x 5
Posted On : 2016-04-23 17:57:40.0
profile Rishi Kumar - anyforum.in Rishi Kumar
523188241268
up-rate
5
down-rate

Answers


JD-Core:
------------------------
is a library that reconstructs Java source code from one or more ".class" files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type "enum", are supported. JD-GUI and JD-Eclipse include JD-Core library.


JD-GUI:
---------------------------
is a standalone graphical utility that displays Java source codes of ".class" files. You can browse the reconstructed source code with the JD-GUI for instant access to methods and fields.


JD-Eclipse:
-------------------------------------
is a plug-in for the Eclipse platform. It allows you to display all the Java sources during your debugging process, even if you do not have them all.

JD-IntelliJ:
-----------------------------
is a plug-in for... the IntilliJ IDE.



Let´s see very simple example using JD-core library. To download JD-Core library for windows- click her. This zip file contains two files:

1. jad.exe
2. Readme.txt

Unzip jad.zip file into any appropriate directory on your hard drive. I extracted it on Desktop in jad158g.win folder. I just created very simple java file that is A.java:

A.java:
--------------------------------------
class A
{
public static void main(String s1[])
{
System.out.println("Hello");
}
}

Just using javac tool I got .class file and placed it into jad158g.win folder located on Desktop. Now open command prompt and point the folder containing jad.exe file and .class file like below:


C:\Users\Anyforum\Desktop\jad158g.win>jad A.class
Parsing A.class... Generating A.jad

Open newly generated .jad file in notepad. Let´s see what i got for above java file:

A.jad:
------------------------------
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: A.java

import java.io.PrintStream;

class A
{

A()
{
}

public static void main(String args[])
{
System.out.println("Hello");
}
}


So .jad file contains the valid source code, It might not be same as you write in java file because java compiler adds something in .class file as you can see in above example "default constructor"(if you don´t write any constructor in java file compiler adds default constructor by itself). If you want to generate .java file use below command:

C:\Users\Anyforum\Desktop\jad158g.win>jad -sjava A.class
Parsing A.class... Generating A.java

It´ll generate A.java file containing the java source code of A.class file. Refer Readme.txt file for more control or help command.

Posted On : 2016-04-23 18:38:34
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129549188
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in