Helloworld.java is our first program to learn Java, simple can no longer simple, but the principle of the inside and the implementation process everyone knows? Recently in the review of Java Knowledge, specially delve into a share to everyone!
The code to post the HelloWorld is as follows:
Class HelloWorld { void// definition string s
Analyze Memory Graphs:
HelloWorld the specific implementation process:
1. Execute Helloworld.java file, generate Helloworld.class bytecode file;
2. The virtual machine executes the Helloworld.class and loads the class into memory (that is, in the class code area of the method area);
3. The virtual machine finds the main method of HelloWorld through the class (the entry method of the program), the access permission is public (publicly available), the virtual machine passes string[] (string array object: Empty array) The address of the type parameter to the main method of args, And in the stack area for the args open memory space, return a void return value;
4. Define a string (the standard class library) type of variable (in the stack space) s,s value is undefined (garbage value, compilation cannot pass);
5. S = "Hello world!", object "Hello world!" Space is created in the constant data area of the method area, which is: Hello world!, the method is: toString (), the variable s holds the object "Hello world!" 's address;
6. The virtual machine finds the System.class class in the standard class library and loads it into memory (that is, in the class code area of the method area), System.out to the standard byte output stream object (), and calls the println () method to print the value of the variable s to the screen.
PS: When the virtual machine calls the Main method, three default objects are created: System.out (standard byte output stream object), system.in (standard byte input stream object), and System.error (standard byte Error stream object).
The above total involves:
1 Java files: Helloworld.java
4 class classes: Helloworld.class, String[].class, String.class, System.class
5 objects: "Hello world!", string[], System.out, system.in, System.error
2 variables: args, S
3 methods: Main (), toString (), println ()
Java Hello World