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>

 

Advertisements

, , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: