Java

introduction

Java is a modern object-oriented, network-oriented programming language sponsored by Sun Microsystems. To try it, use an editor such as emacs or kwrite to create a simple Java source file such as the following from the fine text, "Introduction to Programming Using Java: An Object-Oriented Approach, Java 2 Update," by David Arnow and Gerald Weiss (Addison-Wesley, 2000):

//------------
// Introduction to Programming Using Java: An Object-Oriented Approach
//	Arnow/Weiss
//------------

//------------
// Chapter 1 / Section 1.1 / Page 2
//	A first, small Java program
//------------ 

//------------
// Notes
//	To compile, rename (or copy) the source file to Program1.java
//------------

import java.io.*;

class Program1 {
	public static void main(String arg[]) {
		System.out.println("Welcome To Java!");
	}
}

and name that file "program1.java." To compile the program, invoke the Java compiler by typing

javac program1.java

at a command line prompt. This creates a Java bytecode translation named program1.class. To run that program, invoke the Java interpreter by typing

java program1

at a command line prompt. You should see the response

Welcome to Java!

For a fancier introduction, compile and interpret this second example, based on a demo file from chapter three of the text by Arnow and Weiss. When you run it, this short program will prompt you to enter a URL. Enter something like

http://www.whitehouse.gov

It will then ask for the name of a file to write to. Type something like

whitehouse.html

The program will then fetch the html code from the White House web page and write it to the file you designated. Typing

less whitehouse.html

displays the result on your terminal. The fact that the responsible program is so short, and that this program appears as early as chapter three (of fourteen chapters) in Arnow-Weiss is an indication of the power and ease of use of Java.

software name and current version

documentation

There is extensive help available for Java.

downloads

Go to the Java download page and fetch the appropriate rpm file. You may have to register with Sun Microsystems (for free) to access this page.

installation instructions (as root)

To view and accept the licence and inflate the rpm package, type

		chmod u+x j2sdk-1_3_1_01-linux-i386-rpm.bin
  ./j2sdk-1_3_1_01-linux-i386-rpm.bin

Install the executables with

  rpm -Uvh jdk-1.3.1_01-i386.rpm

The Java software is installed into /usr/java. Finally, add the path to the Java executables to the list of directories in your PATH variable in the file .bash_profile:

PATH=$PATH:$HOME/bin:/usr/java/jdk1.3.1_01/bin:.
JAVA_PATH=/usr/java/jdk1.3.1_01/bin
export JAVA_PATH

Now log out and log back in again to force bash to read the updated .bash_profile, and test your installation by compiling and interpreting an example such as the one described at the top of this page.

There is nice introduction to programming with Java in a Linux environment at the Sun Microsystems Java Developer Connection: "Java Technology on the Linux Platform, A Guide to Getting Started," By Calvin Austin.


cparrish@sewanee.edu