Java

From LQWiki
Jump to: navigation, search

Overview

The Java technology is both a programming language and a platform. Java programs will run on any hardware that has a java virtual machine installed. The java virtual machine is software (that's why it is called "virtual") that executes the actual java programs. Even mobile phones and PDAs can be capable of running java software.

There are three scenarios for running java software:

  • Your java software is installed on your computer.
  • Your java software is installed somewhere on the web. This is called Java webstart.
  • Your java software is in a web site and shown by your browser. This is called an applet.

The Java platform has two components: the Java Runtime environment (JRE) which runs Java programs, and the Java API that is needed to build java programs from source code.

The JRE contains an executable file named java or java.exe (also called the Java virtual machine or JVM) that is capable of running java software.

Get Java

You should get java by means of your distribution, as described in installing software. For example, with SUSE Linux 11.1:

yast -i java-1_6_0-sun-1.6.0.u14-0.2.1

However, if you need a special version you will have to download it, e.g. from java.sun.com.

The Java Plugin

To display a java applet, web browsers need a java plugin. Installing it goes straightforward if you install by means of your distribution and is a bit tedious if you do not, e.g. because you need a specific version. An example easy install is given below for SUSE Linux. If you need a special version, you will have to go the generic (non-distribution-specific) way.

SUSE Linux

Start your program management

yast2 sw_single

Search for java and select the java plugin. Click on "install".

generic

Here is an example how to install a java plugin, it has been done on 2009-08-19 using SUSE Linux Enterprise Server Service Pack 2 X64. We are using firefox as browser and jre 6 update 16 as java version. The process for other distributions may work similar.

  • visit java.sun.com, download jre 6 update 16, the rpm version for "Linux". Note that you download a 32-bit plugin for 32-bit software running on a 64-bit platform.
  • install the software
# chmod 777 /root/jre-6u16-linux-i586-rpm.bin
# /root/jre-6u16-linux-i586-rpm.bin
  • find out your java path
# rpm -qa --last | tac 
[...]
jre-1.6.0_16-fcs                              Wed 19 Aug 2009 08:40:24 AM EDT
  • find out where the java plugin for the browser is stored
# rpm -ql jre-1.6.0_16-fcs | grep libjavaplugin_oji
/usr/java/jre1.6.0_16/plugin/i386/ns7-gcc29/libjavaplugin_oji.so
/usr/java/jre1.6.0_16/plugin/i386/ns7/libjavaplugin_oji.so

You see there are two java plugins, one for distributions compiled with GCC 2.9 and the other for newer distributions.

  • go to your firefox path
# which firefox
/usr/bin/firefox
# cd /usr
# cd lib/firefox/
  • go to your plugin directory
# cd plugins/
  • link the plugin file into the plugin directory
# ln -s /usr/java/jre1.6.0_16/plugin/i386/ns7/libjavaplugin_oji.so . 
  • stop all firefox
# killall firefox-bin
  • start firefox
# firefox
  • surf to about:plugins. You must find a java plugin in the list there.

The Java Programming Language

The Java programming language is a high-level, multi-threaded, object oriented, usually interpreted language.

Language Features

Java's main advantages are that it is extremely portable and that it is easily incorporated into web pages in the form of applets. Other features include automatic garbage collection and optional security - one does not need to give a Java program full access to one's computer.

If you are making changes to an existing Java program, the class file structure allows source compatibility and binary compatibility to be essentially the same thing. Significant additions can be made to large programs with recompilation required for only the altered parts. In general, Java allows for easier program alteration than native code compiled languages.

See also