CS Lesson: Introduction to the Java virtual Machine
Upcoming SlideShare
Loading in...5
×
 

CS Lesson: Introduction to the Java virtual Machine

on

  • 324 views

An introduction to the Java Virtual Machine

An introduction to the Java Virtual Machine

Statistics

Views

Total Views
324
Views on SlideShare
324
Embed Views
0

Actions

Likes
2
Downloads
11
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

CS Lesson: Introduction to the Java virtual Machine CS Lesson: Introduction to the Java virtual Machine Presentation Transcript

  • 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