Java

[Note]

For PowerPC machines, see Ubuntu Help Online.

Java, developed by Sun Microsystems, is and interpreted language which is compiled to bytecode. This bytecode can be run on any Java Virtual Machine, making Java a highly portable language. It is object oriented, has similar syntax to C and is designed to be secure.

Installation

Ubuntu supports both Java 1.5 and 1.6 in both Sun and Open Source flavors.

JDK 1.5

  1. Install sun-java5-jdk from the “Multiverse” repository (see Add Applications). You will need to use Synaptic Package Manager to install these packages.

  2. Read the Java license presented. You must accept it to continue.

  3. To get your system to use Sun Java instead of the open-source (but less functional) GIJ that is installed by default, run:

    sudo update-alternatives --config java

    and choose the option that has j2re1.5-sun in it.

JDK 1.6

Java 1.6 is also available, and can be installed by following the above directions, swapping all instances of 1.5 to 1.6

  1. Install sun-java5-jdk from the “Multiverse” repository (see Add Applications). You will need to use Synaptic Package Manager to install these packages.

  2. Read the Java license presented. You must accept it to continue.

  3. To get your system to use Sun Java instead of the open-source (but less functional) GIJ that is installed by default, run:

    sudo update-alternatives --config java

    and choose the option that has j2re1.6-sun in it.

Hello World

Enter the following code into a text editior and save it as "Hello.java":

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

Open a terminal and run your code by typing:

javac Hello.java; java Hello

Integrated Development Environments

Eclipse IDE for Java

The Eclipse platform provides a complete, extensible Java development environment.

  1. Install the eclipse package from the “Universe” repository (see Add Applications).

  2. Press ApplicationsProgrammingEclipse IDE to start using Eclipse.

Netbeans

The Netbeans platform provides a complete, extensible Java development environment.

  • Install the Netbeans package from the “Universe” repository (see Add Applications).