JAVA

Java is a general - purpose, object oriented programming language developed by Sun Micro systems of USA in 1991. Originally called Oak by James Gosling, one of the inventors of the language, Java was designed for the development of software for consumer electronic devices like TVs, VCR's, toasters and such other electronic machines. This goal had a strong impact on the development team to make the language simple, portable and highly reliable. The Java team which included Patrick Naught on discovered that the existing language like C and C++ that were considered as sources of problems and thus made Java a really simple, reliable, portable, and powerful language.

JAVA FEATURES


The inventors of java wanted to design a language which could offer solutions to some of the problems encountered in modern programming. They wanted the language to be not only reliable, portable and distributed but also simple, compact and interactive. Sun Microsystems officially describes java with the following attributes:

  • Compiled and Interpreted

  • Platform-Independent and portable

  • Object-Oriented

  • Robust and secure

  • Distributed

  • Familiar, Simple and Small

  • Multithreaded and Interactive

  • High Performance

  • Dynamic and Extensible

Although the above appears to be a list of buzzwords, they aptly describe the full potential of the language of the World Wide Web. Java will also become the premier language for general purpose stand-alone applications.

HOW JAVA DIFFERS FROM C AND C++


Although Java was modeled after C and C++ language, it differs from C and C++ in many ways. Java does not incorporate a number of features available in C and C++. For the benefit of C and C++ programmers, we point out here a few major differences between C/C++ and Java language.

JAVA AND C


Java is a lot like C but the major difference between Java and C is that Java is an object-oriented language and has mechanism to define classes and objects. In an effort to build a simple and safe language, the Java team did not include some of the C features in Java.

  • Java does not include the C unique statement keywords goto, sizeof, and typedef.

  • Java does not contain the data type struct, union and enum.

    • Java does not support operator overloading.

    • Java does not have template classes as in C++.

    • Java does not support multiple inheritance of classes. This is accomplished using a new feature called “interface”.

    • Java does not support global variables. Every variable and method is declared within a class and forms part of that class.

    • Java does not use pointers. Java has replaced the destructor function with a finalize () function.

    • here are no header file in Java.

      • Java does not define the type modifiers keywords auto,extern,register,signed, and

      • Java does not support an explicit pointer type.

      • Java does not have a pre-processor and therefore we cannot use # define, # include, and # ifdef

      • Java does not support any mechanism for defining variable arguments to functions.

      • Java requires that the functions with no arguments must be declared with empty parenthesis and not with the void keyword as done in C.

      • Java adds new operators such as instanceof and >>>.

      • Java adds labeled break and continue

      • Java adds many features required for object-oriented programming.

      JAVA AND C++


      Java is a true object-oriented language while C++ is basically C with object-oriented extension. That is what exactly the increment operator ++ indicates. C++ has maintained backward compatibility with C. It is therefore possible to write an old style C program and run it successfully under C++. Java appears to be similar to C++ when we consider only the “extension” part of C++. However, some object-oriented features of C++ make the C++ code extremely difficult to follow and maintain.

      Listed below are some major C++ features that were intentionally omitted from Java or significantly modified.

      • Java does not support operator overloading.

      • Java does not have template classes as in C++.

      • Java does not support multiple inheritance of classes. This is accomplished using a new feature called “interface”.

      • Java does not support global variables. Every variable and method is declared within a class and forms part of that class.

      • Java does not use pointers. Java has replaced the destructor function with a finalize () function.

      • There are no header file in Java.

      JAVA AND INTERNET


      Java is strongly associated with the internet because of the fact that the first application program written in Java was Hot Java , a Web browser to run applets on Internet. Internet users can use Java to create applet programs and run them locally using a “Java-enabled browser” such as Hot Java. They can also use a Java-enabled browser to download an applet located on a computer anywhere in the Internet and run it on his local computer .in fact, Java applets have made the internet a true extension of the storage system of the local computer.Internet users can also set up their Web site containing Java applets that could be used by other remote users of Internet. The ability of Java applets to hitch a ride on the Information Superhighway has made Java a unique programming language for the Internet. In fact, due to this, Java is popularly known as Internet language.

      JAVA AND WORLD WIDE WEB

      World Wide Web (WWW) is an open –ended information retrieval system designed to used in the Internet’s distributed environment. This system contains what are known as Web pages that provide both information and controls.

      Hot Java


      Hot Java is the Web browser from Sun Micro-systems that enables the display of interactive content on the Web, using the Java language. Hot Java is written entirely in Java and demonstrates the capabilities of the Java programming language.

      When the Java language was first developed and ported to the internet, no browsers were available that could run Java applets. Although we can view a Web page that includes Java applets with a regular browser, we will not gain any of Java’s benefits. HotJava is currently available for the SPARC/Solaris platform as well as  Windows 95 and Windows NT. So for as being a Web browser goes, it is nothing special and does not offer anything special that most other Web browsers don’t offer. Its biggest draw is that it was the first Web browser to provide support for the Java language, thus making the Web more dynamic and interactive.

      Data Abstraction and Encapsulation


      The wrapping up of data and methods into a single unit (called class) is known as encapsulation. Data encapsulation is the most striking feature of a class. The data is not accessible to the outside world and only those methods, which are wrapped in the class, can access it. These methods provide the interface between the object’s data and the program. This insulation of the data from direct access by the program is called data hiding. Encapsulation makes it possible for objects to be treated like ‘black boxes’, each performing a specific task without any concern for internal implementation.

      Inheritance


      Inheritance is the process by which objects of one class acquire the properties of objects of another class. Inheritance supports the concept of hierarchical classification. In OOP ,the concept of inheritance provides the idea of re-usability. This means that we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have the combined features of both the classes. Thus the real appeal and power of the inheritance mechanism is that it allow the programmer to reuse a class that is almost, but not exactly, what he wants, and to tailor the class in such a way that it does not introduce any undesirable side effects into the rest of the classes. In Java, derived class is known as ‘subclass’.

      Note that each subclass defines only those features that are unique to it. Without the use of inheritance, each class would have to explicitly include all of its features.

      Polymorphism


      Polymorphism is another important OOP concept. Polymorphism means the ability to take more than one form. For example, an operation may exhibit different behavior in different instances.   The behavior depends upon the types of data used in the operation. Polymorphism plays an important role in allowing objects having different internal structures to share the same manner external interface. This means that a general class of operations may be accessed in the same manner even though specific actions associated with each operation may differ. Polymorphism is extensively used in implementing inheritance.

      HARDWARE AND SOFTWARE REQUIREMENTS


      Java is currently supported on Windows 10, Windows NT, Sun Solaris, Macintosh, and UNIX machines.

      The minimum hardware and software requirements for Windows 10 version of Java are as follows:

      • Minimum of 8 MB memory

      • A hard drive

      • A CD-ROM drive

      • A Windows-compatible sound card, if necessary

      JAVA SUPPORT SYSTEMS


      It is clear from the discussion we had up to now that the operation of Java and Java enabled browsers on the Internet requires a variety of support system.

      • Internet Connection

      • Web Server

      • Web Browser

      JAVA ENVIRONMENT


      Java environment include a large number of development tools and hundreds of classes and methods. The development tools are part of the system known as Java Development Kit (JDK) and the classes and methods are part of the Java Standard Library (JSL).

      Java Development Kit


      The Java Development Kit comes with a collection of tools that are used for developing and running Java program. They include:



      • appletviewer (for viewing Java applets)

      • javac (compiler)

      • java (interpreter)

      • javap ( disassembler)

      • javah (for C header files)

      • javadoc (for creating HTML documents)

      • jdb (debugger)

       

      Java Standard Library


      The Java Standard Library includes hundreds of classes and methods grouped into six



        • functional packages.

        • Language Support Package

        • Utilities Package

        • Input/Output Package

        • Networking Package

        • AWT Package

        • Applet Package

      SIMPLE JAVA PROGRAM

      The best way to learn a new language is to write a  simple example program and execute them. We begin with a very simple program that prints a line of text as output.

      class SampleOne

      {

      Public static void main (String args[ ])

      {

      System.Out .Println(“Java is better than  C++.”) ;

      }

      }


      Class Definitions -


      A Java program may contain multiple class definitions. Classes are the primary and essential elements of a Java program. These classes are used to map the objects of real world problems. The number of classes used depends on the complexity of the problem.

      identifiers –


      Identifiers are programmer- designed tokens. They are used for naming classes, methods, variables, objects, labels, packages and interface in a program. Java identifiers follow the following rules:

      1. They can have alphabets, digits, and the underscore and dollar sign characters.

      2. They must not begin with a digit.

      3. Uppercase and lowercase letters are distinct.

      4. They can be of any length.

      Identifier must be meaningful, short enough to be quickly and easily typed and long enough to be descriptive and easily read.

      Literals


      Literals in Java are a sequence of characters (digits, letters, and other characters) that represent constant values to be stored in variables. Java language specifies five major types of literals. They are:

      • Integer Literals

      • Floating_point Literals

      • Character Literals

      • String Literals

      • Boolean Literals

      Operators


      An operator is a symbol that takes one or more arguments and operates on them to produce a result.

      Separators


       Separators are symbols used to indicate where groups of code are divided and arranged. They basically define the shape and function of our code.
ShowHideComments