Introduction to Java program. Hello World.java. Java Virtual Machine Architecture and how it is working. JVM class loader, Run time Memory, and Execution Engine.
2. Hello world
• Create a file with extension .java
• Have the following code in the file
• Save the file as “Hello.java”
• Open cmd and move to the file directory
• Compile using javac Hello.java
• Execute using java Hello
class Simple{
public static void main(String args
[]){
System.out.println("Hello Java");
}
}
3. Run time Data – Memory
JVM Architecture
Class Loader
Class
Area
Heap Stack
PC
Register
Native
Method
Stack
Execution Engine
BootStrap Extension Application
4. Class Loader - Loading
• Loading the .class files to memory
Bootstrap – Load RT.jar to Runtime Memory
e.g. In System.out.println(“somevalue”);
System comes from import java.lang package.
This is present in RT.jar
Bootstrap loader tooks the System class from RT.jar to Run time
memory
5. Class Loader
Extension Class Loader
• Will load the classes from the external environment
• i.e., from jre/lib/ext/
• E.g., It will take the ojdbc class file from the jar and load in Memory
Application Class Loader
• Loads the application classes.
• i.e, helloworld.class will be loaded to the memory for processing
6. Class Loader - Linking
Verify
• It will verify the bytecode class files are verified if they conform to
standards
Prepare
• Memory is allocated
Resolve
• All Symbolic References are linked with Actual References
7. Run Time Data Area
Class/Method Area
• Class level static Variables are stored in memory
Heap memory
• Objects and Instances are stored in this memory (e.g., new Employee());
Stack Memory
• Locale variable and Operand stack
• In case of exception, catch block data
8. Run Time Data Area
PC Registers
• Current Executing Instructions and have small data area
Native Method Stacks
• Holds Native Method Information. Methods written in a language
other than Java Programming Language
9. JVM Execution Engine
• Here Byte code which is compiled by compiler is converted into the
machine code
• It will then execute that machine code
Interpreter - Read Byte code and execute one by one
JIT Compiler – When repeated method call present, it will convert the byte code to native code
which will be used for repeated method calls.
Garbage Collector – Responsible for destroying the objects that are no longer used
10. Eclipse
• It is an Integrated Development Environment
https://www.eclipse.org/downloads/packages/