Flow of a Java Program
Table of contents
Hello coders, in this blog, we will explore the flow of Java programs through an interesting story that I'm sure you'll enjoy.
The other day, I was craving some biryani made by my mom. I called her to get the recipe. I'm not a great cook, but my roommate Sharda is. Usually, while cooking, Vaishnavi assists Sharda with the preparations.
Following my mom's instructions, Vaishnavi first checked if we had all the necessary ingredients. After gathering everything, she corrected some of the amounts I had noted down and gave the list to Sharda. Sharda then started the cooking process, following the instructions step-by-step. In the end, we had a delicious biryani.
If I have represent that in a block diagram it will look something like this -
Similarly, in Java, the flow of a program involves checking and gathering necessary resources, organizing them, and then executing instructions step-by-step to achieve the desired outcome. Let's dive deeper into how this process works in Java programming.
The programmer creates a file and writes a set of instructions (the program) in it.
They save the file with a .java extension, which represents a Java file.
After that, this file is sent to the compiler to be compiled. The compiler has two tasks assigned to it:
Check for syntax errors in the .java file.
Create a bytecode file (.class file).
The bytecode file is intermediate-level code generated after the source code is compiled.
Byte Code consists of binary, hexadecimal, macro instructions (like new, add, swap, etc.)
It is not directly understandable by the CPU, It is designed for efficient execution by software such as a virtual machine.
In Java, we have the Java Virtual Machine (JVM), which executes this bytecode with the help of an interpreter.
The interpreter executes the instructions line by line.
To speed up execution, we have Just In Time (JIT) compiler.
Subscribe to my newsletter
Read articles from Gautami Shetty directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by