Online Software Educational Training - IT Tutorials - Online Education Training for Computer Software


Home

JAVA PROGRAMMING

A First Program

Now that the basic concept of Java has been discussed, let's look at some actual Java programs. Let's start by writing simple program.

/* This is Comments 

This is a simple Java program call this file "hello.java".

*/

class hello  {

 

public static void main(String[] args) 

    {

System.out.println("Hello World, You are welcome");

    }

}

 

 

For most computer languages, the same name of the file that holds the source code to a program is arbitrary. However, this is not the case  with Java. The first thing that you must learn about Java is that the name you give the source file is very important. For this example, the name of the source file should be hello.java. Let's see why. In Java, a source file is officially called a compilation unit. It is text file that contains one or more class definitions. The Java compiler requires that a source file use the .java file name extension. Notice that the file extension is four characters long. As you might guess, your operating system must be capable of supporting long filenames. As you can see by looking at the program, the name of the class defined by the program is also hello. This is not a coincidence. In Java, all code must reside inside a class. By convention, the name of that class should match the name of the file that holds the program and it is case sensitive also.

 


Previous

Next