OOPortal OOPortal


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

Java Compiler versus C++

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.

Compiler Components
Comparison of C++ and Java Compilers

C++ Compiler

Compiler Components
C++ Compiler

Java Compiler

Compiler Components
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

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

Exercise

Compile the HelloWorld program (Windows)

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.