Structured Programming   «Prev  Next»
Lesson 5Java compiler
Objective Use the Java compiler.

Java Compiler versus C++ Compiler

In this lesson you will create and compile your first Java program. Before you get started with this task there's something you should know about the Java compiler[1] . Unlike compilers for other high-level programming languages, the Java compiler does not produce machine code for a particular type of computer. Instead, it produces machine code for the Java Virtual Machine (Java VM). Move your mouse cursor over the buttons below to see the fundamental differences between a Java compiler and a C compiler.

C++ versus Java Compilation
Comparison of C++ and Java Compilers


C++ Compiler

This shows how a C compiler on one computer would produce machine code specific to that architecture.
C++ Compiler


Java Compiler

The output of the Java Compiler is referred to as Java bytecode.
Java Compiler
java Compiler Compared To other Compilers
To compile a Java source code file, you will use the javac tool that's included with the Java SDK. For example, to compile the Java source code in a file named HelloWorld.java you would issue the following command at the command prompt:
javac HelloWorld.java

Java Compiler - Exercise

Compile the HelloWorld program (Windows) The output of this command would be a file named HelloWorld.class containing thebytecode[2] produced by the compiler. In the next lesson you will run your first Java program.
Java Compiler - Exercise

Compile Java Program - Exercise

Compile the HelloWorld program (Unix)
Compile Java Program - Exercise
[1]Java compiler: Translates Java source code into bytecode.
[2]Bytecode: Machine code for the Java Virtual Machine.