All for Joomla All for Webmasters

How to Getting Started with Java on Linux


Java on Linux

Introduction

So you’ve decided to give Linux a go and now you’re wondering just what might be available for developing with Java in a Linux environment. I will address this issue by describing how to go about getting and installing Java for Linux and highlighting some interesting sites around the net. Along the way, I will give some hints I hope will ease your experience with using Java under Linux.


Getting Java

Of course, before you can develop with Java, you first need to get your hands on the development kit. Currently, the best place to get a Linux port of Sun’s Java Development Kit (JDK) is from the Blackdown Linux Java site at www.oracle.com.

  • JDK 1.0.2

Architecture(s) supported: i386

  • JDK 1.1

Current release: 8.1 are available

Architecture(s) supported: i386, Sparc, Alpha MKLinux/PowerPC, Arm (check individual releases as it does not appear that all architectures are included in all releases)

C library supported: libc5, glibc

  • JDK 1.2

Current release: Beta 2

Architecture(s) supported: i386

C library supported: glibc2.0, glibc2.1

When you go to the download area on the Blackdown site (with mirrors worldwide), you’ll find a number of different files for each Java release. In general, the files can be broken down as follows.

  • jdk* – Java Development Kit includes everything needed to run, compile, and debug Java applets and applications; however, it does not include international converters
  • jre* – Java Runtime Environment including international character converters
  • rt* – Java Runtime Environment without international character converters
  • i18n* – international character converters
  • *native* – additional binaries that provide support for native threads; these will give an additional performance boost for your applications

Recently, International Business Machines (IBM) announced its port of the JDK to Linux. Their port of JDK 1.1.6 is currently in an Alpha release. For more information about and to download IBM’s JDK, visit IBM’s AlphaWorks site at http://www.alphaworks.ibm.com/tech/linuxjvm.

For the remainder of this article, my comments will just focus on the Blackdown site and the JDK 1.1.7 release The main reason for this is I have not had the time to download and play with IBM’s port or to spend any time with Blackdown’s 1.2 beta release.


Installing Java On a Linux System

Installing Blackdown’s distribution is almost a no-brainer. Once you’ve downloaded the file(s) you need, follow these general steps (these steps are known to work under RedHat distributions from 4.2 through 6.0 and using the bash shell):

  1. Log in as root and decide where you want to put the distribution. A good location would be in /usr or /usr/local. For the purposes of this example, let’s assume you’ve chosen /usr/local as your target directory and you’re installing the 1.1.7 JDK.
  2. Open a terminal window and change to your target directory. Keeping with our assumption from step 1., you would issue the cd /usr/local command at the prompt.
  3. Uncompress the distribution archive; it will create its own directory structure. For a tar/gzip formatted archive, you would issue the command tar zxf jdk1.1.7v3.tar.gz
  4. Make appropriate changes to your PATH and CLASSPATH variables. If you plan on using Java’s AWT and/or Swing, you will need to run X. Also, if you plan on using AWT/Swing, be sure to set and export your DISPLAY variable. This involves editing the file in which you define such resources for your system; this can be in either the /etc/profile or your login profile (.bash_profile for the bash shell) file. In either file, the format for the entries will be the same. Assuming you have uncompressed your JDK into /usr/local/jdk1.1.7v3, you would append the following to your PATH statement: /usr/local/jdk/1.1.7v3/bin

    To set up the CLASSPATH for your installation, you will need to create a new line in your configuration file and enter CLASSPATH=.:/usr/local/jdk1.1.7_v3/lib/classes.zip; then you must add CLASSPATH to the EXPORT command. When setting the CLASSPATH, be sure to include the initial period; this informs the JVM to look in the current directory for needed class files – this comes in handy when running Java applications from the command line.

    If you don’t have the DISPLAY variable set, you will need to add the following line to your configuration file DISPLAY=:0 and be sure to include DISPLAY on the EXPORT command.

    Note: When you’re entering the above information into your configuration file, you must enter the name of the directories, variables, etc. in the case shown; Linux is a case sensitive operating system and /usr/local/jdk1.1.7_v3 is not the same as /usr/local/JDK1.1.7_V3.

And that’s all there is to it.


Trying It Out

After I install the JDK, I usually perform two simple tests to confirm I’ve installed the package correctly.

  1. My first test confirms I have my PATH variable defined correctly. I go to the command line and type

javac

and press the return key. If I get the usage message, then I know my PATH statement is set properly and the system is finding the executables for the various Java tools. If I have a problem with the PATH (say, I misspelled the directory name), I will see the javac: command not found message.

  1. The next test I run is to verify that the JVM can find the Java class files to run a Java program; for this I run any already-compiled Java program (applet or application).

If you don’t have any compiled Java programs handy, create a file called hello.java with your favorite text editor and enter the following:

class hello {

public static void main (String args []) {

System.out.println (“Hello, world!”);

}

}

When you’re done, save the file as hello.java (note the file name and the class name must match in name and case). At the command line, type

javac hello.java

and press the enter key. If you get any compile errors, go back into your source file, correct the errors, and recompile the program.

On successful compilation of the program, you will see a hello.class file in the directory. This file contains your hello.java program ready for execution by the JVM. To run your program, type the following on the command line

java hello

and press the return key. The program should print the message Hello, world! and return to the command prompt. If you don’t see this message, go back into your source file and make sure you typed in the program correctly (of course, if you make any changes, you’ll have to recompile the program). If you get a Can’t find xxxx message, check that you defined CLASSPATH correctly. You can do this quickly by issuing echo $CLASSPATH at the command prompt.


What Else Blackdown Offers

In addition to the various ports of the Java environments, Blackdown also has a decent number of links to other Java-related products and services. They break down the links into three lists: JavaSoft Products, Java Tools for Linux, and 3rd Party Projects and Packages. Each of the pages provide a description of the product, a note on whether the given package is free or commercial, and a link to go to that product’s home page or download site.

The JavaSoft Products page gives you links to other Sun Java products such as Java Swing, the Hot Java Browser, the JavaBeans Development Kit, etc.

The Java Tools for Linux page lists the various web browsers, integrated development environments, just-in-time compilers, and available JVMs.

The 3rd Party Projects and Packages page describes various miscellaneous packages that don’t neatly fit in either of the other pages. If you’re interested in using Java against a database, check the links on this page for available JDBC drivers for various popular database engines running on Linux.

What is GNU/Linux OS | Commentary on the GNU/Linux Community

GNU-Linux OS
Read More

Like it? Share with your friends!

0
, 0 points

How to Getting Started with Java on Linux

log in

Become a part of our community!

reset password

Back to
log in
Choose A Format
Personality quiz
Trivia quiz
Poll
Story
List
Meme
Video
Audio
Image