|
-
Dec 27th, 2004, 10:02 AM
#1
Thread Starter
Addicted Member
Convert .class back to .java file
Hi
Anyone know the steps to convert the class file back to the original java file..
Say i have one file call example.class..
Thanks
Last edited by toytoy; Dec 27th, 2004 at 12:27 PM.
-
Dec 27th, 2004, 11:55 AM
#2
Frenzied Member
Re: Convert Class
I don't understand your question. Are you wanting to do something equivilant to undo? I mean, did you mess up and accidently compile? You could just delete the class file and recompile or something.
-
Dec 27th, 2004, 12:24 PM
#3
Thread Starter
Addicted Member
Re: Convert Class
I heard from my friends that i could use some methods to get back from the classes file back to the .java files...
but they are not sure how to convert back.....indeed it can be done..
I know i can re-compile the java file to get back the class but....
I am curious and want to learn new thing so i just try but don't know the steps to start it...
-
Dec 27th, 2004, 12:40 PM
#4
Frenzied Member
Re: Convert .class back to .java file
Are you talking about decompiling?
-
Dec 27th, 2004, 12:44 PM
#5
Frenzied Member
Re: Convert Class
 Originally Posted by toytoy
I heard from my friends that i could use some methods to get back from the classes file back to the .java files...
I've heard about this too, but I really don't know how. Maybe someone else does. Anyways I'll try researching it, and see what I can find.
-
Dec 27th, 2004, 01:42 PM
#6
Addicted Member
Re: Convert .class back to .java file
You can use the DJ program, it works quite well, although your comments and layout will be gone, as those aren't stored in the class files.
http://members.fortunecity.com/neshkov/dj.html
-
Dec 27th, 2004, 05:21 PM
#7
Dazed Member
Re: Convert .class back to .java file
There is a built in decompiler called javap. For instance if you want to decompile a .class file named Search you would do the following at the command line. C:\jdk1.5.0\bin> javap -classpath C:\; Search.class
-
Dec 27th, 2004, 05:51 PM
#8
Dazed Member
Re: Convert .class back to .java file
You will notice that if you run the decompiler on a .class file the output will have no implementation. Running C:\jdk1.5.0\bin> javap -classpath C:\; D on the code below will give you the following. If you want to get the disassembled code, i.e., the instructions that comprise the Java bytecodes then you can run javap with the -c switch C:\jdk1.5.0\bin> javap -c -classpath C:\; D
Code:
public class D extends java.lang.Object{
public D();
public static void main(java.lang.String[]);
}
Code:
class DeTest{
private String greeting = "Hello";
public void changeGreeting(String greeting){
this.greeting = greeting;
}
public void printGreeting(){
System.out.println(greeting);
}
}
public class D{
public static void main(String[] args){
DeTest dt = new DeTest();
dt.printGreeting();
dt.changeGreeting("Goodbye");
dt.printGreeting();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|