{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L3mt_print - CSE 12 Basic data structures and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 12 : Basic data structures and object-oriented design Jacob Whitehill [email protected] Lecture Three 3 Aug 2011 Wednesday, August 3, 2011 The Java Virtual Machine (JVM). Wednesday, August 3, 2011 Why study the Java VM? Before studying the more complicated data structures, it is important to understand the relationship between a computer program and the memory on which it operates. In the case of Java, this entails a discussion of the Java Virtual Machine (JVM). Wednesday, August 3, 2011 “Real machines” To appreciate “virtual machines”, let’s fi rst consider how a source program is converted to an executable program on a “real machine”: The programmer writes some source code . He/she then compiles the source code into machine instructions that are speci fi c to the particular hardware platform. Wednesday, August 3, 2011 “Real machines” If the programmer wants her program to run on 5 different hardware platforms, she needs to: Write the source code only once (thank goodness!). Compile the source code 5 times. Wednesday, August 3, 2011 “Real machines” Source code class MyClass { void myMethod () { } ... Intel compiler ARM compiler Snapdragon compiler Intel machine language ARM machine language Snapdragon machine language Intel executable fi le ARM executable fi le Snapdragon executable fi le Wednesday, August 3, 2011 Java In the 1990s, Sun Microsystems developed a new programming language called “Java”. Motto: “Write once, run everywhere.” This might be more aptly described as, “Compile once, run everywhere.” Once Java code is compiled, it can run on any platform, irrespective of CPU type. How is this possible? Wednesday, August 3, 2011 Java Virtual Machine The designers of Java inserted a layer of abstraction between the Java compiler and the hardware CPUs. This abstraction is called the Java Virtual Machine (JVM). The JVM provides a convenient “abstract machine language” that can run on any CPU . This means that a Java program need only be compiled once , and it can run on any hardware platform. Wednesday, August 3, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The JVM was also designed from the ground-up to provide security , e.g.: Bounds checking: it won’t let you access the 9th element of an 8-element array. Type safety: it won’t let you treat an Integer as a String . Java Virtual Machine Wednesday, August 3, 2011 Java Virtual Machine Source code Intel JVM ARM JVM Snapdragon JVM Java compiler Java machine language (“bytecode”) Java object fi le ( .class ) Wednesday, August 3, 2011 Java Virtual Machine Every compiled Java .class fi le will run on every Java Virtual Machine for every hardware platform in the same way. This convenience through abstraction comes at a price: A new JVM must be created for every hardware platform.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}