Monday 7 March 2011

Overview of java programming

Java is general purpose, object-oriented programming language. Two types of java programs canbe developed.
  • Stand-alone applications
  • Web Applets
Stand-alone applications are programs written in java to carry out certain tasks on a stand-alone local computer. A stand-alone java program can be executed in two steps:
  1. Compiling source code into byte code using javac compiler.
  2. Executing the byte code program using java interpreter.
Web Applets are small java programs developed for internet applications.They are developed for doing everything like creating simple animated graphics, complex games, utilities etc.

SIMPLE JAVA PROGRAM:

//A Simple java program
Class Simple
{
public static void main (String args[])
    {
     System.Out.Println ("A Simple Java Program");
     }
}

We will explain the above program step by step.

Comment
The First line is a single line comment which will be ignored during compilation. Comments make you understand what your program does. Use /*-----*/ for multiple line comments.

Class Declaration
In java, everything must be declared in a class, which is declared by the keyword Class. Public is a keyword which makes the class available and accessible to any one.
(Simple) one is a java identifier that specifies the name of the class to be defined.

Opening Brace
In java, every class definition begins with an opening brace "{" and ends with a closing brace "}". Pair of "{}" braces define the scope of any method or class.

The Main Line
public static void main (String args[])
This linbe begins the main() method. This is the line at which program will begin executing. All java applications begin execution by calling main(). The main() must be declared as Public, since it must be called by code outside of it's class when the program is started.
The keyword void simply tells the compiler that the main() does not return a value. The keyword static allows main() to be called without having to instantiate a particular instance of the class.

The Output Line
System.Out.Println ("A Simple Java Program");
This line outputs the string followed by a new line on the screen. Output is accomplished by the built-in  println() method. System is a predefined class that provides access to the system, and out is the output stream that is connected to the console.

All statements in java ends with a semicolon(;).

No comments:

Post a Comment