Java programming language

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”.

Secure execution of remote code

The Java platform was one of the first systems to provide wide support for 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 delivers reasonably well on all these goals. The language is not, however, without drawbacks.

Java tends to be more high-level than similar languages (such as C++), which means that the Java language lacks features such as hardware-specific data types, low-level pointers to arbitrary memory addresses, or programming methods like operator overloading. Although these features are frequently abused or misused by programmers, they are also powerful tools. However, Java technology includes Java Native Interface (JNI), a way to call native code from Java language code. With JNI, it is still possible to use these features.

Some programmers also complain about its lack of multiple inheritance, a powerful feature of several object-oriented languages, among others C++. 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 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!”);

Control structures


while (Boolean expression) {

do {
} while (Boolean expression);

for (initialisation ; termination condition ; incrementing expr) {

Conditional statements

if (Boolean expression) {

if (Boolean expression) {
} else {

With else if arbitrarily complex if-then-constructions may be built.

if (Boolean expression) {
} else if (Boolean expression) {
} else if (Boolean expression) {
} else {

switch (integer expression) {
case constant integer expr:


Exception handling

try {
} catch (exception type) {
} catch (exception type) {
} finally {

Goto statements

It is possible to put a label before any statement

myLabel: aJavaStatement;

The command


terminate the current loop.

The label may be used to jump out of a inner for, while or do-loop

break myLabel;

A continue-expression terminates the current interation step and starts the next one


In addition with

continue label;

program control may be handed directly to an outer loop.

The statement


terminates a method.


return aValue;

aValue may be given back to the calling method.

Primitive data types

Variable Type Description
byte 8-bit signed (two’s complement) integer
short 16-bit signed (two’s complement) integer
int 32-bit signed (two’s complement) integer
long 64-bit signed (two’s complement) integer
float 32-bit single-precision floating point (IEEE 754 standard)
double 64-bit double-precision floating point (IEEE 754 standard)
char 16-bit single Unicode character
boolean true or false

Characters use the 16-bit Unicode encoding. It contains all of the usual characters, but also includes character sets for many languages other than English, including Greek, Cyrillic, Chinese, Arabic, etc. Java programs can use all of these characters, although most editors do not have built-in support for character sets other than the usual ASCII characters. Arrays and strings are not primitive types: they are objects.


* JDK 1.0 1996, Solaris, Windows, MacOS Classic, Linux
* JDK 1.1 1997, Solaris, Windows, MacOS Classic, Linux
* JDK 1.2 1998, Solaris, Windows, Linux, ?
* JDK 1.3 2000 (also known as Java 2), Solaris, Windows, MacOS X, Linux
* JDK 1.4 2002, Solaris, Windows, MacOS X, Linux
* JDK 1.5 2003 (yet to be released)

Java was initially released as the Java Development Kit 1.0 (JDK 1.0). This included the Java runtime (the virtual machine and the class libraries), and the development tools (e.g. the Javac compiler). Later, Sun also provided a runtime-only package, called the Java Runtime Environment (JRE). The first name stuck, however, so usually people refer to a particular version of Java by its JDK version (e.g. JDK 1.4). The JDKs of version 1.2 and later versions are often called Java 2 as well. For example, the official name of JDK 1.4 is The Java(TM) 2 Platform, Standard Edition version 1.4.

The language as such has been stable since JDK 1.0; the class libraries that come with the JDK got larger and have changed in some parts. Extensions and architectures closely tied to the Java programming language include: J2EE, J2ME, JNDI, JSML, JDBC, JAIN, JDMK[?], Jini[?], Jiro[?], JXTA, JavaSpaces[?], JMI[?].

1.5 (codename[?] Tiger) is scheduled to be released in late 2003. Major changes include:

* Generics – Provides compile-time type safety for collections and eliminates the drudgery of casting.
* Autoboxing/unboxing – Eliminates the drudgery of manual conversion between primitive types (such as int) and wrapper types (such as Integer).
* Metadata – Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a “declarative” programming style where the programmer says what should be done and tools emit the code to do it.

(from [1] (

Interpreted version

There is an interpreted version of Java called beanshell which may be used as a shell scripting language. The interpreter may be embedded in a Java application to make it scriptable.

A good starting point for learning Java is the Sun tutorial on Java Programming, found at

Another very helpful page for beginners and experts alike is the current Java Syntax page for the latest Java API, Java 2 v1.4.2, also from the Sun site, found at

See also

* Java platform
* Java API
* Java virtual machine
* gcc (includes a Java to machine language compiler)
* Comparison of Java to C++.
* Eclipse (Open source IDE)
* NetBeans (Another open source IDE)
* Optimization of Java