PreviousTOCNext

Java

Brief Description

Java started out as a programming language for consumer electronics. Software for consumer electronics has some unique requirements. For example, the software needs to run on new chips as they are introduced. As prices change for computer chips, the manufacturers will switch to the now less expensive computer chip. This means the software must be platform independent. The type of software must also be extremely reliable, often when a unit fails, the consumer will demand it be replaced. [4]

The Java language was originally called Oak. Oak never really caught on, yet a development team headed by James Gosling continued to work on this new programming environment. With the explosion of the Internet it was quickly realized by Sun Microsystems that Oak (now called Java) fit the Internet model quite well. Java was released in Alpha form to the Internet in 1995. [4] [5] [6]

Java has been described by Sun as having the following characteristics [4] [5] [6] [7] :

  • Simple: it is a language that can be learned quickly, similar in syntax to C/C++.
  • Object-Oriented: it is made up of classes, where a class is a collection of data and methods that operate on data. The data and methods describe the state and behavior of an object. It has strong type checking.
  • Architecture Neutral: Java programs are compiled into Byte-codes which is a machine independent format that allows these to be run on any platform.
  • Portable: besides being architecture neutral, Java has also gone to great lengths to ensure its portability. Portability features include things like explicitly specifying the size of primitive data types and arithmetic behavior.
  • High Performance: Java is in the middle of other development languages for speed. It is not as fast as C/C++, but it is much better then scripting languages such as TCL or the UNIX shell. With the release of Just-In-Time compilers Java is coming much closer to C/C++ performance while retaining all the important characteristics of Java.
  • Multi-threaded: Java provides native support for multiple threads of execution that can handle different tasks. Multi-threading greatly improves the performance of many applications, especially graphical applications. It is accomplished by having different threads handling separate aspects of the user interface. A graphical program can also gain a lot by having separate threads responsible for interacting with other network resources such as databases or application servers.
  • Dynamic: Java loads classes as they are needed. Java programs can also determine what class an object belongs to during execution by performing run time type checking. Run time type checking makes it possible to dynamically link classes into a running system.

Features

Here are the most significant features of the Java programming language: [2]

  • platform independent / architecture neutral
  • transparent memory management (garbage collection)
  • standard class libraries (AWT, RMI, JDBC, etc.)
  • standard component model 'Java Beans'
  • grouping of classes to libraries (packages)
  • strong type checking (and bounds checking for arrays)
  • documentation tool (Javadoc)

Java source code is compiled into architecture neutral bytecodes. A Virtual Machine (VM), which has to be implemented on each architecture, interprets these bytecodes. The Java Virtual Machine (JVM) takes each instruction (bytecode) and executes that instruction on the programs behalf. So a Java program does not actually execute on the CPU; instead it is executed by a "virtual" CPU. To increase execution speed of Java programs, there are also just-in-time (JIT) compilers translating the bytecodes into native platform machine code at runtime. [2] [12]

Compared to C/C++, there are no pointers, no addresses, no operator overloading, no structures, no functions, no multiple inheritance, no header files and no object files to be linked together to produce an executable. Before executing bytecode in the VM, memory is laid out only after the byte codes have been verified by the Java runtime environment and security manager. These simplifications of the language and additional verifications before and during program execution lead to more robust and secure applications. [2] [6]

Java Applications

Java applications are stand-alone programs, running in a virtual machine (not inside a Web browser). By default, every class inherits from the Object class, which supplies a basic set of methods. There is also a main method which is executed after instantiation of the object. Constructor methods can be used to initialize an object; which can be overloaded, so that different parameters to the object can cause different behavior. [2]

The famous "HelloWorld" program in Java looks like [2]

class HelloWorldApp {

    public static void main(String[] args) {

        System.out.println("Hello World!");

    }

}

Java also offers a native interface (JNI) to access already implemented functionality in C/C++ which helps promote reusability of legacy applications. This interface can only be used in Java applications (and not in Applets), because these functions are not written in Java. This would open a hole in the "sandbox" within browsers and would limit cross platform portability. [2]

Java Applets

To run an Applet, it has to be called from an HTML web page that can be viewed in an Appletviewer or in a Java enabled Web browser. There is a special HTML tag to run an Applet inside the HTML page:

<APPLET CODE ="HelloWorld.class" WIDTH=100 HEIGHT=50>

</APPLET>

Unlike applications, Applets must be a subclass of java.applet.Applet. The HelloWorld program implemented as an Applet would look like this:

import java.applet.Applet;

import java.awt.Graphics;

public class HelloWorld extends Applet {

    public void paint(Graphics g) {

        g.drawString("Hello world!", 50, 25);

    }

}

Applets have more restrictions than Java applications. They have no access to the file system and they can only access the server where the Applet was loaded. For this reason, there's no possibility for an Applet to alter anything on the client's computer, like reading/writing/deleting files, or starting programs. This behavior is also known as the 'sandbox model'. The Applet is only able to play (and mess up) within the confines of the Java Virtual Machine. This makes it virtually impossible to receive a virus from a Java applet. [2] [4]

PreviousTOCNext

Return to Gerber Family Home Page
directNIC Search
Hosted by directNIC.com