Java Classes
Many new Java programmer seem to encounter difficulty when they first start
using packages. It's actually quite straightforward once you understand the
basics. Let's begin with a discussion of environment variables.
Environment variables
JAVA_HOME
The JAVA_HOME environment variable should point to the
directory in which Java has been installed. Depending on the version
of Java you're using, this variable is used to locate the run-time
environment and standard libraries.
You'll sometimes hear (especially on the comp.lang.java.programmer
newsgroup) that you shouldn't need to set this environment variable.
While that might be true in production environments, it's not the
case when you're developing and testing your code.
Here's the typical HelloWorld application.
public class HelloWorld {
public static void main( String args[] ) {
System.out.println( "Hello world!" );
}
}
|
Assuming that you've successfully installed the JDK (note that the JRE
doesn't include the Java compiler) then your session will look something
like this:
$ javac HelloWorld.java
$ java HelloWorld
Hello world!
$
|
There are a couple of things worth noting here. First of all, the example
assumes that the current directory is included in the CLASSPATH. That's the
essence of "visibility".
Copyright © 2004 by Phil Selby