Hands on - Basics of Programming

Step 1 of 4

Understand the starting point of standalone application
(From where the Program begins).

Always remember, a standalone application (as in our case) always starts from main method.

What is a main method?
Main method is considered as entry point of Java application (only
for standalone application. There are other ways to let computer
know from where to start the execution but it is out of scope for now).
[main method in Java is an standard method which is used by JVM
to start execution of any Java program]

Let’s try to understand, Why Main method is important?
The most important point is, it is used by Java Virtual Machine
(JVM) to start execution.
Now, what is a JVM?
To understand, what is JVM and what it does let’s dive deep a little
more. [This is something we cover in earlier chapter but I am
revisiting once again because it is important.]
Step 1. We write our code/program and save in .java extension. (ex: MyProgram.java).
Step 2. When we run the Program, a software named the
compiler converts our .java file to .class file.
Step 3. These .class files are fed to Java Virtual Machine(JVM).
JVM converts the code into 0s and 1s and it is this unique
sequence that computer understands. -  (This is why JVM is important)
[Remember computer only understands 0 and 1]
[The objective of Java software is to lay some standard rules to write high level commands
for computer that is easy to understand
by humans and at the same time, feasible for Java software to convert to 0s and 1s].

Now coming back to the main method. It is important to understand that
when you are writing a program you are basically giving a
sequence of commands to computer to perform a task.
And hence it is important for computer to understand the starting
point of the program. This enables a computer to understand in
what sequence it has to execute the commands. This is where the
main method comes into picture.

When we write a main method, it basically tells the computer, “hey
here is the starting point of execution” for standalone application.
Example of main method code in a class.