Results 1 to 8 of 8

Thread: Convert .class back to .java file

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    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.

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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.

  3. #3

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    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...

  4. #4
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Convert .class back to .java file

    Are you talking about decompiling?

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Convert Class

    Quote 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.

  6. #6
    Addicted Member
    Join Date
    Jun 2002
    Location
    Far.. far away! (Netherlands)
    Posts
    169

    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

  7. #7
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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

  8. #8
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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
  •  



Click Here to Expand Forum to Full Width