High Level to Machine Language

Understand the details of how high-level code is converted into machine code with the help of an example.

Coding example: 1

As we mentioned in the previous lesson, we will be explaining concepts using coding examples. Here you see a simple Java program that takes input from a user and gives an output, such as “Hello World”. If you want to rerun the code, write java main in the terminal:

import java.util.*;
import java.util.Scanner;
import java.lang.String;
public class main {
    public static void main(String[] args) {
        String s;
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a string");
        s = in.nextLine();
        System.out.println("You entered string " + s);
    }
}

Code explanation

If you are a beginner, the first problem really does not convey any meaningful message to you. However, we have learned one thing, how to take input from a user and give an output. We’ll dissect that problem later and learn how it works.

Machine code

The text, “Hello World,” looks completely different in machine language (binary). Here is the output:

01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100

An analogy between human language and machine language

We hope now you understand why we need a high-level language to build applicable software. It is impossible for us to write a simple “Hello World” in machine language. In human language, the same thing happens. It is easier to say, “Good Morning,” than it is to draw it. If you had to draw an image to convey the same message, it would be cumbersome and seem like an impossible task to people.

When somebody wishes you “Good Morning,” our brain processes that message and forms an image inside our mind. In the case of high-level programming language, the compiler does that processing job and converts the high-level language to machine language (binary).

The following figure gives you an idea of what happens.

We have also learned another important lesson: it is very difficult to give the same output in machine language (binary). Therefore, we need a high-level language like Java to write code that will build an applicable software or application; for both web and mobile.

Furthermore, we have also seen that when we write code in the high-level language, it is ultimately translated to binary code. Hardware does not understand anything but binary.