Java programming language

HomePage | Recent changes | View source | Discuss this page | Page history | Log in |

Printable version | Disclaimers | Privacy policy

The Java language is an object-oriented programming language created by James Gosling and other engineers at Sun Microsystems. It was officially announced on May 23, 1995, at SunWorld. The Java programming platform is based upon the language, the Java virtual machine, and the Java API.

There were four primary goals in the creation of the Java language:

  • It is object-oriented.
  • It is independent of the host platform.
  • It contains language facilities and libraries for networking.
  • It is designed to securely execute code from remote sources.

The first characteristic, object orientation, refers to a modern method of programming and language design. Its purpose is to make large software projects easier to manage and to improve quality and reduce the number of failed projects.

The second characteristic, platform independence, means that programs written in the Java language must run similarly on diverse harware. One should be able to write a program once and run it anywhere. This is achieved by compiling Java language code "halfway" to bytecode--simplified machine instructions that conform to a set standard. The code is then run on a virtual machine, a program written in native code on the host hardware that translates generic Java bytecode into usable code on the hardware. Further, standardized libraries are provided to allow access to features of the host machines (such as graphics and networking) in unified ways. The Java language also includes support for multi-threaded programs--a necessity for many networking applications.

The first implementations of the language used an interpreted virtual machine to achieve portability, and many implementations still do. These implementations produce programs that run more slowly than the fully-compiled programs created by the typical C++ compiler and some later Java language compilers, so the language suffered a reputation for producing slow programs. More recent implementations of the Java VM produce programs that run much faster, using multiple techniques.

The first of these is to simply compile directly into native code like a more traditional compiler, skipping bytecodes entirely. This achieves great performance, but at the expense of portability. Another technique, the just-in-time compiler or "JIT", compiles the Java bytecodes into native code at the time the program is run. More sophisticated VMs even use dynamic recompilation, in which the VM can analyze the behavior of the running program and selectively recompile and optimize critical parts of the program. Both of these techniques allow the program to take advantage of the speed of native code without losing portability.

Portability is a technically difficult goal to achieve, and Java's success at that goal is a matter of some controversy. Although it is indeed possible to write programs for the Java platform that behave consistently across many host platforms, the large number of available platforms with small errors or inconsistencies led some to parody Sun's "Write once, run anywhere" slogan as "Write once, debug everywhere".

The Java platform was one of the first systems to widely support the execution of code from remote sources. An applet could run within a user's browser, executing code downloaded from a remote HTTP server. The remote code runs in a highly restricted "sandbox", which protects the user from misbehaving or malicious code; publishers could apply for a certificate that they could use to digitally sign applets as "safe", giving them permission to break out of the sandbox and access the local filesystem and network, presumably under user control.

In most people's opinions, Java technology manages to reasonably deliver on all these goals. The language is not, however, without drawbacks. Some features of C++ that the Java language lacks, such as hardware-specific data types, low-level pointers to arbitrary memory addresses, or programming methods like operator overloading, can be abused or misused by programmers but are also powerful tools. (However, Java technology includes Java Native Interface, a way to call native code from Java language code.) Some programmers also complain about its lack of multiple inheritance, a powerful feature of C++ and other object-oriented languages. The Java language separates inheritance of type and implementation, allowing inheritance of multiple type definitions through interfaces, but only single inheritance of type implementation via class hierarchies. This allows most of the benefits of multiple inheritance while avoiding many of its dangers. In addition, through the use of concrete classes, abstract classes, as well as interfaces, a Java language programmer has the option of choosing full, partial, or zero implementation for the object type he defines, thus ensuring maximum flexibilty in his application design.

There are some who believe that for certain projects, object orientation makes work harder instead of easier (this particular complaint is not unique to the Java language but applies to other object-oriented languages as well).

An example of a hello world program in the Java language follows:

public class HelloWorld
    public static void main(String[] args)
        System.out.println("Hello world!");

See also: Java programming platform, How to program in Java, Java API, Java virtual machine, GCC.

Java is a trademark of Sun Microsystems.

External links: