SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Java Compiler and Runtime
Omar Bashir
@OmarBashir_40 obashir@yahoo.com
Java: Write Once Run Anywhere
Java Source Code (.java files)
Java: Write Once Run Anywhere
Java Source Code (.java files) Java Compiler
Java: Write Once Run Anywhere
Java Source Code (.java files) Java Compiler Java Bytecode (.class files)
Java: Write Once Run Anywhere
Java Source Code (.java files) Java Compiler Java Bytecode (.class files)
Java Virtual Machine
Java: Write Once Run Anywhere
Java Source Code (.java files) Java Compiler Java Bytecode (.class files)
Java Virtual Machine
Interpreted
platform specific
instructions
Any Hardware
Java Virtual Machine (JVM)
● A virtual computer that executes Java bytecode.
– A platform specific program giving Java its platform
independence.
● Key JVM concepts,
– Specification
● Abstract definition omitting irrelevant implementation details.
– Implementation
● Platform specific implementation that executes bytecode.
– Instance
● Each Java application is executed in a separate JVM instance.
● Launched by executing the java command.
Java HotSpotTM
Virtual Machine
● Oracle's/Sun's JVM implementation.
● Key features
– JIT (Just In Time) compilation
● Compilation of specific program sections to native instructions
and caching them.
– Adaptive optimisation
● Dynamic recompilation of program sections based on current
execution profiles.
● Generational garbage collection
– Disposing unused objects and reclaiming memory.
JVM Architecture
Class Loader
Compiled
Classes
JVM Runtime Memory
Heap
Method Area
Java Stack
Native Method Stack
Program Counter Registers
Execution Engine Native Interface
Native
Libraries
Thread common memory Thread specific memory
Code Cache
JVM Architecture
Thread common memory Thread specific memoryThread common memory
Dynamic on demand loading of Java
classes from the classpath
1. Loading bytecode,
2. Linking,
3. Variable initialisation
Class Loader
Compiled
Classes
JVM Runtime Memory
Heap
Method Area
Java Stack
Native Method Stack
Program Counter Registers
Execution Engine Native Interface
Native
Libraries
Code Cache
JVM Architecture
Thread common memory Thread specific memory
Heap contains
instances of classes,
i.e., objects. Heap is
garbage collected to
remove unused objects.
Class Loader
Compiled
Classes
JVM Runtime Memory
Heap
Method Area
Java Stack
Native Method Stack
Program Counter Registers
Execution Engine Native Interface
Native
Libraries
Code Cache
JVM Architecture
Thread common memory Thread specific memory
Method Area stores
information regarding
loaded classes, their
fields, methods and
values of class
variables. Also referred
to as Perm Gen, it no
longer exists in Java 8.
Class Loader
Compiled
Classes
JVM Runtime Memory
Heap
Method Area
Java Stack
Native Method Stack
Program Counter Registers
Execution Engine Native Interface
Native
Libraries
Code Cache
JVM Architecture
Thread common memory Thread specific memory
Code cache stores
methods that have
been compiled to
native code.
Class Loader
Compiled
Classes
JVM Runtime Memory
Heap
Method Area
Java Stack
Native Method Stack
Program Counter Registers
Execution Engine Native Interface
Native
Libraries
Code Cache
JVM Architecture
Thread common memory Thread specific memory
Stacks are per thread memory
frames organised in LIFO (Last
In First Out) structure.
Class Loader
Compiled
Classes
JVM Runtime Memory
Heap
Method Area
Java Stack
Native Method Stack
Program Counter Registers
Execution Engine Native Interface
Native
Libraries
Code Cache
JVM Architecture
Thread common memory Thread specific memory
Program counter and three
registers manage the stack.
Stack-oriented design helps
keep the JVM's instruction set
and implementation small.
Program counter tracks
instructions to be executed.
optop register points to the top
of operand stack, the
workspace.
frame register points to
operations of the stack.
vars register points to the local
variables sections.
Class Loader
Compiled
Classes
JVM Runtime Memory
Heap
Method Area
Java Stack
Native Method Stack
Program Counter Registers
Execution Engine Native Interface
Native
Libraries
Code Cache
JRE
Java Runtime Environment (JRE)
JVM
Java Class
Library
Package needed to run a Java application
JDK
Java Development Kit (JDK)
JRE
JVM
Java Class
Library
Java
Development
Tools
javac – Java Compiler
● Part of JDK
● Reads Java class and interface files and compiles
them into bytecode class files.
– Source files have .java extensions.
– Bytecode files have .class extensions.
● Syntax
– javac [options] [sources] [classes] [@argfiles]
● options: Command line options.
● sources: Source files.
● classes: Classes to be processed for annotations.
● argfiles: Files listing options and source files.
javac – Java Compiler
● Most frequently used options,
– -cp: Classpath, i.e., path to dependencies.
– -d: directory containing the compiled classes.
– -deprecation: Shows a description of each use of
a deprecated member or class.
– -g: Generate debugging information.
javac – Java Compiler (Example)
code
bin
src
app
calc
CalcApp.java
Calculator.java
javac src/*/*.java ­d bin 
javac – Java Compiler (Example)
code
bin
src
app
calc
CalcApp.java
Calculator.java
app
calc
CalcApp.class
Calculator.class
java – Launch Java Application in JVM
● Syntax
– java [options] main-class [arguments …]
– java [options] -jar file.jar [arguments …]
● Most frequently used options,
– -cp: Classpath, path to libraries and class files.
– -Dproperty=value: set a system property.
– -Xmsn: Minimum heap size.
– -Xmxn: Maximum heap size.
– -Xssn: Stack size.
java Demo
jar – Java Archive
● Grouping class files into libraries and java executables.
– Convenient packaging and deployment.
– Based on the zip file format.
– Command syntax closely related to tar
● Syntax
– Creation,
● jar cf jarfile input-files
● jar cmf manifest jarfile input-files
– Extraction
● jar xf jarfile
● Manifests provide,
– Versioning, signing, specifying classpaths, java executable.
jar Demo
Garbage Collection
● JVM relieves coders from deleting unused objects.
● Unused objects are deleted from the heap by the
Garbage Collector (GC).
– i.e., objects whose reference is not assigned to any variable.
● Each application has two threads at least,
– Thread running main,
– Thread running GC.
● When the GC thread runs, all other threads may pause
(Dependant on GC implementation).
– GC's execution is non-deterministic.
– Results in Java not being suitable for applications with strict
timing constraints (i.e., real-time applications).
Garbage Collection
Marking
Deletion
Compaction
Referenced
Unreferenced
Free
Garbage Collection
● Young generation
– New objects created.
– Minor garbage collection removes dead objects.
– Surviving objects aged and moved to old generation.
● Old generation
– Long surviving objects.
– Major garbage collection removes dead objects.
● Permanent generation
– Metadata of methods and classes for the JVM
Eden S0 S1Eden Tenured Permanent
Young Generation
Survivor
Space
Old Generation Permanent Generation
Garbage Collection
Example
import java.util.ArrayList;
import java.util.List;
public class DemoGc {
public static void main(String[] args) {
    wait1Minute();
for(int i = 0 ; i < 1000000; i++) {
List<Double> products = new ArrayList<Double>();
for(int j = 0; j < 1000; j++) {
products.add(i * j * 1.0);
}
System.out.print("***** " + i + "r");
}
}
  private static void wait1Minute() {
    try {
      Thread.sleep(60000);
    } catch (Exception exp) {}
  }
}
Garbage Collection Example
java ­Xms512m ­Xmx1024m DemoGc
An Introduction to Java Compiler and Runtime

Más contenido relacionado

La actualidad más candente

Core Java Slides
Core Java SlidesCore Java Slides
Core Java SlidesVinit Vyas
 
使用 Apache IoTDB 构建工业时序数据管理解决方案的实践
使用 Apache IoTDB 构建工业时序数据管理解决方案的实践使用 Apache IoTDB 构建工业时序数据管理解决方案的实践
使用 Apache IoTDB 构建工业时序数据管理解决方案的实践ZhangZhengming
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Mr. Akaash
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Memory management ppt
Memory management pptMemory management ppt
Memory management pptManishaJha43
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machineLaxman Puri
 
Java Presentation
Java PresentationJava Presentation
Java Presentationaitrichtech
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State TransferPeter R. Egli
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysisRicha Sharma
 

La actualidad más candente (20)

Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Core Java
Core JavaCore Java
Core Java
 
Java presentation
Java presentation Java presentation
Java presentation
 
Testing Spring Applications
Testing Spring ApplicationsTesting Spring Applications
Testing Spring Applications
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 
使用 Apache IoTDB 构建工业时序数据管理解决方案的实践
使用 Apache IoTDB 构建工业时序数据管理解决方案的实践使用 Apache IoTDB 构建工业时序数据管理解决方案的实践
使用 Apache IoTDB 构建工业时序数据管理解决方案的实践
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Memory management ppt
Memory management pptMemory management ppt
Memory management ppt
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Yacc
YaccYacc
Yacc
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Core java
Core javaCore java
Core java
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State Transfer
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 

Similar a An Introduction to Java Compiler and Runtime

It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enGeorge Birbilis
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machineNikhil Sharma
 
Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...
Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...
Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...Rhythm Suiwal
 
A Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVMA Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVMBRNSSPublicationHubI
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunningguest1f2740
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance TunningTerry Cho
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecturesubnesh
 
JVM, JRE and Javac are the main part for the java program
 JVM, JRE and Javac are the main part for the java program JVM, JRE and Javac are the main part for the java program
JVM, JRE and Javac are the main part for the java programsiyaram ray
 
Lecture 2 Java Virtual Machine .pptx
Lecture 2 Java Virtual Machine .pptxLecture 2 Java Virtual Machine .pptx
Lecture 2 Java Virtual Machine .pptxAnupamKumar559254
 
Android Training Chandigarh
Android Training ChandigarhAndroid Training Chandigarh
Android Training ChandigarhSheetal Sharma
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting StartedRakesh Madugula
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, androidi i
 

Similar a An Introduction to Java Compiler and Runtime (20)

Java Basic PART I
Java Basic PART IJava Basic PART I
Java Basic PART I
 
It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_en
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Basic Java I
Basic Java IBasic Java I
Basic Java I
 
Java JVM
Java JVMJava JVM
Java JVM
 
Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...
Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...
Introduction of jvm|Java Training In Jaipur | Java Training Jaipur | Java Tra...
 
A Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVMA Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVM
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecture
 
JVM, JRE and Javac are the main part for the java program
 JVM, JRE and Javac are the main part for the java program JVM, JRE and Javac are the main part for the java program
JVM, JRE and Javac are the main part for the java program
 
Lecture 2 Java Virtual Machine .pptx
Lecture 2 Java Virtual Machine .pptxLecture 2 Java Virtual Machine .pptx
Lecture 2 Java Virtual Machine .pptx
 
Android Training Chandigarh
Android Training ChandigarhAndroid Training Chandigarh
Android Training Chandigarh
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 
Java JDK.docx
Java JDK.docxJava JDK.docx
Java JDK.docx
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
Run time data areas
Run time data areasRun time data areas
Run time data areas
 

Más de Omar Bashir

Cloud migration challenges london ct os
Cloud migration challenges   london ct osCloud migration challenges   london ct os
Cloud migration challenges london ct osOmar Bashir
 
5 Software Development Lessons From a Mountaineer
5 Software Development Lessons From a Mountaineer5 Software Development Lessons From a Mountaineer
5 Software Development Lessons From a MountaineerOmar Bashir
 
Technology Agility
Technology AgilityTechnology Agility
Technology AgilityOmar Bashir
 
Quality Loopback
Quality LoopbackQuality Loopback
Quality LoopbackOmar Bashir
 
Achieving Technological Agility
Achieving Technological AgilityAchieving Technological Agility
Achieving Technological AgilityOmar Bashir
 
Technical Debt: Measured and Implied
Technical Debt: Measured and ImpliedTechnical Debt: Measured and Implied
Technical Debt: Measured and ImpliedOmar Bashir
 
Distilling Agile for Effective Execution
Distilling Agile for Effective ExecutionDistilling Agile for Effective Execution
Distilling Agile for Effective ExecutionOmar Bashir
 
Authorisation: Concepts and Implementation
Authorisation: Concepts and ImplementationAuthorisation: Concepts and Implementation
Authorisation: Concepts and ImplementationOmar Bashir
 
Coding for 11 Year Olds
Coding for 11 Year OldsCoding for 11 Year Olds
Coding for 11 Year OldsOmar Bashir
 
High Speed Networks - Applications in Finance
High Speed Networks - Applications in FinanceHigh Speed Networks - Applications in Finance
High Speed Networks - Applications in FinanceOmar Bashir
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8Omar Bashir
 
Computing at Schools: A Guide to Parents
Computing at Schools: A Guide to ParentsComputing at Schools: A Guide to Parents
Computing at Schools: A Guide to ParentsOmar Bashir
 
Information technology
Information technologyInformation technology
Information technologyOmar Bashir
 
Maths with Programming
Maths with ProgrammingMaths with Programming
Maths with ProgrammingOmar Bashir
 
Code Club Talk 2014
Code Club Talk 2014Code Club Talk 2014
Code Club Talk 2014Omar Bashir
 

Más de Omar Bashir (17)

Cloud migration challenges london ct os
Cloud migration challenges   london ct osCloud migration challenges   london ct os
Cloud migration challenges london ct os
 
5 Software Development Lessons From a Mountaineer
5 Software Development Lessons From a Mountaineer5 Software Development Lessons From a Mountaineer
5 Software Development Lessons From a Mountaineer
 
Why Java ?
Why Java ?Why Java ?
Why Java ?
 
Technology Agility
Technology AgilityTechnology Agility
Technology Agility
 
Quality Loopback
Quality LoopbackQuality Loopback
Quality Loopback
 
Achieving Technological Agility
Achieving Technological AgilityAchieving Technological Agility
Achieving Technological Agility
 
Technical Debt: Measured and Implied
Technical Debt: Measured and ImpliedTechnical Debt: Measured and Implied
Technical Debt: Measured and Implied
 
Distilling Agile for Effective Execution
Distilling Agile for Effective ExecutionDistilling Agile for Effective Execution
Distilling Agile for Effective Execution
 
Authorisation: Concepts and Implementation
Authorisation: Concepts and ImplementationAuthorisation: Concepts and Implementation
Authorisation: Concepts and Implementation
 
SOLID Java Code
SOLID Java CodeSOLID Java Code
SOLID Java Code
 
Coding for 11 Year Olds
Coding for 11 Year OldsCoding for 11 Year Olds
Coding for 11 Year Olds
 
High Speed Networks - Applications in Finance
High Speed Networks - Applications in FinanceHigh Speed Networks - Applications in Finance
High Speed Networks - Applications in Finance
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8
 
Computing at Schools: A Guide to Parents
Computing at Schools: A Guide to ParentsComputing at Schools: A Guide to Parents
Computing at Schools: A Guide to Parents
 
Information technology
Information technologyInformation technology
Information technology
 
Maths with Programming
Maths with ProgrammingMaths with Programming
Maths with Programming
 
Code Club Talk 2014
Code Club Talk 2014Code Club Talk 2014
Code Club Talk 2014
 

Último

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 

Último (20)

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 

An Introduction to Java Compiler and Runtime

  • 1. Java Compiler and Runtime Omar Bashir @OmarBashir_40 obashir@yahoo.com
  • 2. Java: Write Once Run Anywhere Java Source Code (.java files)
  • 3. Java: Write Once Run Anywhere Java Source Code (.java files) Java Compiler
  • 4. Java: Write Once Run Anywhere Java Source Code (.java files) Java Compiler Java Bytecode (.class files)
  • 5. Java: Write Once Run Anywhere Java Source Code (.java files) Java Compiler Java Bytecode (.class files) Java Virtual Machine
  • 6. Java: Write Once Run Anywhere Java Source Code (.java files) Java Compiler Java Bytecode (.class files) Java Virtual Machine Interpreted platform specific instructions Any Hardware
  • 7. Java Virtual Machine (JVM) ● A virtual computer that executes Java bytecode. – A platform specific program giving Java its platform independence. ● Key JVM concepts, – Specification ● Abstract definition omitting irrelevant implementation details. – Implementation ● Platform specific implementation that executes bytecode. – Instance ● Each Java application is executed in a separate JVM instance. ● Launched by executing the java command.
  • 8. Java HotSpotTM Virtual Machine ● Oracle's/Sun's JVM implementation. ● Key features – JIT (Just In Time) compilation ● Compilation of specific program sections to native instructions and caching them. – Adaptive optimisation ● Dynamic recompilation of program sections based on current execution profiles. ● Generational garbage collection – Disposing unused objects and reclaiming memory.
  • 9. JVM Architecture Class Loader Compiled Classes JVM Runtime Memory Heap Method Area Java Stack Native Method Stack Program Counter Registers Execution Engine Native Interface Native Libraries Thread common memory Thread specific memory Code Cache
  • 10. JVM Architecture Thread common memory Thread specific memoryThread common memory Dynamic on demand loading of Java classes from the classpath 1. Loading bytecode, 2. Linking, 3. Variable initialisation Class Loader Compiled Classes JVM Runtime Memory Heap Method Area Java Stack Native Method Stack Program Counter Registers Execution Engine Native Interface Native Libraries Code Cache
  • 11. JVM Architecture Thread common memory Thread specific memory Heap contains instances of classes, i.e., objects. Heap is garbage collected to remove unused objects. Class Loader Compiled Classes JVM Runtime Memory Heap Method Area Java Stack Native Method Stack Program Counter Registers Execution Engine Native Interface Native Libraries Code Cache
  • 12. JVM Architecture Thread common memory Thread specific memory Method Area stores information regarding loaded classes, their fields, methods and values of class variables. Also referred to as Perm Gen, it no longer exists in Java 8. Class Loader Compiled Classes JVM Runtime Memory Heap Method Area Java Stack Native Method Stack Program Counter Registers Execution Engine Native Interface Native Libraries Code Cache
  • 13. JVM Architecture Thread common memory Thread specific memory Code cache stores methods that have been compiled to native code. Class Loader Compiled Classes JVM Runtime Memory Heap Method Area Java Stack Native Method Stack Program Counter Registers Execution Engine Native Interface Native Libraries Code Cache
  • 14. JVM Architecture Thread common memory Thread specific memory Stacks are per thread memory frames organised in LIFO (Last In First Out) structure. Class Loader Compiled Classes JVM Runtime Memory Heap Method Area Java Stack Native Method Stack Program Counter Registers Execution Engine Native Interface Native Libraries Code Cache
  • 15. JVM Architecture Thread common memory Thread specific memory Program counter and three registers manage the stack. Stack-oriented design helps keep the JVM's instruction set and implementation small. Program counter tracks instructions to be executed. optop register points to the top of operand stack, the workspace. frame register points to operations of the stack. vars register points to the local variables sections. Class Loader Compiled Classes JVM Runtime Memory Heap Method Area Java Stack Native Method Stack Program Counter Registers Execution Engine Native Interface Native Libraries Code Cache
  • 16. JRE Java Runtime Environment (JRE) JVM Java Class Library Package needed to run a Java application
  • 17. JDK Java Development Kit (JDK) JRE JVM Java Class Library Java Development Tools
  • 18. javac – Java Compiler ● Part of JDK ● Reads Java class and interface files and compiles them into bytecode class files. – Source files have .java extensions. – Bytecode files have .class extensions. ● Syntax – javac [options] [sources] [classes] [@argfiles] ● options: Command line options. ● sources: Source files. ● classes: Classes to be processed for annotations. ● argfiles: Files listing options and source files.
  • 19. javac – Java Compiler ● Most frequently used options, – -cp: Classpath, i.e., path to dependencies. – -d: directory containing the compiled classes. – -deprecation: Shows a description of each use of a deprecated member or class. – -g: Generate debugging information.
  • 20. javac – Java Compiler (Example) code bin src app calc CalcApp.java Calculator.java javac src/*/*.java ­d bin 
  • 21. javac – Java Compiler (Example) code bin src app calc CalcApp.java Calculator.java app calc CalcApp.class Calculator.class
  • 22. java – Launch Java Application in JVM ● Syntax – java [options] main-class [arguments …] – java [options] -jar file.jar [arguments …] ● Most frequently used options, – -cp: Classpath, path to libraries and class files. – -Dproperty=value: set a system property. – -Xmsn: Minimum heap size. – -Xmxn: Maximum heap size. – -Xssn: Stack size.
  • 24. jar – Java Archive ● Grouping class files into libraries and java executables. – Convenient packaging and deployment. – Based on the zip file format. – Command syntax closely related to tar ● Syntax – Creation, ● jar cf jarfile input-files ● jar cmf manifest jarfile input-files – Extraction ● jar xf jarfile ● Manifests provide, – Versioning, signing, specifying classpaths, java executable.
  • 26. Garbage Collection ● JVM relieves coders from deleting unused objects. ● Unused objects are deleted from the heap by the Garbage Collector (GC). – i.e., objects whose reference is not assigned to any variable. ● Each application has two threads at least, – Thread running main, – Thread running GC. ● When the GC thread runs, all other threads may pause (Dependant on GC implementation). – GC's execution is non-deterministic. – Results in Java not being suitable for applications with strict timing constraints (i.e., real-time applications).
  • 28. Garbage Collection ● Young generation – New objects created. – Minor garbage collection removes dead objects. – Surviving objects aged and moved to old generation. ● Old generation – Long surviving objects. – Major garbage collection removes dead objects. ● Permanent generation – Metadata of methods and classes for the JVM Eden S0 S1Eden Tenured Permanent Young Generation Survivor Space Old Generation Permanent Generation