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.

Thursday, November 12, 2009

Java Introduction



JAVA CHARACTERSITICS
Sun Micro Systems introduced java in 1995 and its cofounder Bill Joy described java as follows.
Java is just a small,simple,safe,object-oriented,interpreted,byte-coded,architecture,neutral.garbage-collected,multithreaded and strongly typed with exception-handling mechanism.
Let us understand Java characteristics little in detail:
Architecture neutral: Java file can run on any cpu architecture ie. It may be Intel ,Motorola or AMD.etc.
Platform –independent:java developed under any operating system can run on every operating system.One leading bank has replaced 80 million lines of plat- form specific banking applications with 20 million lines of java code.What a saving!
Object oriented fully:All program tokens have to be included in classes ,even main() function.In java programming,derived classes cannot have more than one super class ie.multiple in heritance is not supported.
Byte-coded:Java is compiled and interpreted language.Source code is first compiled similar to machine code but can be executed on any operating system wich has java interpreter.The interpreter reads the byt-ecode file and translates into machine language which can be directly executed by the local machine where java program is running.
Secured & Robust:Multilevel securities provided.
(1)Java pointers can be used to forge access to that part of program where access is not allowed and to access areas in memory that are supposed to be unalterable. So pointers are not supported in java.
(2)Byte code verifier: Before a java program is run,a verifier checks each byte code to make sure and assures that no viruses are there with a running applet.
Extensible: Java supports native methods written in another language,usually c++.
Multi-threaded: Java supports multiple path of execution in a program so that several tasks like rendering an image on the screen on one thread and accepting key board in put in the main thread can run simultaneously.
Exception handling mechanism:When any serious error is encountered,java creates an exception.This exception can be captured and managed by the program without system crashing.Java has its own garbage collection mechanism.User need not required to delete objects when they go out of their scope .So java is robust.
RMI supported:Java is suitable for distributed computing by providing tools for managing Remote Method Invocation .
Internet compatible: Java is net centric. Its networkability separates java from other languages.Many tell it is the language of Internet. Java applets helps to distribute executable components on Internet providing user interaction.
Flow chart for executing java programs




There are some features,whch Jav programming does not support but C++suppots:
1. Java does not support Pointers.
2. No implicit type casting.
3. No structures and unions.
4. No operator overloading .
5. No templates , header files.
6. Doesnot support multiple inheritance.