Jul 26, 2013

LEARNING JAVA

Introduction:
Java is an object-oriented programming language, which can be used to do any of the thousands of things that a computer software can do. With the features it offers, Java has become the language of choice for internet and intranet applications. Java plays an important role in the proper functioning of many software-based devices attached to a network. The kind of functionality the java offers has contributed a lot towards the popularity of Java.

                   Java is both, a programming language and a platform. Like any other programming language, you can use java to write and create various types of computer applications. Java is also a platform for application development. The word 'platform' generally is used to refer to some combination of hardware and system software.


JAVA Programs    



History of Java:
In the following lines, the history of java can be found out in the java timeline.

1991: James Gosling develops Oak(later renamed java) language for programming intelligent consumer electronic devices.

1993: World Wide Web explodes.

1995: Java formally announced. Incorporated into Netscape web browser.

1996: Java development kit (JDK) 1.0 ships. java beans component architecture Corel Office for java preview. Sun announces java station network computer. Sun announces 100% pure java initiative.

1997: JDK 1.1 launched. Java servlet API released.

1998: JDK 1.2 launched. Sun introduces community source 'open' licensing. Sun produces a JDK 1.2 for Linux.

1999-2001: JDK 1.3 released. JDK's also produced by IBM on multiple platforms. Java-based application servers (BEA, IBM Websphere etc.) become popular. J2EE (Java 2 Enterprise Edition), J2SE(Java 2 Standard Edition), J2ME(Java 2 Micro Edition) appear.

2002: Java support for web services officially released via the java web services developer pack.

Characteristics of Java:
1.Write once run anywhere(WORA):  The java programs need to be written just once, which can be run on different platforms without making changes in the java program.

2.Lightweight code:  With Java, big and useful applications can also be created with very light code. No huge coding is required.

3.Security:  Java offers many security features to make its programs safe and secure.

4.Built-in graphics:  Java offers many built-in graphics features and routines which can be used to make java application more visual.

5.Object-oriented language:  Java is an object-oriented language, thereby, very near to the real world.

6.Supports multimedia:  Java is ideally suited for integration of video, audio, graphics, and animation in the internet environment.

7.Platform independent:  Java is essentially platform independent. Change of platform does not affect the original java program or application.

8.Open product:  Java is an open product, freely available to all. However, there exist some special time-saving java development kits, which can be availed by paying small amounts.

Types of Java:
There are two types of Java programs.
1.Internet Applets:  Internet applets are small programs that are embedded in web pages and are run on the viewer's machine in a secured manner by java capable browsers. Applets are designed to be delivered to internet web browsers and that is why an applet has a built-in graphical window. But Java applets have some security restrictions.

2.Stand Alone Applications:  These type of java program is much more interesting. It is generally a software application that does not require low-level operating system or hardware access. This includes most of the usual desktop applications such as word processors or spreadsheets. Stand-alone Java applications could be distributed on standard ISO 9660 format CD-ROMs and installed on any Java-capable machine. Every stand-alone application of java begins executing with the main method. 

Some Simple Java Programs:
Let us now have a look at an example java program. Following lines show a simple and short example java program - Hello World.

Example-1

                          /*program Hello World*/
                             class Hello World
                      {
                             public void say Hello( )
                              {
                                     system.out. printIn("Hello World!!");
                                 }
                           }         //class definition ends here

          Let us now examine parts of this sample program.

class Hello World
                       The line class Hello World means that a class is being defined. After the class name, the data members and member functions of the class are defined within curly braces{}.

Method say Hello
                     The Hello World class contains one method - the Say Hello method. This is a member function of class Hello World.

System.out.printIn("Hello World!!")
                       This statement prints Hello World!! on the standard output device which is generally your monitor.

Comments /* .....*/ and // ....
                        The text enclosed within /*...... */, called comments, is purely for enhancing readability. The comments are ignored by the compiler and not executed at all even if you write a valid Java statement within /*......*/. within /*........*/, multi-line comments can be inserted but with // .... only single line comment can be inserted.


Example-2

/* java short example 
    this java example shows how to declare and use java primitive short variable
inside a java class.
*/

       public class JavaShortExample {
              public static void main(String[]args) {
  
              /*
               *short is 16 bit signed type ranges from - 32,768 to 32,767.
               *
               *Declare short variable as below
               *
               *short <variable name> = <default value>;
               *
               *here assigning default value is optional.
               */

                 short s1 = 45;
                 short s2 = 35;

            system.out.printIn("value of short variable b1 is :"+s1);
            system.out.printIn("value of short variable b1 is :"+s2);
         }
 }

/*

             output would be.... 
               value of short variable b1 is :45
               value of short variable b2 is :35
*/ 
       


3 comments:

Post a Comment

Share

Twitter Facebook Digg Stumbleupon Favorites More