Java Programming and Portability: Understanding Java Virtual Machine and Bytecode, Lecture notes of Web Design and Development

This handout explains the concept of write once run anywhere (wora) in java programming, focusing on java virtual machine (jvm) and java bytecode. It covers how java source code is compiled into bytecode, the role of jvm in executing bytecode, and the availability of jvms for various operating systems and cpus. It also introduces the java runtime environment (jre) and its importance in running java software.

Typology: Lecture notes

2011/2012

Uploaded on 11/10/2012

taariq
taariq 🇵🇰

4.4

(16)

61 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Handout 2–2
Web Design & Development CS-506
- 9 -
Java Virtual Machine & Runtime Environment
Basic Concept
When you write a program in C++ it is known as source code. The C++ compiler
converts this source code into the machine code of underlying system (e.g. Windows) If
you want to run that code on Linux you need to recompile it with a Linux based compiler.
Due to the difference in compilers, sometimes you need to modify your code.
Java has introduced the concept of WORA (write once run anywhere). When you write a
java program it is known as the source code of java. The java compiler does not compile
this source code for any underlying hardware system, rather it compiles it for a software
system known as JVM (This compiled code is known as byte code). We have different
JVMs for different systems (such as JVM for Windows , JVM for Linux etc). When we
run our program the JVM interprets (translates) the compiled program into the language
understood by the underlying system. So we write our code once and the JVM runs it
everywhere according to the underlying system.
This concept is discussed in detail below
Java Compiler javac
Java Byte
Code
JAVA
Source
Code
Java Interpreter
Machine
Code
pf3

Partial preview of the text

Download Java Programming and Portability: Understanding Java Virtual Machine and Bytecode and more Lecture notes Web Design and Development in PDF only on Docsity!

Web Design & Development CS-

Java Virtual Machine & Runtime Environment

Basic Concept

When you write a program in C++ it is known as source code. The C++ compiler converts this source code into the machine code of underlying system (e.g. Windows) If you want to run that code on Linux you need to recompile it with a Linux based compiler. Due to the difference in compilers, sometimes you need to modify your code.

Java has introduced the concept of WORA (write once run anywhere). When you write a java program it is known as the source code of java. The java compiler does not compile this source code for any underlying hardware system, rather it compiles it for a software system known as JVM (This compiled code is known as byte code). We have different JVMs for different systems (such as JVM for Windows , JVM for Linux etc). When we run our program the JVM interprets (translates) the compiled program into the language understood by the underlying system. So we write our code once and the JVM runs it everywhere according to the underlying system.

This concept is discussed in detail below

Java Compiler javac

Java Byte Code

JAVA

Source Code

Java Interpreter

Machine Code

Web Design & Development CS-

Bytecode

ƒ Java programs (Source code) are compiled into a form called Java bytecodes.

ƒ The Java compiler reads Java language source (.java) files, translates the source into Java bytecodes, and places the bytecodes into class (.class) files.

ƒ The compiler generates one class file for each class contained in java source file.

Java Virtual Machine (JVM)

ƒ The central part of java platform is java virtual machine

ƒ Java bytecode executes by special software known as a "virtual machine".

ƒ Most programming languages compile source code directly into machine code, suitable for execution

ƒ The difference with Java is that it uses bytecode - a special type of machine code.

ƒ The JVM executes Java bytecodes, so Java bytecodes can be thought of as the machine language of the JVM.

ƒ JVM are available for almost all operating systems.

ƒ Java bytecode is executed by using any operating system’s JVM. Thus achieve portability.

Java Virtual Machine

Windows Linux OS X Solaris Linux

Intel PowerPC SPARC

App1 App2 App3 App4 App