Java Programming Language

« BACK TO DICTIONARY INDEX

Java allows a client computer with its own runtime environment to execute dynamic applications independently from a networked host. A Java program may be downloaded and run dynamically from a web server. The language is a secure, high-performance, portable development environment for distributing dynamic content over the Internet. Using Java eliminates the need to port an application to each different platform because the same executable runs on any computer with the proper interpreter, or “virtual machine”, and with the necessary class objects. Java provides its own memory management in the form of an automatic garbage collector, which runs as a separate thread. When there are no references to an object, the garbage collector tags it for removal.

The development of Java began in 1991 by James Gosling, an employee of Sun Microsystems, who was charged with building a programming language that would operate on any platform. He began by attempting to extend the C++ compiler, but soon realized that he needed to create a new language. It eventually became known as Java, after failing a trademark search under the name of “Oak.” Originally it was intended for consumer electronic devices, and prototypes were built in 1993. The World Wide Web was growing in significance, and in 1994 Sun developed a Java-capable browser called WebRunner. It later became known as HotJava.

Java consists of three interdependent components. The first is a programming language in which the code needed for applications is written. The second is the run-time environment, or Java Virtual Machine, which provides the architecture for applications. The third is the set of tools with which to build, compile, and run applications: the Java compiler, the Java interpreter, and the HotJava browser. The compiler lets programmers create machine-independent bytecode, which runs under the interpreter and browser environments.

At the heart of the Java package is a set of class libraries for the browser and the interpreter, the routines that programmers use to perform basic functions. These class libraries are a package of predeveloped and pretested code, which can be linked to create individual applications. Some of the common libraries are as follows:

  • Applets: Utilities needed for interaction with any Java-enabled browser.
  • AWT: Abstract Windowing Toolkit; the graphic interface tools including fonts, buttons, controls, and scrollbars.
  • I/O: Standard provision for input and output, along with file utilities.
  • Language Foundation: Classes for strings and arrays, part of the basic structure of Java.
  • Network: Utilities for accessing network protocols like FTP, Telnet, and the web.
  • Utility: Provision for stacks, vectors, encoding/ decoding, and hash tables.

Although Java is similar in many ways to C++, it does not allow a procedural approach since it is thoroughly object-oriented. In addition to the capabilities of C++, Java adds automatic boundary checking by eliminating pointers, and it performs automatic garbage collection. Due to its multithreading features, it can take care of these memory management functions in the background.

In Java the fundamental unit, or object, is referred to as a class. A class is a grouping of code that models the behavior of an object in software. A faucet is an example of an object in real life. All objects have a state, and the state of the faucet could be on or off, or perhaps hot or cold. The state of an object is described by instance variables. Variables that are controlled by a class are inaccessible to any other class, except under special conditions. The flow of water is controlled by turning a faucet on or off. In Java, a method is used to control a class, or object. A method is a small body of code that performs a function that can be reused. The functions of a class are limited to what is prescribed by its methods. In the plumbing of a building there are many faucets, but they are identical in function. Each faucet (class) may be either on or off (instance variable) by turning it (method). A class (faucet) must only be created once, after which it may be reused many times. Another instance of the faucet may be created, or reproduced, without reinventing the object. A method is all that is needed to control any number of instances of a class.

Another important aspect of an object is that each instance inherits the characteristics or properties of the original object. Some aspects of a new class may be changed, while the new class retains all the properties of the old class. The new faucet could be made of brass instead of chrome. The new class becomes a subclass of the original superclass. A class is simply a template for future instances of an object.

In Java a package is a single compilation unit which is a collection of similar classes, and access modifiers control access to methods and variables. Four levels of access are defined: Public, Private, Protected, and Friendly. Public methods are freely accessible. Private methods are accessible only to the class itself. Protected variables are accessible only through methods in a given class and its subclasses. Friendly methods and variables are accessible to any classes in the same package. A program is written by creating a class, and a class is automatically a subclass of the superclass Object. Other superclasses are Applet and Thread.

Java is quite different conceptually from C++. There are no pointers, no goto statements or individual functions, no multiple inheritance, and no type definitions. There are no structures or unions. Instead of header files, Java uses interfaces. The interface is the means by which other classes see what methods a class may implement. Java keeps track of all references to an object, and when there are no longer any references to it, Java removes it with the garbage as a low-priority thread in the background.

Java provides portability by compiling bytecode, which is interpreted on each platform by the run-time environment, or Java Virtual Machine (JVM). The bytecode is an executable program for the Virtual Machine, which exists only in software. The code is then interpreted and executed on the target hardware itself. All code will run on any computer for which an interpreter has been ported. Memory layout problems are solved by deferring symbolic reference to the interpreter at run time.

The robustness of Java is due in large part to its automatic memory management and strict compile-time and run-time checking. In C++, memory is addressed by the use of pointers, or variables that hold the address of the memory range used. A pointer could be misdirected to the wrong location. Java eliminates the pointer and encapsulates memory usage into classes. The syntax is strictly checked for errors upon compilation and again as it is interpreted at run time.

Multithreading is included at every level in Java, beginning at the syntactical level with synchronization modifiers in the language. Multitasking is the act of running two or more applications at once in an operating system. Multithreading is the act of executing more than one thread at once while running a single application.

Java is a secure environment for several reasons. The first stage in the interpreter is a bytecode verification to test whether code conforms to Java specification as it is received. Then the interpreter provides a distinct name space for each class that is uploaded, preventing accidental name references. Since there are no pointers when it is compiled, Java is immune to memory allocation problems. At run time it does not allow illegal processes, incorrect parameters, or violation of access restrictions.

Information about Java may be found at these web sites:

Scroll to Top