Lecture 4
Lecture 4
2
Content
(Unit I)
Principles of Object-Oriented Programming
Chapter 1.1:
Lecture1.1.4-
1. First Java Program
2. JVM Architecture
3
Objectives/Outcomes
4
First Java Program
• The requirements for Java Program
execution:
• Install the JDk
• Set path of the jdk/bin directory.
• Create the java program
• Compile the java program
• Run the java Program
5
Executing Java Program
• To execute the java program
• Open command prompt
• select the folder where the program file
is saved
• write command: javac Hello.java
• upper command is used to compile the
program
• Write : java Hello
• java then class name (Hello) executes
the program and displays the output
6
Compilation Flow
7
Parameters used in First Java
Program
8
Parameters used in First Java
Program contd.
• void is the return type of the method. It means it doesn't return any value.
• main represents the starting point of the program.
• String[] args is used for command line argument. We will learn it later.
• System.out.println() is used to print statement. Here, System is a class, out is the
object of PrintStream class, println() is the method of PrintStream class. We will
learn about the internal working of System.out.println statement later.
9
JVM
• JVM (Java Virtual Machine) is an abstract machine. It is a specification that
provides runtime environment in which java bytecode can be executed.
• JVM is a part of Java Run Environment (JRE).
• In other programming languages, the compiler produces machine code for a
particular system. However, Java compiler produces code for a Virtual Machine
known as Java Virtual Machine.
• JVM is responsible for allocating memory space.
Fig 2: JVM[2]
10
JVM Architecture
11
JVM Architecture Contd.
1. ClassLoader : The class loader is a subsystem used for loading class files. It
performs three major functions viz. Loading, Linking, and Initialization.
2. Method Area: JVM Method Area stores class structures like metadata, the
constant runtime pool, and the code for methods.
3. Heap: All the Objects, their related instance variables, and arrays are stored in
the heap. This memory is common and shared across multiple threads.
12
JVM Architecture Contd.
4. JVM language Stacks: Java language Stacks store local variables, and it’s
partial results. Each thread has its own JVM stack, created simultaneously as
the thread is created. A new frame is created whenever a method is invoked,
and it is deleted when method invocation process is complete.
5. PC Registers: PC register store the address of the Java virtual machine
instruction which is currently executing. In Java, each thread has its separate
PC register.
13
JVM Architecture Contd.
6. Native Method Stacks: Native method stacks hold the instruction of native
code depends on the native library. It is written in another language instead of
Java.
7. Execution Engine: It is a type of software used to test hardware, software, or
complete systems. The test execution engine never carries any information
about the tested product.
8. Native Method Interface: The Native Method Interface is a programming
framework. It allows Java code which is running in a JVM to call by libraries
and native applications.
9. Native Method Libraries: Native Libraries is a collection of the Native
Libraries(C, C++) which are needed by the Execution Engine.
14
Difference
Fig 4: Differences[4]
15
References
• https://www.javatpoint.com/simple-program-of-java
• https://www.digimat.in/nptel/courses/video/106105191/L03.html
• https://www.geeksforgeeks.org/jvm-works-jvm-architecture/
• https://www.guru99.com/java-virtual-machine-jvm.html
• https://www.javatpoint.com/difference-between-jdk-jre-and-jvm
• https://www.guru99.com/difference-between-jdk-jre-jvm.htm
16
References
• Fig 1: Image source: https://www.javatpoint.com/simple-program-of-java
• Fig 2: https://www.guru99.com/java-virtual-machine-jvm.html.
• Fig 3: https://www.guru99.com/java-virtual-machine-jvm.html.
• Fig 4: https://www.guru99.com/difference-between-jdk-jre-jvm.htm
17
THANK YOU