You are on page 1of 5

My Java Notes (Prepared by Chalapathi Rao Davala)

Java is an object oriented programming language that enables us to create real


world applications and the code reusability feature of java enable software
developers to upgrade the existing applications without rewriting the entire code
of java application
Using Java we can develop Desktop Applications such as acrobat reader, media
player, antivirus etc. Web Applications such as irctc.co.in, yahoo.com etc.
Enterprise Applications such as banking applications. Mobile, Embedded System,
Smart Card, Robotics, Games etc.
Using java we can develop Standalone Applications, web Applications, enterprise
applications, and mobile applications
Java is an object oriented programming language that enables you to create real
world applications and the code reusability feature of java enable software
developers to upgrade the existing applications without rewriting the entire code
of java application.
Java is a purely object orientated programming language; we cant write java
program without class or object
Single line comment: //comment
Multi line comment: /* comments
Comments ..

*/

Java documentation comments: /** description about class or method */


When we install java development kit the following directories are created along
with java run time environment those are bin , demo, include, sample, jre, lib and
etc. bin directory contains tools like javac, javah(every tool is exe file).
Demo contains demonstration files nothing but examples programs. Lib contains
jdk related library files. JRE contains JVM and runtime environment. src contains
source code files of java runtime library.
JRE contains bin and lib only.
Include directory contains jni(java native interface) this useful when java
programs communicate with native languages like c, c++. Java program can call
native methods (those methods which are declared in java whose logic not in
java) by using this native interface.
Java development kit (JDK) = Java development tools (javac and etc) + JRE,
which is used development and execution purpose
JRE= JVM+ run time library, which is execution purpose only
The JDK has as its primary components a collection of programming tools,
including: javac, java, javadoc and etc The JDK also comes with a complete Java
Runtime Environment, usually called a private runtime. It consists of a Java
Virtual Machine and all of the class libraries present in the production
environment, as well as additional libraries only useful to developers, such as the
internationalization libraries and the IDL libraries.

Binary code (0s and 1s) or executable codes (exe files) understand by system
directly, byte code is understood by JVM only and this special to java.
If a java program compiles successfully, without getting any errors, then it
creates .class file with same of source file (.java file)
Java supports two types of environments 1. Compile time 2. Runtime
In the compile time environment, java compiler coverts source file to byte code
instructions (.class file) after compilation we will get .class file containing byte
code. In the run time environment, byte code is given to JVM and JVM loads and
executes .class file and passes the result to hardware along with OS instructions.
After runtime environment output of the program will be displayed.
Q: What is JVM (Java Virtual Machine)?
Java virtual machine is hart of entire java program execution process. Its
responsibility is taking .class file and converting each byte code instructions into
the machine language instructions that can be executed by microprocessor
First of all .java program is converted into .class file consisting of byte code
instructions by the java compiler. Now this .class file is given to JVM, in JVM there
is a module (program) called class loader sub system which performs the
following actions

I.
II.
III.

IV.
V.
VI.

It loads the .class file


Verifies whether all byte code instructions are proper or not (if it finds any
instruction suspicious means doubtful then the execution rejects
immediately. If the byte code instructions are proper then it allocates
necessary memory to execute the program. This memory is divided into 5
parts called runtime data areas which contains data and results
Method area: it is a memory black which stores class code, code of
variables, method code
Heap: this is the area where objects are created. When JVM loads the
class a method and heap area are immediately created
Java Stacks: method code is stored in method area but while running this
method it needs some more memory to stores data and results. This
memory is allocated on java stacks. Java stacks are memory areas where
java methods are executed. While executing methods separate frame will
be created in java stacks. JVM uses a separate thread to execute each
method
PC (Program counter) registers: these are the registers (memory areas)
which contains memory addresses of each method. If there are three
methods 3 PC registers
Native method stacks: java methods are executed in java stacks, native
methods (C,C++ methods) are executed in native method stacks
Execution engine: contains interpreter and JIT (just in time) compiler.
Which are responsible for converting byte code into machine code so that
processer will execute this code. Most of the JVM implementations use
both interpreter and JIT compiler simultaneously to convert the byte code
Put the JVM figure here :

JVM has various sub components internally.

1. Class loader sub system: JVM's class loader sub system performs 3 tasks
a. It loads .class file into memory.
b. It verifies byte code instructions.
c. It allots memory required for the program.
2. Run time data area: This is the memory resource used by JVM and it is
divided into 5 parts
a. Method area: Method area stores class code and method code.
b. Heap: Objects are created on heap.
c. Java stacks: Java stacks are the places where the Java methods are
executed. A Java stack contains frames. On each frame, a separate method is
executed.
d. Program counter registers: The program counter registers store
memory address of the instruction to be executed by the microprocessor.
e. Native method stacks: The native method stacks are places where
native methods (for example, C language programs) are executed. Native
method is a function, which is written in another language other than Java.
3. Native method interface: Native method interface is a program that
connects native methods libraries (C header files) with JVM for executing native
methods.
4. Native method library: holds the native libraries information.
5. Execution engine: Execution engine contains interpreter and JIT compiler,
which covert byte code into machine code. JVM uses optimization technique to
decide which part to be interpreted and which part to be used with JIT compiler.
The Hotspot represent the block of code executed by JIT compiler.
1. A virtual processor
2. Interpreter: Read byte code 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. Here
the term? Compiler? Refers to a translator from the instruction set of a
Java virtual machine (JVM) to the instruction set of a specific CPU.

Q: What is JIT (Just-in-Time) Compilation?


JIT is a part of JVM (java execution engine) which increases the speed of
execution of java program by converting byte code into machine code. It is works
simultaneously with java interpreter
Q: How can you say java programs are WORA?
WORA: Write once runs anywhere. Once we write program in java environment
that is compiled only once and can be executed any no of times on any other
platforms (without recompilation)
.class file doesnt contain any OS instructions; it contains byte code instructions
compiled by java compiler. Without OS instructions java program cant be
executed by on OS. These OS instructions are given by a separate program
called JVM (java virtual machine); JVM is platform dependent program for each
and every OS a separate JVM is available. In java orientation java programs are
never communicate directly with OS, between java program and OS there is a
mediator program called JVM. So java programs are WORA (write once and run
anywhere)

Q: what is the difference between JVM, JRE, JDK?


JVM (Java Virtual Machine) is an abstract machine. It is a specification that
provides runtime environment in which java byte code can be executed.
JVMs are available for many hardware and software platforms. JVM, JRE and JDK
are platform dependent because configuration of each OS differs. But, Java is
platform independent.
The JVM performs following main tasks:
Loads code

Verifies code

Executes code

Provides runtime environment

JRE: JRE (Java Runtime Environment) it is used to provide runtime environment.


It is the implementation of JVM. It physically exists. It contains set of libraries +
other files that JVM uses at runtime. Implementation of JVMs are also actively
released by other companies besides Sun Micro Systems.
JDK: The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software
that you can use to develop Java based software. The "JRE" is the Java Runtime
Environment. I.e., the JRE is an implementation of the Java Virtual Machine which
actually executes Java programs. Typically, each JDK contains one (or more) JRE's
along with the various development tools like the Java source compilers,
bundling and deployment tools, debuggers, development libraries, etc

JVM Full Figure:

You might also like