Posts Tagged source code

Java Decompiler:Getting the source code from java .class file

When we compile  .java file using <code> javac</code>, we get .class file. But we can get the source code from class file, but not the full source code. <code> javap</code>, is the utility which gives details of variables and methods declared in the code.

<code>

C:\Documents and Settings\chirag.jain\Desktop>javac Test.java

C:\Documents and Settings\chirag.jain\Desktop>javap Test
Compiled from “Test.java”
public class Test extends java.lang.Object{
int number;
public Test();
public void sayHello();
}

</code>

 

To get the byte code details, use  <code> javap -c </code>

<code>

C:\Documents and Settings\chirag.jain\Desktop>javap -c Test
Compiled from “Test.java”
public class Test extends java.lang.Object{
int number;

public Test();
Code:
0:   aload_0
1:   invokespecial   #1; //Method java/lang/Object.”<init>”:()V
4:   aload_0
5:   iconst_5
6:   putfield        #2; //Field number:I
9:   return

public void sayHello();
Code:
0:   getstatic       #3; //Field java/lang/System.out:Ljava/io/PrintStream;
3:   ldc     #4; //String Hello
5:   invokevirtual   #5; //Method java/io/PrintStream.println:(Ljava/lang/Str
ing;)V
8:   return

}

</code>

 

, , ,

Leave a comment