GETTING UP AND RUNNING WITH JAVA

By: Maria Russell

What Is Java?

Java is a fully object oriented language. The programs written in Java can stand alone or can be modified slightly to run inside a Web page. A Java program running inside a Web browser is called an applet. In order to use an applet, a Java- enabled Web browser, such as Netscape version 2.0 or later or Internet Explorer 3.0, is needed.

A Simple Java Program

Here is a very simple example of a Java program taken from the book Core JAVA by Gary Cornell and Cay Horstmann.

public class Welcome

{ public static void main(String[] args)

   { System.out.println("We will not use `Hello world!'"); }

}

This program simply writes the string to the console. Java is case sensitive so any mistakes in capitalization will cause compile problems. The program name must be the same as the name of the class with the word java appended. Thus for this example we would name the program Welcome.java; welcome.java would not work since the class has been named with a capital W. To compile and run a Java program, simply type the following commands from the command line:

javac Welcome.java

java Welcome

The javac program is the Java compiler that takes our program Welcome.java and compiles it into the file Welcome.class. The Java interpreter (java) then interprets what the compiler placed in the class file.

Java allows for the collection of classes into what is called a package. To use a public class that is in a package simply include it with the keyword import at the beginning of the program. For example import corejava.*; will import all the classes in the corejava package, and import corejava. Console will import only the Console class within the package. To put comments in your code so that others can easily read it, use a // for comments that will run only the length of a line and for longer comments the common C comment notation of /* and */ is used.

Before Getting Started

Be sure to set the correct environment variables. Working on nye, the following line should be included into your local.cshrc file so that classes included with the CD from the Core JAVA book may be utilized:

setenv CLASSPATH /usr3/java/bin:.:/usr3/java/CoreJavaBook

[an error occurred while processing this directive]