Get to know - JAVA

What is Java?

To start with the basics, Java is an HLL (High-Level Language). Its other features are that it's object-oriented (OPPs) and platform-independent. It lets users write once and run anywhere (WORA).

To further explain the above abbreviations, being an HLL means the language allows programmers to communicate with the system, which enables a user-friendly interaction and development of a program. It focuses more on the logic behind the program rather than the underlying hardware architecture.

OOPs is a method of programming which brings about the concept of 'objects'. The object contains the code with the data, as this method of programming revolves around data rather than logic and functions.

Everything in Java is done using classes, this is one of the reasons for it being platform-independent, as the source code doesn't get directly converted to machine code. The below flowchart will improve the understanding:

History

Java was developed by James Gosling in the 1990s, and its previous name was 'Oak', later the name was changed to Java, which represents some sort of espresso beans. The team initiated this project to develop a language for digital devices such as set-top boxes, television, etc. But, it was too advanced for the cable industry at that time. Gosling designed Java with somewhat similarity to C/C++ in terms of syntax.

Detailed Working of Java

Its major components which facilitate its smooth running are:

  • JDK (Java Development Kit)

  • JRE (Java Runtime Environment)

  • JVM (Java Virtual Machine)

  • JIT (Just in time)

JDK (Java Development Kit)

  • It provides an environment to develop and run a program.

  • It's a package that includes:

    --> Development tools

    --> Compiler (javac)

    --> Archiver (jar)

    --> Docs generator (javadoc)

    --> Interpreter (loader)

JRE (Java Runtime Environment)

  • Its an installation program, and it only provides the environment to run the program.

  • Consists of:

    --> Deployment tech

    --> User interface tool kits

    --> Integration process

    --> Base Libraries

    --> JVM


The following steps happen after we get the byte code (.class file):

  1. All the files which require execution are loaded by the class loader.

  2. To cross-check the format of the code, the byte code verifier is sent by the JVM.

    (COMPILER IS ONLY AT JDK!!!)


Execution by JVM

  • For the execution of the files, JVM uses the interpreter for line-by-line execution meaning when one method is called multiple times, it would interpret that many times itself. (But, this affects the performance of the execution process)

    To tackle this issue JIT comes into the picture.

Use of JIT

For those methods which are repeated, JIT provides direct MC (Machine code) for that meaning reinterpretation is not needed. (Tells interpreter to not convert it to MC multiple times, just take the interpretation from me, to make the execution process faster)

A Little about Compile time and Runtime

HOW JVM WORKS?

It is important to know about JVM's working as most important steps in compilation of file occurs:

Loading

  • reads .class file and generates the binary data.

  • an object of this data is created in heap memory.

Linking

  • JVM verifies the .class file.

  • Allocates the memory for default values & class variables.

  • Symbolic refrence get replaced with direct refrence.

    (Meaning if sum=a+b, then during this step values of a&b would be there, and the symbols would be flushed out)

Initialization

  • All static variables (static variables are independent of objects (OOPs concept)) are assigned with their values defined in the static block (static block is used for initialization during the run-time as class is loaded into the memory)

    (JVM contains the stack and heap memory allocation!!!)

Voluntary Extra Info !!!

If we want to change the location of the byte code

(This involves a little knowledge of Linux commands)

The above example is of saving the byte code in the current file itself.

  • '-d' is the command for saving the file.

  • The -d. represents the file would be saved in the current directory.

    (If -d.. is written the the file would be saved in the previous directory)

  • javac is the compiler.

  • filename.java is the syntax.


In reality, javac is a type of executable file only, located somewhere in the computer, and if we write the above command, it would show the location of the file.


Hope you liked this article!!

And found it somewhat informative :-)

Keep Creating, Keep Learning

--> Shrey Kothari