Friday 1 March 2013

How to Build Java Program


Java is a text file that contains one or more class definitions.  Java compiler requires that a source file use the .java file name extension.
            Example:         class Example
{
                                    public static void main(String[] args)
                                    {
                                                System.out.println("Hello");
                                    }
}

Ø  The keyword ‘class’ is used to declare the new class is being defined
Ø  Example is an identifier that is the name of the class
Ø  Entire class definition will be between the opening curly brace ({) and the closing curly brace (})
Ø  ‘public’ keyword is an access specifier, which allows the programmer to control the visibility of class members
Ø  The keyword ‘static’ allows main() to be called without having to instantiate a particular instance of the class.  Since, main() method is called by the Java interpreter before any objects are made
Ø  The keyword ‘void’ used to tell the compiler that main() does not return a value
Ø  main() is a method called when a Java application begins
Ø  String args[] declares a parameter named args, which is an array of instances of the class string.  args receives any command line arguments present when the program is executed
Now the file is saved with .java extension .  Let the file name is taken as Example.java

No comments:

Post a Comment