You are on page 1of 13

OOP II

Java
JVM in details
• JVM (Java Virtual Machine) is an abstract machine. It is a
specification that provides runtime environment in which
java bytecode can be executed.
• JVMs are available for many hardware and software
platforms (i.e. JVM is platform dependent).
JVM in details
What is JVM:
• A specification where working of Java Virtual Machine is
specified. Its implementation has been provided by Sun
and other companies.
• An implementation Its implementation is known as JRE
(Java Runtime Environment).
• Runtime Instance Whenever you write java command on
the command prompt to run the java class, an instance
of JVM is created.
JVM in details
What it does:
The JVM performs following operation:
• Loads code
• Verifies code
• Executes code
• Provides runtime environment

JVM provides definitions for the:


• Memory area
• Class file format
• Register set
• Garbage-collected heap
• Fatal error reporting etc.
Internal Architecture of JVM
Internal Architecture of JVM
1) Classloader
• Classloader is a subsystem of JVM that is used to load
class files.

2) Class(Method) Area
• Class(Method) Area stores per-class structures such as
field and method data, the code for methods.
Internal Architecture of JVM
3) Heap
• It is the runtime data area in which objects are allocated.
4) Stack
Java Stack stores frames. It holds local variables and partial
results, and plays a part in method invocation and return.
A new frame is created each time a method is invoked. A
frame is destroyed when its method invocation completes.
Internal Architecture of JVM
5) Program Counter Register
• PC (program counter) register contains the address of the
Java virtual machine instruction currently being
executed.
6) Native Method Stack
• It contains all the native methods used in the application.
Internal Architecture of JVM
7) Execution Engine
It contains:
1) A virtual processor
2) Interpreter: Read bytecode stream then execute the
instructions.
3) Just-In-Time(JIT) compiler: It is used to improve the
performance. JIT compiles parts of the byte code
that have similar functionality at the same time, and
hence reduces the amount of time needed for
compilation.
Just-In-Time(JIT) Compiler
• In the past, most programs written in any language have
had to be recompiled, and sometimes, rewritten for each
computer platform. One of the biggest advantages of
Java is that you only have to write and compile a program
once. The Java on any platform will interpret the
compiled bytecode into instructions understandable by
the particular processor. However, the virtual machine
handles one bytecode instruction at a time. Using the
Java just-in-time compiler (really a second compiler) at
the particular system platform compiles the bytecode
into the particular system code (as though the program
had been compiled initially on that platform). Once the
code has been (re-)compiled by the JIT compiler, it will
usually run more quickly in the computer.
Java Naming Conventions:
Java Naming conventions:
• Java naming convention is a rule to follow as you decide
what to name your identifiers such as class, package,
variable, constant, method etc.
• But, it is not forced to follow. So, it is known as
convention not rule.
• All the classes, interfaces, packages, methods and fields
of java programming language are given according to java
naming convention.
Java Naming Conventions:
Java Naming Conventions:
CamelCase in java naming conventions:
• Java follows camelcase syntax for naming the
class, interface, method and variable.
• If name is combined with two words, second
word will start with uppercase letter always
e.g. actionPerformed(), firstName etc.

You might also like