Title: Using the Java programming language compiler
1Using the Java programming language compiler
2Review of relevant material from previous
lectures
- A computer can only execute machine instruction
codes (binary numbers) - Writing algorithms in machine instruction codes
is extremely tedious
3Review of relevant material from previous
lectures (cont.)
- People have invented a number of English-like
languages that is highly suitable for writing
algorithms - People have also written computer applications
that translate algorithm written in a programming
language into machine instructions
- These languages are called (high level)
programming languages
- These applications are called compilers
4How to write an algorithm that a computer can
execute
- The hard way
- You will hate your professor if he/she make you
do this.... (and yet, the pioneers in Computer
Science had done this... we must be grateful to
them)
- Write the algorithm (yourself) in machine
instruction (binary numbers)
5How to write an algorithm that a computer can
execute (cont.)
- Write the algorithm (yourself) in a programming
language (using an editor like gedit) - Translate the program using a compiler into
machine instructions (The translated program is
stored in a computer file) - Let the computer execute the translated program
in machine instructions (This translated program
is an computer application because it can be run
by a computer)
6How to write an algorithm that a computer can
execute (cont.)
- Pictorially
- (An application is a file that contains machine
instructions (which can be executed by a
computer))
7Using the Java compiler
- The name of the Java compiler (application) is
8Using the Java compiler (cont.)
- A Java program ( a computer algorithm written in
the Java programming language) is first written
and stored in a file - The name of the file must end with the
characters - The ending of a filename is called the file
extension and it is commonly used to identify the
kind of file.
9Using the Java compiler (cont.)
- The following command will translate a Java
program into machine code - The Java compiler javac will store the
translated machine codes into a file name
ProgramFileName.class
- UNIX promptgtgt javac ProgramFileName.java
10Using the Java compiler (cont.)
11Using the Java compiler (cont.)
- Example Program (Demo above example) Â
- The Hello.java Prog file http//mathcs.emory.edu/
cheung/Courses/170/Syllabus/02/Progs/Hello.java
  - What to do
- Right click of the link and save in some scratch
directory - Change current directory to that scratch
directory - Compile Hello.java with javac Hello.java
12The Java machine language
- The translated machine code produced by the Java
compiler javac is called
13The Java machine language
- Java bytecodes are executed by a Java machine ---
a computer that executes machine instructions in
Java bytecodes -
- However, no such Java machine has ever been
built -
- In other words
- There does not exist a physical computer
(machine) that can execute Java byte codes
14The Java virtual machine
- Emulators
- Emulators are also known as virtual machines
- (Because they do the same thing as a real
machine, but is not a physical machine)
- Emulators are (special) computer programs that
emulate the exact behavior of a machine or entity
15The Java virtual machine (cont.)
- Java virtual machine
- (A Java virtual machine is an emulator)
- A Java virtual machine is a computer program
(application) than can execute an algorithm
written in Java bytecode
16The Java virtual machine (cont.)
- The name of this computer application is
17Executing the translated Java program with a Java
virtual machine
- Suppose the program containing the Java bytecode
is called - This program can be executed by the Java virtual
machine java by executing the following command
ProgramFileName.class
java ProgramFileName
18Executing the translated Java program with a Java
virtual machine (cont.)
- You must omit the extension .class
- The Java virtual machine java will append the
extension .class to its argument
19Executing the translated Java program with a Java
virtual machine (cont.)
20Executing the translated Java program with a Java
virtual machine (cont.)
- Example Program (Demo above code) Â
- Hello.java Prog file http//mathcs.emory.edu/che
ung/Courses/170/Syllabus/02/Progs/Hello.java - What to do     Â
- Right click on the link ans save in some scratch
directory - Change current directory to that scratch
directory - Compile Hello.java with nsbp javac Hello.java
- Then execute the Java bytecode Hello.class with
 java Hello