A First Simple Program In Java

Start compiling and running the sample program.

Print "hello world" program in java.

/*  
simply displays "Hello World" output. */
//programming789.blogspot.com/
class Test 
{
     public static void main(String args[])
      {
       System.out.println("hello world");
      }
}

● Open notepad and add the code.
● Save the file as Test.java.
● Open a command prompt window and go to the directory where you saved the java file. Assume it's C:\Test.
● Type ' javac Test.java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line.

● The javac compiler creates a file called Test.class that contains the bytecode.
● To actually run the program, you must use the Java interpreter, called java. To do so, pass the class name Test as a command-line argument, as shown here.
>C:\Test>java Test


● When the program is run, the following output is displayed:
hello world

Explaination:

Comment:

● The Java language supports three kinds of comments.

/* text */
The compiler ignores everything from /* to */.

/** documentation */
This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation

// text
The compiler ignores everything from // to the end of the line.

Class:

 A class is a group of objects that has common properties. It is a template or blueprint from which objects are created.
● A class in java can contain:
    ● data member
    ● method
    ● constructor
    ● block
    ● class and interface

Syntax of class:

class <class name>
{
//code
}

Class rules for Naming

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive.

Public Static Void Main(String args[]) :

● The keyword “static” allows main( ) to be called without having to instantiate a particular instance of the class. Void keyword tell the compiler that main() function does not return a value.