Chapter 3: Working Of Java

Chapter 3: Working of Java

Welcome back 😁! You must have come across words like compiler, interpreter. If not, these are the ways a program written in a programming language is translated into Binary digits( 0 and 1 ) to make the computer understand what to do, since Binary is computer's native language. The programming languages that we use are designed to give commands to the computer in a systematic manner, and to convert it into an even lower language - Binary. For more information on binary numbers and how computers interpret binary, give a visit to https://www.freecodecamp.org/news/binary-definition/.

Now that we know that we need to translate our thoughts into a programming language, and the program(implemented thoughts) written in that programming language is translated into Binary form.
Let's understand how it's done.

We translate our thoughts into programming language by learning both - our native language and a programming language understood by the computer so we can convert our language into programs and vice-versa.
    Now that we have a program understood by a computer, how does that computer check whether what you have written is correct or not? and if it is further execute it. This is achieved using: Compilers and Interpreters.
    Compilers: They translate the whole program into a lower level language understood by the computer, in one go, and list all the errors, typos, wrong things etc.
    Interpreters: They translate the program into a lower level language understood by the computer,  line-by-line and as soon as an error occurs it stops interpreting and displays the error.
    Now that we have a compiled/interpreted program, it can be executed by the computer. YAY! However, programs me interpret differently on different systems. Therefore, preventing programmers from using the same program on other systems. Therefore Java uses both - Compiler and Interpreter.
    
Remember we had written a program which can be understood by the computer, Java uses a compiler (designed by Java's developers, the compiler command syntax is javac <filename>.java) to convert the program into bytecode(a combination of letters, numbers, symbols which are only understood by java). Bytecode does not depend on the system on which it runs since it remains the same on all systems due to use of java compiler.

Now that we have a bytecode, which is independent of the system. We can now execute it, (interpret it).
This bytecode is executed by translating it into Binary Digits ( 0 and 1 ) systematically, using interpreter, in case of java the interpreter used is JVM(Java Virtual Machine). (Syntax: java <classname>)

WE HAVE SUCCESSFULLY EXECUTED OUR PROGRAM! ✌✌

You can notice this working of java if you have a computer.
As you run the command javac <filename.java>, go to the respective folder and notice there will be a class file created with the extension .class which is the bytecode.
As you run the command java <classname>, the bytecode will get interpreted and the program will execute! 

For reference look at this image:




Comments

Popular posts from this blog

Chapter 10: Divide and Conquer

Chapter 1: Introduction To Java

Resources