Simple Hello world program

Your First Java Program

Now, in this post we will see how we can write our first program in java. Type the below java program in a notepad editor and save it in bin folder of JDK installation directory. File name should be Hello.java

class Hello
{
     public static void main(String args[])
     {
          System.out.println("Hello World");
     }
}

Every word in the above program has its own significance.

1) class is a keyword and Every keyword in java should be in lowercase.

2) Hello is our class name. It can be any name, even your name and First letter of class name should be in uppercase. This is not important but we have to follow some conventions.

3) publicstatic and void  are keywords and we will go into more details of it in upcoming lessons.

4) main is a method name and method name must be in lowercase. main is the most important method of every java program and every java program should have one main method. When you run any java program, it will search for the main method. This method takes one argument of type String array. Just remember main is not a keyword, its a method.

5) String is a final class from java.lang package. More about it later.

6) System is also a final class from java.lang package. out is a static member of System class of type PrintStreamprintln is a method of PrintStream class.

7) Java is open source, that means that source code of java is available in your system when you installed JDK. You can explore the source code of both System class and String class.

Go to JDK installation directory and extract the ‘src‘ zip file. Then go to src –> java –> lang. In lang folder, you will find both System and String Java files.

8) Above program will print “Hello World” on the console.

In the next topic we will see how we can compile and run our program.

Leave a Reply