How does Java work under the hood?
First off, what is java ? Java is a multiplatform object-oriented programming language. What I mean by the word "multiplatform" is that not only can it be used to create web, mobile applications and games, It can also run on any device you can think of. What I meant by Object-oriented programming(OOP) is that its main concept turns around objects, which are simply data that have properties and behaviors. Now, How is it processed in our Computers ? Java processing can be compared to a journey, and the best way to describe this journey is by breaking it down step by step: Step 1. The code script As we all know the code needs to be typed in a ".java" file from an editor(Notepad, IDE, etc.). But this code is only understandable by humans so we'll need a way to convert our Java code into something that can be read and understood by our computer. Step 2. Compilation into Bytecode Javac or Java compiler, just as its name shows it, is the standard Java compiler. So what it does is, take the Java code and compile it into something called Bytecode under the influence of some command. A Bytecode is a set of instructions that can run on any device as long as it contains a Java Virtual Machine(JVM). Step 3. JVM's role play The JVM(Java Virtual Machine), is a powerful translator, it takes the Bytecode and makes it understandable by the computer's processor backed up by the JRE(Java Runtime Environment) that provides different libraries or interfaces that will help the JVM operate seamlessly. One more thing though, the JVM doesn't just run our Bytecode directly, this is what it goes through: - interpretation: Our JVM converts each line of code into an instruction or action the computer should execute, also called the Bytecode. - JIT compilation: For things to run faster, the JVM takes those bytecodes and converts them into native machine code(the language our computer's processor can understand) by the JIT(Just-In-Time Compiler). Step 4. Running the Program Now that our JVM has done its work, it finally sends the instruction to the computer to run or print whatever the developer was intending to print(let's say may be a "hello world!!" on the screen, or that cool game above
First off, what is java ?
Java is a multiplatform object-oriented programming language.
What I mean by the word "multiplatform" is that not only can it be used to create web, mobile applications and games, It can also run on any device you can think of.
What I meant by Object-oriented programming(OOP) is that its main concept turns around objects, which are simply data that have properties and behaviors.
Now, How is it processed in our Computers ?
Java processing can be compared to a journey, and the best way to describe this journey is by breaking it down step by step:
Step 1. The code script
As we all know the code needs to be typed in a ".java" file from an editor(Notepad, IDE, etc.).
But this code is only understandable by humans so we'll need a way to convert our Java code into something that can be read and understood by our computer.
Step 2. Compilation into Bytecode
Javac or Java compiler, just as its name shows it, is the standard Java compiler.
So what it does is, take the Java code and compile it into something called Bytecode under the influence of some command.
A Bytecode is a set of instructions that can run on any device as long as it contains a Java Virtual Machine(JVM).
Step 3. JVM's role play
The JVM(Java Virtual Machine), is a powerful translator, it takes the Bytecode and makes it understandable by the computer's processor backed up by the JRE(Java Runtime Environment) that provides different libraries or interfaces that will help the JVM operate seamlessly.
One more thing though, the JVM doesn't just run our Bytecode directly, this is what it goes through:
- interpretation: Our JVM converts each line of code into an instruction or action the computer should execute, also called the Bytecode.
- JIT compilation: For things to run faster, the JVM takes those bytecodes and converts them into native machine code(the language our computer's processor can understand) by the JIT(Just-In-Time Compiler).
Step 4. Running the Program
Now that our JVM has done its work, it finally sends the instruction to the computer to run or print whatever the developer was intending to print(let's say may be a "hello world!!" on the screen, or that cool game above