CS Lesson: Introduction to the Java virtual Machine

download CS Lesson: Introduction to the Java virtual Machine

of 30

  • date post

    10-May-2015
  • Category

    Technology

  • view

    252
  • download

    1

Embed Size (px)

description

An introduction to the Java Virtual Machine

Transcript of CS Lesson: Introduction to the Java virtual Machine

  • 1.Java Virtual Machine Katrin Becker All rights reserved.Java Virtual MachineJan 18, 2014 1

2. Java Virtual Machine - start Java Source Program Java Source ProgramProgram Program Running RunningJava Compiler Java CompilerProgram Program Running RunningJVM on LINUX PC JVM on LINUX PCByte Byte Code CodeJVM 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 RunningJava Virtual MachineProgram 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 -Doesnt matter which machine its created on.Java Virtual MachineJan 18, 2014 3 4. Java Virtual Machine - compile Java Source Program Java Source Program >> javac MyProg.javaJava Compiler Java Compiler Java compiler does syntactic analysis and parsing. Translates source into Byte Code MyProg.class Katrin Becker All rights reserved.Java Virtual MachineJan 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 MachineJan 18, 2014 5 6. Java Virtual Machine ready-set-.. Java Source Program Java Source ProgramJava Compiler Java CompilerByte 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 MachineJava Virtual MachineJan 18, 2014 6 7. Java Virtual Machine go Java Source Program Java Source ProgramJava Compiler Java CompilerByte 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 onJava Virtual MachineJan 18, 2014 7 8. Java Virtual Machine - Linux Java Source Program Java Source ProgramJava Compiler Java Compiler JVM on LINUX PC JVM on LINUX PCByte Byte Code Code Katrin Becker All rights reserved.Java Virtual MachineJan 18, 2014 8 9. Java Virtual Machine Linux-b Java Source Program Java Source ProgramProgram Program Running RunningJava Compiler Java Compiler JVM on LINUX PC JVM on LINUX PCByte Byte Code Code Katrin Becker All rights reserved.Java Virtual MachineJan 18, 2014 9 10. Java Virtual Machine - Windows Java Source Program Java Source ProgramJava Compiler Java CompilerByte Byte Code Code Katrin Becker All rights reserved.JVM on Windows PC JVM on Windows PCJava Virtual MachineJan 18, 2014 10 11. Java Virtual Machine Windows-b Java Source Program Java Source Program Program Program Running RunningJava Compiler Java CompilerByte Byte Code Code Katrin Becker All rights reserved.JVM on Windows PC JVM on Windows PCJava Virtual MachineJan 18, 2014 11 12. Java Virtual Machine - iMAC Java Source Program Java Source ProgramJava Compiler Java CompilerByte Byte Code Code Katrin Becker All rights reserved.JVM on iMAC JVM on iMACJava Virtual MachineJan 18, 2014 12 13. Java Virtual Machine iMAC-b Java Source Program Java Source ProgramJava Compiler Java CompilerByte Byte Code Code Katrin Becker All rights reserved.Program Program Running Running JVM on iMAC JVM on iMACJava Virtual MachineJan 18, 2014 13 14. Java Virtual Machine - UNIX Java Source Program Java Source ProgramJava Compiler Java CompilerByte Byte Code Code JVM on UNIX JVM on UNIX Katrin Becker All rights reserved.Java Virtual MachineJan 18, 2014 14 15. Java Virtual Machine UNIX-b Java Source Program Java Source ProgramJava Compiler Java CompilerByte Byte Code Code JVM on UNIX JVM on UNIX Katrin Becker All rights reserved.Java Virtual MachineProgram Program Running Running Jan 18, 2014 15 16. Java Virtual Machine ..TA-Da Java Source Program Java Source ProgramProgram Program Running RunningJava Compiler Java CompilerProgram Program Running RunningJVM on LINUX PC JVM on LINUX PCByte Byte Code CodeJVM 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 RunningJava Virtual MachineProgram Program Running Running Jan 18, 2014 16 17. Once more from the top A slightly different perspective. Katrin Becker All rights reserved.Java Virtual MachineJan 18, 2014 17 18. Java Source :: JVM -1 JVM source written in C JVM source written in CSomebody writes the Java Virtual Machine; Jim Gosling probably wrote the first one. Katrin Becker All rights reserved.Java Virtual MachineJan 18, 2014 18 19. Java Source :: JVM -2 JVM source written in C JVM source written in CC compiler compiles JVM.c C compiler compiles JVM.cJVM.c gets compiled to produce. Katrin Becker All rights reserved.Java Virtual MachineJan 18, 2014 19 20. Java Source :: JVM -3 JVM source written in C JVM source written in CC 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 MachineJan 18, 2014 20 21. Java Source :: JVM 3b JVM source written in C JVM source written in CC 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 MachineJan 18, 2014 21 22. Java Source :: JVM -4 Java Source Program: Java Source Program: MyProg.java MyProg.javaAlong comes My Program, written in Java Katrin Becker All rights reserved.JVM source written in C JVM source written in CC compiler compiles JVM.c C compiler compiles JVM.c JVM.exe JVM.exe (executable version of (executable version of JVM) JVM)Java Virtual MachineJan 18, 2014 22 23. Java Source :: JVM -5 Java Source Program: Java Source Program: MyProg.java MyProg.javaJVM source written in C JVM source written in CJava Compiler Java CompilerC 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 MachineJan 18, 2014 23 24. Java Source :: JVM -6 Java Source Program: Java Source Program: MyProg.java MyProg.javaJVM source written in C JVM source written in CJava Compiler Java CompilerC compiler compiles JVM.c C compiler compiles JVM.cByte Byte Code CodeJVM.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 MachineJan 18, 2014 24 25. Java Source :: JVM 6b Java Source Program: Java Source Program: MyProg.java MyProg.javaJVM source written in C JVM source written in CJava Compiler Java CompilerC compiler compiles JVM.c C compiler compiles JVM.cByte Byte Code CodeJVM.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 MachineJan 18, 2014 25 26. Java Source :: JVM -7 Java Source Program: Java Source Program: MyProg.java MyProg.javaJVM source written in C JVM source written in CJava Compiler Java CompilerC compiler compiles JVM.c C compiler compiles JVM.cByte Byte Code CodeJVM.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 MachineJan 18, 2014 26 27. Java Source :: JVM -8 Java Source Program: Java Source Program: MyProg.java MyProg.javaJVM source written in C JVM source written in CJava Compiler Java CompilerC compiler compiles JVM.c C compiler compiles JVM.cByte Byte Code CodeJVM.exe JVM.exe (executable version of (executable version of JVM) JVM)Machine-dependent Machine-dependent Linker/Loader Linker/LoaderThe JVM expects a file containing ByteCode as input Katrin Becker All rights reserved.Java Program Java Program Running bytecode Running bytecode as input as inputJava Virtual MachineJan 18, 2014 27 28. Java Source :: JVM -9 Java Source Program: Java Source Program: MyProg.java MyProg.javaJVM source written in C JVM source written in CJava Compiler Java CompilerC compiler compiles JVM.c C compiler compiles JVM.cByte Byte Code CodeMyProg.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 MachineJan 18, 2014 28 29. Java Source :: JVM -10 Java Source Program: Java Source Program: MyProg.java MyProg.javaJVM source written in C JVM source written in CJava Compiler Java CompilerC compiler compiles JVM.c C compiler compiles JVM.cByte Byte Code CodeJVM.exe JVM.exe (executable version of (executable version of JVM) JVM)Machine-dependent Machine-dependent Linker/Loader Linker/LoaderMyProg.class MyProg.class Program Program