javac, we get .class file. But we can get the source code from class file, but not the full source code.  javap, is the utility which gives details of variables and methods declared in the 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();
}
To get the byte code details, use
 javap -c 
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.””:()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
}
  
No comments:
Post a Comment