Codementor Events

Java tutorial 1 - A basic program

Published Dec 15, 2020Last updated Dec 22, 2020
Java tutorial 1 - A basic program

If you do not know how to code, or even what is code, then you are at the right place. In this tutorial, We'll try to understand a very basic java program.

Drum Roll

The program that we are going to understand is given below. Just stare at it for like 1 minute and try to make some sense out of it.

public class Main {

    public static void main(String[] args) {
        System.out.println("Hi Mr. Reader!!!");
    }
}

Let's see if your intuition is correct.

I'll be referencing a person named Mr. Compiler again and again. Who is he?
He is the software responsible for running the program.

In this case, when we will try to run this program, Mr. Compiler will come up and check if our code/program is correct. If it is correct, it will show us an output otherwise we will get an error. Since this code is correct, we will get the output as follows.

Hi Mr. Reader!!!

But Why
Let's try to answer this

Now, these are the steps Mr.Compiler took to run this program.

Step 1.

Assume that the name of the file is Main.java. So first when Mr. Compiler visits Main.java, it looks for the class with the same name i.e Main.

Step 2.

Next, inside this class, Mr. Compiler will look for psvm or public static void main and will run the entire code inside the two curly braces.

Step 3.

Now, what's the code inside psvm? It's just 1 line i.e

System.out.println("Hi Mr Reader!!!");

This line, in easy words, is asking Mr. Compiler to print "Hi Mr. Reader!!!".

And there we are

I think that you were able to understand how a basic program works. In case you have any doubts, I am happy to help you out.

In the next part,we will learn about variables. Hope to see you there too.

That`s it for this blog. If you wanna become a great programmer, I am there to help.

You can see my profile by clicking on my name below.

Discover and read more posts from Aniket Malik
get started