Let's consider the following piece of code:
package p;
public class Simple {
public static void main(String[] args){
System.out.println("HELLO!\n");
}
}
and JVM code for that ( javap -c Simple.class
):
Compiled from "Simple.java"
public class p.Simple {
public p.Simple();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3 // String HELLO!\n
5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
}
And I have a questions:
Probably, the entry point is the
main
function. But, before that, it is neccesary to invoke a constructor for Simple class. So, how does it work? I mean, who calls firstly the construactor and then pass a control tomain
? If I am wrong please explain me how the control flow works.Instructions like
getstatic
take arguments like#2
. What does it mean#2
?Comment looks like:
// Method java/lang/Object."<init>":()V
What does it meanV
?How does the control flow work?