08 March 2019

Decompiling Java

Simple example:

public class Hola {

    public static void main(String[] args) {


        double pi = 3.14156;
       
        System.out.println("pi="+pi);
       
    }
}


Using javap -c can be solved:

$ javap -c Hola.class Compiled from "Hola.java"
public class Hola {
  public Hola();
    Code:
       0: aload_0      
       1: invokespecial #8                  // Method java/lang/Object."":()V
       4: return       

  public static void main(java.lang.String[]);
    Code:
       0: ldc2_w        #16                 // double 3.14156d
       3: dstore_1     
       4: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
       7: new           #24                 // class java/lang/StringBuilder
      10: dup          
      11: ldc           #26                 // String pi=
      13: invokespecial #28                 // Method java/lang/StringBuilder."":(Ljava/lang/String;)V
      16: dload_1      
      17: invokevirtual #31                 // Method java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder;
      20: invokevirtual #35                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      23: invokevirtual #39                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      26: return       
}



javap -verbose MyClass | grep "major"
to know java version.
 


No comments :

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.