Java

TOPIC 02 – CONVERSION TO MACHINE LANGUAGE

 

 

LESSON NOTE

 

 

MACHINE LANGUAGE

 

Computer CPUs only understand a specific language consisting of only 0s and 1s called the machine language.  PCs (IBM-compatible machines) have a different machine language than MACs and Sun machines. Similarly, different types of smartphones have different machine languages.

 

This means that a computer program that works on one type of machine isn’t compatible with another type of machine.

 

For example, the command represented by the sequence 0001 0011 might mean addition on one system but mean store to memory on another.

 

HIGH-LEVEL PROGRAMMING LANGUAGES

 

For humans, programming with 0s and 1s is simply RIDICULOUS!  If you ever wanted a quick way to get a headache, this would be a good start.

 

For the most part, anything but very simple applications are done using high-level programming languages (or simply programming languages).  Examples of such languages include Java, Turing, Fortran, C++ and VB.

 

SOURCE CODE

 

Source code consists of all of the statements that one writes to create a program.  All source code for a program is stored inside of a file.

 

CONVERSION

 

The problem with programming languages is that CPUs don’t understand them.  They only understand machine language.  Therefore, a conversion is needed to transform source code into machine language. 

 

     1 – Compilation

     2 – Interpretation

     3 – Hybrid approach

 

COMPILATION

 

In this process, a software program called a compiler converts source code to machine language.  Usually, this appears in the form of an EXE file. 

 

INTERPRETATION

 

In this process, a software program called an interpreter takes one line at time from your source code, converts it to machine language, has it executed by the CPU and then returns for the next line of source code.

 

PROS AND CONS

 

Compilation

Interpretation

PRO

  • Doesn’t require any special software to run the program after it is compiled.  This means that program execution is faster.

CON

  • The source code has to be compiled by a different compiler for each type of computer that is not compatible.  This means that you end up with different versions of each program (ie – A version for PC, a version for MAC, a version for Linux, …)

CON

  • Requires a special interpreter software to run the completed program.  This means that the CPU has to spend its time on the program itself but also on the running the interpreter.  So such a process is a bit slower to run.

PRO

  • The program can be used on all computers (even ones that are not compatible).

 

HYBRID APPROACH

 

This process is not commonly used.  However, we will look at it because Java uses it. 

This is a two-step process.  First, a software program called the Java Compiler compiles the source code to what is called bytecode.  Such files end in the .class file extension. 

 

During the second step, an interpreter program called the Java Virtual Machine interprets one line of bytecode at a time.