You are on page 1of 27

15CSE202 Object oriented Programming

15CSE202 Object Oriented Programming


Lecture 3

Overview of JDK

Nalinadevi Kadiresan
CSE Dept.
Amrita School of Engg.
15CSE202 Object oriented Programming 2

HelloWorld Java program - Recap

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 3

HelloWorld Program
public class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World");
}
} • Save this file as HelloWorld.java
• To compile: javac HelloWorld.java
• To execute: java HelloWorld
• Output: Hello world

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 4

Compiling and Running

javac HelloWorld.java
HelloWorld.java
compile

source code
HelloWorld.class

bytecode
java HelloWorld
run
June 2019 Nalinadevi Kadiresan
15CSE202 Object oriented Programming 5

JavaSE/JDK
• Before you can develop an application written in the Java
programming language, you will need the
Java Platform Standard Edition (Java SE) development kit.

• It has the necessary Java Virtual Machine (JVM), core


Application Programming Interfaces (API)s, and the
compiler you'll need for most and perhaps all of your
development.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 6

Java SE/JDK

• The JDK includes a compiler and an


interpreter
• The compiler for Java language to
generate the architecture- natural
bytecodes.
• The interpreter executes the
standalone java application.
June 2019 Nalinadevi Kadiresan
15CSE202 Object oriented Programming 7

Java SE/JDK
• JDK consists of Java Runtime Environment(JRE) +
compiler, debuggers

JRE

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming

JRE
Java Runtime Environment(JRE):
• 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.
15CSE202 Object oriented Programming

JVM
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. 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
15CSE202 Object oriented Programming 10

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 11

JVM
Java program at run time
Classloader: is the subsystem of JVM that
is used to load class files.

Bytecode Verifier: checks the code fragments


for illegal code that can violate access right to
objects.
Interpreter: read bytecode stream then execute the
instructions.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 12

JVM Architecture

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 13

JVM Architecture
1. Class Loader: 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.
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.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 14

JVM Architecture
5. 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.
6. 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.
7. 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.
8. Native Method Libraries: Native Libraries is a collection of the Native
Libraries(C, C++) which are needed by the Execution Engine.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 15

C program Compilation and


Execution

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 16

Java Program Compilation and


Execution

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 17

Java Program Compilation and


Execution
• The Java VM or Java Virtual Machine resides on the RAM.
• During execution, using the class loader the class files are brought on
the RAM.
• The BYTE code is verified for any security breaches.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 18

Java Program Compilation and


Execution
• Next, the execution engine will convert the Bytecode into Native machine code.
– This is just-in-time compiling(JIT).
• It is one of the main reason why Java is comparatively slow.
• It interprets part of the Byte Code that has similar functionality at the
same time.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 19

Java vs Python
Java Python
Java is a compiled language Python is a interpreted language

Java is a OO language Python is a multi-paradigm


language – OO and functional

Java is statically typed (Type Python is dynamically typed


checking at compile time) (Type checking at runtime)
Java implements concurrency Python implements concurrency
with multithreading at process level.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 20

Java vs Python – Execution


Speed

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 21

Java vs Python – Legacy system

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 22

Java vs Python – practical agility

• Refactoring is a controlled technique for improving the design of an


existing code base.
• small, manageable steps that incrementally increase the cleanliness
of code while still maintaining the functionality of the code
June 2019 Nalinadevi Kadiresan
15CSE202 Object oriented Programming 23

Java vs Python
• Choosing which language to goes with depends on
your company’s needs, and which setbacks you’re
willing to accept.

– While Java churns out higher performance speed, Python is


more suited to evolve legacy systems.

– When it comes to practical agility, Java is a more proven


option, while Python has more flexibility for experimentation.

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 24

Java vs Python

Courtesy: https://stackify.com/java-vs-python/
https://www.edureka.co/blog/java-vs-python/

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming

Supplemental reading
• Getting Started
http://java.sun.com/docs/books/tutorial/getStarted/index.html

• Nuts and bolts of the Java Language


http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html

• Compiling and Running a Simple Program

http://developer.java.sun.com/developer/onlineTraining/Programming/
BasicJava1/compile.html
15CSE202 Object oriented Programming 26

Object Oriented Development


• First Goal: Model the objects of the world
– Noun-oriented
– Focus on the domain of the program
• Phases
– Object-Oriented Analysis: understand the domain
• Define an object-based model of it
– Object-Oriented Design: Define an implementation
• Design the solution
– Object-Oriented Programming: Build it

June 2019 Nalinadevi Kadiresan


15CSE202 Object oriented Programming 27

Next Session will be


Object Oriented Analysis

June 2019 Nalinadevi Kadiresan

You might also like