Well, if you're interested, why not look at the byte code generated by the compiler
class HelloWorld { private String hello = "Hello world!"; private void printHello(){ System.out.println (this.hello); } public static void main (String args[]){ HelloWorld hello = new HelloWorld(); hello.printHello(); }
}
Compile with
% JAVA_HOME% / bin / javac HelloWorld.java
Get bytecode with
javap -c HelloWorld
change add output
enter code here HelloWorld(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":() 4: aload_0 5: ldc #2; //String Hello world! 7: putfield #3; //Field hello:Ljava/lang/String; 10: return public static void main(java.lang.String[]); Code: 0: new #6; //class HelloWorld 3: dup 4: invokespecial #7; //Method "<init>":()V 7: astore_1 8: aload_1 9: invokespecial #8; //Method printHello:()V 12: return
}
source share