SlideShare a Scribd company logo
Java Virtual Machine

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 1
Java Virtual Machine - start
Java Source Program
Java Source Program

Program
Program
Running
Running

Java ‘Compiler’
Java ‘Compiler’

Program
Program
Running
Running

JVM on LINUX PC
JVM on LINUX PC

Byte
Byte
Code
Code

JVM on Windows PC
JVM on Windows PC
JVM on iMAC
JVM on iMAC
JVM on UNIX
JVM on UNIX

© Katrin Becker
All rights reserved.

Program
Program
Running
Running

Java Virtual Machine

Program
Program
Running
Running
Jan 18, 2014 2
Java Virtual Machine - source
Java Source Program
Java Source Program

© Katrin Becker
All rights reserved.

-Written in standard Java
-Target machine irrelevant
-Doesn’t matter which machine
it’s created on.

Java Virtual Machine

Jan 18, 2014 3
Java Virtual Machine - compile
Java Source Program
Java Source Program
>> javac MyProg.java

Java ‘Compiler’
Java ‘Compiler’
Java ‘compiler’ does syntactic analysis
and parsing.
Translates source into Byte Code
MyProg.class

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 4
Java Virtual Machine - Byte Code
Java Source Program
Java Source Program
Bytecode is
the same for ALL machines
Java ‘Compiler’
Java ‘Compiler’
and ALL versions of Java
Up to this point everything looks
and behaves identically
on ALL machines
Bytecode is assembler-like, but there
Byte
Byte
is no really real machine that
‘understands’ bytecode.
Code
Code
Called Bytecode because most
instructions are one or two
bytes long
© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 5
Java Virtual Machine – ready-set-..
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

•Bytecode can be transported to
any machine with a bytecode
interpreter [called the “Java
Virtual Machine”]
•Assemblers run on real
machines, so…..
•Java Bytecode runs on a
“Virtual Machine”

Java Virtual Machine

Jan 18, 2014 6
Java Virtual Machine – go
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

•The Virtual Machine is like a
simulator – it simulates a real
machine, but…
•It also ‘tells’ the real machine
on which it is currently running
to do the stuff the virtual
machine would be doing
•This requires it to be ‘tailormade’ for the machine it is
running on…

Java Virtual Machine

Jan 18, 2014 7
Java Virtual Machine - Linux
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’
JVM on LINUX PC
JVM on LINUX PC

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 8
Java Virtual Machine – Linux-b
Java Source Program
Java Source Program

Program
Program
Running
Running

Java ‘Compiler’
Java ‘Compiler’
JVM on LINUX PC
JVM on LINUX PC

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 9
Java Virtual Machine - Windows
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

JVM on Windows PC
JVM on Windows PC

Java Virtual Machine

Jan 18, 2014 10
Java Virtual Machine – Windows-b
Java Source Program
Java Source Program
Program
Program
Running
Running

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

JVM on Windows PC
JVM on Windows PC

Java Virtual Machine

Jan 18, 2014 11
Java Virtual Machine - iMAC
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

JVM on iMAC
JVM on iMAC

Java Virtual Machine

Jan 18, 2014 12
Java Virtual Machine – iMAC-b
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code

© Katrin Becker
All rights reserved.

Program
Program
Running
Running
JVM on iMAC
JVM on iMAC

Java Virtual Machine

Jan 18, 2014 13
Java Virtual Machine - UNIX
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code
JVM on UNIX
JVM on UNIX
© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 14
Java Virtual Machine – UNIX-b
Java Source Program
Java Source Program

Java ‘Compiler’
Java ‘Compiler’

Byte
Byte
Code
Code
JVM on UNIX
JVM on UNIX
© Katrin Becker
All rights reserved.

Java Virtual Machine

Program
Program
Running
Running
Jan 18, 2014 15
Java Virtual Machine ..TA-Da
Java Source Program
Java Source Program

Program
Program
Running
Running

Java ‘Compiler’
Java ‘Compiler’

Program
Program
Running
Running

JVM on LINUX PC
JVM on LINUX PC

Byte
Byte
Code
Code

JVM on Windows PC
JVM on Windows PC
JVM on iMAC
JVM on iMAC
JVM on UNIX
JVM on UNIX

© Katrin Becker
All rights reserved.

Program
Program
Running
Running

Java Virtual Machine

Program
Program
Running
Running
Jan 18, 2014 16
Once more from the top
A slightly different
perspective….

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 17
Java Source :: JVM -1
JVM source written in C
JVM source written in C

Somebody writes the “Java Virtual Machine”;
Jim Gosling probably wrote the first one.

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 18
Java Source :: JVM -2
JVM source written in C
JVM source written in C

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

JVM.c gets compiled to produce….

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 19
Java Source :: JVM -3
JVM source written in C
JVM source written in C

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’
JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

There has to be a specially tailored
one of these for the specific
machine we are currently using.

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 20
Java Source :: JVM –3b
JVM source written in C
JVM source written in C

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’
JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

The ‘Java Virtual Machine’ is now
ready to be used (invoked).
It can sit around on the system
indefinitely.
© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 21
Java Source :: JVM -4
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

Along comes My
Program,
written in Java

© Katrin Becker
All rights reserved.

JVM source written in C
JVM source written in C

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’
JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

Java Virtual Machine

Jan 18, 2014 22
Java Source :: JVM -5
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

JVM source written in C
JVM source written in C

Java ‘Compiler’
Java ‘Compiler’

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

>> javac MyProg.java
Results in…..

JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

The Java compiler gets invoked –
It takes standard Java source as input
And produces standard Java ByteCode as output
© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 23
Java Source :: JVM -6
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

JVM source written in C
JVM source written in C

Java ‘Compiler’
Java ‘Compiler’

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

Byte
Byte
Code
Code

JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

Now I am free to take my MyProg.class to
any computer I choose,
Any brand; any flavour; anywhere in the world
PROVIDED…
It has a working JVM.exe
© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 24
Java Source :: JVM –6b
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

JVM source written in C
JVM source written in C

Java ‘Compiler’
Java ‘Compiler’

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

Byte
Byte
Code
Code

JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

When I say:
>> java MyProg.class

© Katrin Becker
All rights reserved.

The target machine loads, and then starts to
run the
Java Virtual Machine….
Java Virtual Machine

Jan 18, 2014 25
Java Source :: JVM -7
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

JVM source written in C
JVM source written in C

Java ‘Compiler’
Java ‘Compiler’

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

Byte
Byte
Code
Code

JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

Machine-dependent
Machine-dependent
Linker/Loader
Linker/Loader

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 26
Java Source :: JVM -8
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

JVM source written in C
JVM source written in C

Java ‘Compiler’
Java ‘Compiler’

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

Byte
Byte
Code
Code

JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

Machine-dependent
Machine-dependent
Linker/Loader
Linker/Loader

The JVM expects
a file containing
ByteCode as input
© Katrin Becker
All rights reserved.

‘Java’ Program
‘Java’ Program
Running bytecode
Running bytecode
as input
as input

Java Virtual Machine

Jan 18, 2014 27
Java Source :: JVM -9
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

JVM source written in C
JVM source written in C

Java ‘Compiler’
Java ‘Compiler’

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

Byte
Byte
Code
Code

MyProg.class
MyProg.class
Program
Program
Running
Running
© Katrin Becker
All rights reserved.

The output
JVM.exe
JVM.exe
from the JVM
(executable version of
(executable version of
is the output
JVM)
JVM)
that your
program
Machine-dependent
Machine-dependent
produces
Linker/Loader
Linker/Loader
(unless of
course the
‘Java’ Program
‘Java’ Program JVM detects a
Running bytecode
Running bytecode problem)
as input
as input
Java Virtual Machine

Jan 18, 2014 28
Java Source :: JVM -10
Java Source Program:
Java Source Program:
MyProg.java
MyProg.java

JVM source written in C
JVM source written in C

Java ‘Compiler’
Java ‘Compiler’

C compiler compiles ‘JVM.c’
C compiler compiles ‘JVM.c’

Byte
Byte
Code
Code

JVM.exe
JVM.exe
(executable version of
(executable version of
JVM)
JVM)

Machine-dependent
Machine-dependent
Linker/Loader
Linker/Loader

MyProg.class
MyProg.class
Program
Program
Running
Running
© Katrin Becker
All rights reserved.

‘Java’ Program
‘Java’ Program
Running bytecode
Running bytecode
as input
as input

Java Virtual Machine

MyProg
MyProg
output
output
Jan 18, 2014 29
The end.

© Katrin Becker
All rights reserved.

Java Virtual Machine

Jan 18, 2014 30

More Related Content

PPTX
Java virtual machine
PPTX
Jvm Architecture
PPTX
Java byte code presentation
PPTX
Java architecture
PDF
What is-java
PPT
Byte code jvm
PDF
Java Virtual Machine - Internal Architecture
Java virtual machine
Jvm Architecture
Java byte code presentation
Java architecture
What is-java
Byte code jvm
Java Virtual Machine - Internal Architecture

What's hot (20)

PPTX
DOCX
Java Tutorial to Learn Java Programming
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
DOCX
JDK,JRE,JVM
PDF
Java unit 1
PPT
1 Introduction To Java Technology
PDF
The Real Thing: Java Virtual Machine
DOCX
Introduction to java
PDF
Java and Java platforms
PPTX
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
PPTX
Introduction to Java Programming
PDF
Java introduction
PPTX
JAVA ENVIRONMENT
PPTX
QSpiders - Jdk Jvm Jre and Jit
PDF
Learn Java Part 1
ODP
Java compilation
PDF
Java Tutorial to Learn Java Programming
Introduction to Java Programming, Basic Structure, variables Data type, input...
JDK,JRE,JVM
Java unit 1
1 Introduction To Java Technology
The Real Thing: Java Virtual Machine
Introduction to java
Java and Java platforms
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
Introduction to Java Programming
Java introduction
JAVA ENVIRONMENT
QSpiders - Jdk Jvm Jre and Jit
Learn Java Part 1
Java compilation
Ad

Viewers also liked (20)

PDF
Introduction to virtualization
PDF
Android Lesson 2
PPT
Virtual machine
PPT
Virtual machine subhash gupta
ODP
Android App Development - 02 Activity and intent
PPTX
Android development session 2 - intent and activity
PDF
Hypervisors and Virtualization - VMware, Hyper-V, XenServer, and KVM
PPTX
Virtual machine
PPTX
PDF
Virtualization and cloud Computing
PDF
Virtualization presentation
PPT
Virtualization in cloud computing ppt
PPTX
Virtualization 101: Everything You Need To Know To Get Started With VMware
PDF
What Makes Great Infographics
PDF
Masters of SlideShare
PDF
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
PDF
You Suck At PowerPoint!
PDF
10 Ways to Win at SlideShare SEO & Presentation Optimization
PDF
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
PDF
How to Make Awesome SlideShares: Tips & Tricks
Introduction to virtualization
Android Lesson 2
Virtual machine
Virtual machine subhash gupta
Android App Development - 02 Activity and intent
Android development session 2 - intent and activity
Hypervisors and Virtualization - VMware, Hyper-V, XenServer, and KVM
Virtual machine
Virtualization and cloud Computing
Virtualization presentation
Virtualization in cloud computing ppt
Virtualization 101: Everything You Need To Know To Get Started With VMware
What Makes Great Infographics
Masters of SlideShare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
You Suck At PowerPoint!
10 Ways to Win at SlideShare SEO & Presentation Optimization
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How to Make Awesome SlideShares: Tips & Tricks
Ad

Similar to CS Lesson: Introduction to the Java virtual Machine (20)

PDF
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
PDF
Put your Java apps to sleep? Find out how - John Matthew Holt (Waratek)
PPTX
Decapitating Selenium with JavaScript
KEY
PDF
Building your own Desktop Cloud Environment
PDF
Installing vmware server 2.0.2 on windows7
PDF
Create Development and Production Environments with Vagrant
PDF
JRuby on Rails Deployment: What They Didn't Tell You
PDF
JDConf 2025 - Paketo Buildpacks : the best way to build Java container images
PPTX
Java Class1
PDF
Walking through the Spring Stack for Apache Kafka with Soby Chacko | Kafka S...
PDF
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
PPTX
Real time data processing with kafla spark integration
 
PDF
Vagrant for Development
PDF
Installing Endeca Server, Studio, Integrator ETL , Commerce and Platform Serv...
PDF
JavaFX JumpStart @JavaOne 2016
ODP
Puppet Provisioning Vagrant Virtual Machine
PDF
SFScon 21 - Davide Montesin - Typescript vs. Java
PDF
GraalVm and Quarkus
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
Put your Java apps to sleep? Find out how - John Matthew Holt (Waratek)
Decapitating Selenium with JavaScript
Building your own Desktop Cloud Environment
Installing vmware server 2.0.2 on windows7
Create Development and Production Environments with Vagrant
JRuby on Rails Deployment: What They Didn't Tell You
JDConf 2025 - Paketo Buildpacks : the best way to build Java container images
Java Class1
Walking through the Spring Stack for Apache Kafka with Soby Chacko | Kafka S...
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
Real time data processing with kafla spark integration
 
Vagrant for Development
Installing Endeca Server, Studio, Integrator ETL , Commerce and Platform Serv...
JavaFX JumpStart @JavaOne 2016
Puppet Provisioning Vagrant Virtual Machine
SFScon 21 - Davide Montesin - Typescript vs. Java
GraalVm and Quarkus

More from Katrin Becker (20)

PPTX
Cross breeding animation
PPT
Assignments that Meet the Needs of Exceptional Students without Disadvantagin...
PPTX
T.A.P. : The Teach Aloud Protocol
PPTX
Misguided illusions of understanding
PPTX
Signature pedagogy
PPTX
Virtue of Failure
PPTX
4 Pillars of DGBL: A Structured Rating System for Games for Learning
PPTX
Gamification paradigm
PPTX
The Calm and The Storm: Simulation and Games - Why All Games are Simulations ...
PPTX
Gamification how to gamify learning and instruction Part 1 (of 3)
PPTX
Gamification how to gamify learning and instruction, part 2 (of 3)
PPTX
Is gamification a game changer
PPT
CS Example: Parsing a Sentence
PPT
CS: Introduction to Record Manipulation & Indexing
PPT
CS Lesson: Creating Your First Class in Java
PPTX
Informing pedagogy through collaborative inquiry
PPTX
Informing SoTL using playtesting techniques
PPTX
Using cards games as learning objects to teach genetics
PPTX
Gamification how to gamify learning and instruction, Part 3 (of 3)
PPTX
The decorative media trap
Cross breeding animation
Assignments that Meet the Needs of Exceptional Students without Disadvantagin...
T.A.P. : The Teach Aloud Protocol
Misguided illusions of understanding
Signature pedagogy
Virtue of Failure
4 Pillars of DGBL: A Structured Rating System for Games for Learning
Gamification paradigm
The Calm and The Storm: Simulation and Games - Why All Games are Simulations ...
Gamification how to gamify learning and instruction Part 1 (of 3)
Gamification how to gamify learning and instruction, part 2 (of 3)
Is gamification a game changer
CS Example: Parsing a Sentence
CS: Introduction to Record Manipulation & Indexing
CS Lesson: Creating Your First Class in Java
Informing pedagogy through collaborative inquiry
Informing SoTL using playtesting techniques
Using cards games as learning objects to teach genetics
Gamification how to gamify learning and instruction, Part 3 (of 3)
The decorative media trap

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Modernizing your data center with Dell and AMD
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Modernizing your data center with Dell and AMD
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
NewMind AI Weekly Chronicles - August'25 Week I
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm
The AUB Centre for AI in Media Proposal.docx
CIFDAQ's Market Insight: SEC Turns Pro Crypto

CS Lesson: Introduction to the Java virtual Machine

  • 1. Java Virtual Machine © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 1
  • 2. Java Virtual Machine - start Java Source Program Java Source Program Program Program Running Running Java ‘Compiler’ Java ‘Compiler’ Program Program Running Running JVM on LINUX PC JVM on LINUX PC Byte Byte Code Code JVM on Windows PC JVM on Windows PC JVM on iMAC JVM on iMAC JVM on UNIX JVM on UNIX © Katrin Becker All rights reserved. Program Program Running Running Java Virtual Machine Program Program Running Running Jan 18, 2014 2
  • 3. Java Virtual Machine - source Java Source Program Java Source Program © Katrin Becker All rights reserved. -Written in standard Java -Target machine irrelevant -Doesn’t matter which machine it’s created on. Java Virtual Machine Jan 18, 2014 3
  • 4. Java Virtual Machine - compile Java Source Program Java Source Program >> javac MyProg.java Java ‘Compiler’ Java ‘Compiler’ Java ‘compiler’ does syntactic analysis and parsing. Translates source into Byte Code MyProg.class © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 4
  • 5. Java Virtual Machine - Byte Code Java Source Program Java Source Program Bytecode is the same for ALL machines Java ‘Compiler’ Java ‘Compiler’ and ALL versions of Java Up to this point everything looks and behaves identically on ALL machines Bytecode is assembler-like, but there Byte Byte is no really real machine that ‘understands’ bytecode. Code Code Called Bytecode because most instructions are one or two bytes long © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 5
  • 6. Java Virtual Machine – ready-set-.. Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code © Katrin Becker All rights reserved. •Bytecode can be transported to any machine with a bytecode interpreter [called the “Java Virtual Machine”] •Assemblers run on real machines, so….. •Java Bytecode runs on a “Virtual Machine” Java Virtual Machine Jan 18, 2014 6
  • 7. Java Virtual Machine – go Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code © Katrin Becker All rights reserved. •The Virtual Machine is like a simulator – it simulates a real machine, but… •It also ‘tells’ the real machine on which it is currently running to do the stuff the virtual machine would be doing •This requires it to be ‘tailormade’ for the machine it is running on… Java Virtual Machine Jan 18, 2014 7
  • 8. Java Virtual Machine - Linux Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ JVM on LINUX PC JVM on LINUX PC Byte Byte Code Code © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 8
  • 9. Java Virtual Machine – Linux-b Java Source Program Java Source Program Program Program Running Running Java ‘Compiler’ Java ‘Compiler’ JVM on LINUX PC JVM on LINUX PC Byte Byte Code Code © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 9
  • 10. Java Virtual Machine - Windows Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code © Katrin Becker All rights reserved. JVM on Windows PC JVM on Windows PC Java Virtual Machine Jan 18, 2014 10
  • 11. Java Virtual Machine – Windows-b Java Source Program Java Source Program Program Program Running Running Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code © Katrin Becker All rights reserved. JVM on Windows PC JVM on Windows PC Java Virtual Machine Jan 18, 2014 11
  • 12. Java Virtual Machine - iMAC Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code © Katrin Becker All rights reserved. JVM on iMAC JVM on iMAC Java Virtual Machine Jan 18, 2014 12
  • 13. Java Virtual Machine – iMAC-b Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code © Katrin Becker All rights reserved. Program Program Running Running JVM on iMAC JVM on iMAC Java Virtual Machine Jan 18, 2014 13
  • 14. Java Virtual Machine - UNIX Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code JVM on UNIX JVM on UNIX © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 14
  • 15. Java Virtual Machine – UNIX-b Java Source Program Java Source Program Java ‘Compiler’ Java ‘Compiler’ Byte Byte Code Code JVM on UNIX JVM on UNIX © Katrin Becker All rights reserved. Java Virtual Machine Program Program Running Running Jan 18, 2014 15
  • 16. Java Virtual Machine ..TA-Da Java Source Program Java Source Program Program Program Running Running Java ‘Compiler’ Java ‘Compiler’ Program Program Running Running JVM on LINUX PC JVM on LINUX PC Byte Byte Code Code JVM on Windows PC JVM on Windows PC JVM on iMAC JVM on iMAC JVM on UNIX JVM on UNIX © Katrin Becker All rights reserved. Program Program Running Running Java Virtual Machine Program Program Running Running Jan 18, 2014 16
  • 17. Once more from the top A slightly different perspective…. © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 17
  • 18. Java Source :: JVM -1 JVM source written in C JVM source written in C Somebody writes the “Java Virtual Machine”; Jim Gosling probably wrote the first one. © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 18
  • 19. Java Source :: JVM -2 JVM source written in C JVM source written in C C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ JVM.c gets compiled to produce…. © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 19
  • 20. Java Source :: JVM -3 JVM source written in C JVM source written in C C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) There has to be a specially tailored one of these for the specific machine we are currently using. © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 20
  • 21. Java Source :: JVM –3b JVM source written in C JVM source written in C C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) The ‘Java Virtual Machine’ is now ready to be used (invoked). It can sit around on the system indefinitely. © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 21
  • 22. Java Source :: JVM -4 Java Source Program: Java Source Program: MyProg.java MyProg.java Along comes My Program, written in Java © Katrin Becker All rights reserved. JVM source written in C JVM source written in C C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) Java Virtual Machine Jan 18, 2014 22
  • 23. Java Source :: JVM -5 Java Source Program: Java Source Program: MyProg.java MyProg.java JVM source written in C JVM source written in C Java ‘Compiler’ Java ‘Compiler’ C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ >> javac MyProg.java Results in….. JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) The Java compiler gets invoked – It takes standard Java source as input And produces standard Java ByteCode as output © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 23
  • 24. Java Source :: JVM -6 Java Source Program: Java Source Program: MyProg.java MyProg.java JVM source written in C JVM source written in C Java ‘Compiler’ Java ‘Compiler’ C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ Byte Byte Code Code JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) Now I am free to take my MyProg.class to any computer I choose, Any brand; any flavour; anywhere in the world PROVIDED… It has a working JVM.exe © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 24
  • 25. Java Source :: JVM –6b Java Source Program: Java Source Program: MyProg.java MyProg.java JVM source written in C JVM source written in C Java ‘Compiler’ Java ‘Compiler’ C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ Byte Byte Code Code JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) When I say: >> java MyProg.class © Katrin Becker All rights reserved. The target machine loads, and then starts to run the Java Virtual Machine…. Java Virtual Machine Jan 18, 2014 25
  • 26. Java Source :: JVM -7 Java Source Program: Java Source Program: MyProg.java MyProg.java JVM source written in C JVM source written in C Java ‘Compiler’ Java ‘Compiler’ C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ Byte Byte Code Code JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) Machine-dependent Machine-dependent Linker/Loader Linker/Loader © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 26
  • 27. Java Source :: JVM -8 Java Source Program: Java Source Program: MyProg.java MyProg.java JVM source written in C JVM source written in C Java ‘Compiler’ Java ‘Compiler’ C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ Byte Byte Code Code JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) Machine-dependent Machine-dependent Linker/Loader Linker/Loader The JVM expects a file containing ByteCode as input © Katrin Becker All rights reserved. ‘Java’ Program ‘Java’ Program Running bytecode Running bytecode as input as input Java Virtual Machine Jan 18, 2014 27
  • 28. Java Source :: JVM -9 Java Source Program: Java Source Program: MyProg.java MyProg.java JVM source written in C JVM source written in C Java ‘Compiler’ Java ‘Compiler’ C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ Byte Byte Code Code MyProg.class MyProg.class Program Program Running Running © Katrin Becker All rights reserved. The output JVM.exe JVM.exe from the JVM (executable version of (executable version of is the output JVM) JVM) that your program Machine-dependent Machine-dependent produces Linker/Loader Linker/Loader (unless of course the ‘Java’ Program ‘Java’ Program JVM detects a Running bytecode Running bytecode problem) as input as input Java Virtual Machine Jan 18, 2014 28
  • 29. Java Source :: JVM -10 Java Source Program: Java Source Program: MyProg.java MyProg.java JVM source written in C JVM source written in C Java ‘Compiler’ Java ‘Compiler’ C compiler compiles ‘JVM.c’ C compiler compiles ‘JVM.c’ Byte Byte Code Code JVM.exe JVM.exe (executable version of (executable version of JVM) JVM) Machine-dependent Machine-dependent Linker/Loader Linker/Loader MyProg.class MyProg.class Program Program Running Running © Katrin Becker All rights reserved. ‘Java’ Program ‘Java’ Program Running bytecode Running bytecode as input as input Java Virtual Machine MyProg MyProg output output Jan 18, 2014 29
  • 30. The end. © Katrin Becker All rights reserved. Java Virtual Machine Jan 18, 2014 30