Monday, November 16, 2009

Two Types of Java Programs:

All java programs can be catagorised in to two types:

  1. Java Application
  2. Java Applets

1st Application Program:I hope you have installed Sun Micro Ststem's JDK 1.6 version in your System.If not please down load it from Sun Microsystems and install it in your computer.It is free down load, Using JDK's editor or any other text editor create a java source file and save it say Hello_World.java .Rembeber Hello_World is the name of class file, where main() function is included.Then compile your source file with javac Hello_World.java .

If no syntax error,after compilation you will get Hello_World.class byte-codode file.This byte code file can run on any computer system equipped to handle Java programs simply typing java Hello_World at dos prompt.Now you see the result in your terminal.Let me write the program.

class Hello_World{

public static void main(String args[]){

System.out.println("To my viewers,HelloWorld!");

}

}

Being the first program, like explaing Gita Sloka,let me explain meanig of each important key word.

The first statement, class Hello_World ,the name of the class is defined as Hello_World.Since java is fully object oriented every part of program has to be included in a class file.You have to name the file as Hello_World.java.You canot save the file in any other name.This file contains only one method main().In the statement, public static void main(String args[]){-----}

main()is declared as publc static and void return type.

public keyword means this method is available to all classes in the program.

static key word declares that this method remains samefor all instances of the class.

void key word states that main() method does not return any value.main() method is taking a single parameter,String args[ ],mens it can take array of String objects as command line arguements.Further main() method contains a single statement

System.out.println("To my viewers,HelloWorld!");

The out object is a member variable of the System object which represents standard output stream which invokes println() funtion

Now cmplile the source program typing,

javac Hello_World.java

After compilation you will get executable class file as Hello_wrld.class file as Hello_World.class

file.now class file wil be inter preted by the command

java Hello_Wrld

You will now get the ouput in your monitor as

To my viewers,HelloWorld!

Any program has basically two two sections ie.

  1. Code section
  2. Data section.
  3. Codes operate on the data and provides result to the user.Data can be provided to the program broadly in four ways.

  1. Through the program itself
  2. Through command line arguements
  3. Online through key board
  4. Persistent data handling in files and backend data bases like Oracle

In the above example we have not manipulated any data.I have contemplated to present java in two parts

  1. Part-I Core java (mainly client side programming)
  2. Part-II Advanced Java (mainly Server side Programming)Following J2EE slide show pertains to part-II and canbe skipped by begineers.

No comments:

Post a Comment