The program is first loaded into RAM. The computer reads the program one instruction at a time. As instructed the CPU reads data, manipulates it and stores it back. The CPU may also interact with the monitor, printer or speakers as instructed.
The CPU understands machine language. The machine language instructions are encoded as strings of bits. The instruction set is dependent on the type of CPU. The instructions are primitive like load, add, store, jump.
The machine instruction that adds 3 to register D1 might be encoded as the bit string:
0101 011 000000 001
Writing and understanding machine language code is error prone. The first step was to have short mnemonics for the primitive operations instead of binary strings. The above instruction could be written as:
ADD 3, D1
This is assembly language programming. An assembler translates the mnemonics to machine code. But even the assembly language code is unwieldy. The time to write, debug, understand, and maintain a piece of code is proportional to the number of lines of instruction.
A high level language allows common operations such as expression evaluation, repetition, assignment, and conditional action to be invoked in a single high-level statement. Examples of high level languages - Fortran, Pascal, C, C++, Lisp, SmallTalk, Basic, Java.
A computer does not understand a program that is written in a higher level language. A compiler translates a high level program into machine code for that particular CPU.
public class HelloWorld
{
public static void main ( String args[] )
{
System.out.println ("Hello World!");
}
}
Your program has to be saved in a file called HelloWorld.java.
To compile the code for the Java Virtual Machine do:
javac HelloWorld.java
This will produce a file called HelloWorld.class which is
the byte code for the Java Virtual Machine. To run this code do:
java HelloWorld