Introduction to Java
Java. An object-oriented programming language so popular in the tech industry that it is the second most popular programming language in the whole world, only after C. Also, around 95% of enterprises use Java for building their applications. So, no wonder that Java is a pretty useful programming language to learn and use, as it has been battle-tested and emerged as a stable and versatile programming language for building all kinds of different software.
Birth of Java
Java was developed by James Gosling at Sun Microsystems and the first version was released on 23rd January 1996. Initially Java was very slow, but subsequent releases made it much faster. Today, Java is considered to be a very fast language - as fast as C and Rust, and much faster than other programming languages.
Note: Though Java is fast, it consumes a lot of memory.
But how does Java work?
Before learning how Java works under the hood, we need to know about two important components of Java:
Java compiler - The compiler will check your java source code for errors and if none, will convert your source code to bytecode. One important thing to note is that the generated bytecode is platform independent.
JVM (Java Virtual Machine) - The JVM is used to convert bytecode generated by compiler to machine code that the underlying operating system can understand and execute. JVM is platform dependent which means we have different JVMs for Windows, Linux etc.
But why do we need different JVMs for different platforms?
Since the JVM must translate the bytecode into machine code, and the machine code depends on the operating system being used, it is clear that the JVM needs to be platform (operating system) dependent.
With these two components in mind, let's see how Java works.

I hope the above diagram gave you a brief understanding of how Java works. In short:
You write the source code in Java.
Next, you try compiling the source code using a Java compiler. If there are any errors, then it will throw an error. Else it will compile the source code to Java bytecode. The generated bytecode is platform independent.
Now, when you want to execute your source code in some other device, the JVM takes the bytecode generated in the previous step, converts it into machine code that the device can understand, and then executes and provides the output.
Code structure in Java
In Java, everything goes in a class. Every Java application has to have at least one class, and at least one main method (just one main per application and not one main per class).
A source code file (file with .java extension) typically contains a single class definition. A class represents a piece of your application and acts as a blueprint for an object.
A class can contain instance variables and methods.
Instance variables represent the state of the class.
Methods represent the behaviour of the class. Methods contain a set of statements to perform some business logic.
I hope you got a good introduction to Java; it's working and code structure. In the next post, we will delve more into the object-oriented features of Java. Until then, cheers! đź‘‹
Last updated