|
Java on TuringIf you have an existing Turing account, then you are already set up to use Java. The Java directory is /usr/local/java/bin, but that directory is already included by default in your path (this is part of the lineset path= ('usr/local/bin/localpath') ). To create a java file, use your favorite editor (vi, emacs, whatever) and enter your java code. Once you have written your program, you compile java applications with the command javac filename.java. Remember that your class name must be the same as your filename. Once your program compiles, run the application with the command java classname. If you are looking for the Java API documentation on Turing, follow the links below: Java 1.4 Java 1.3 Java 1.2 Here's an example, going step-by-step through the process:
There are two types of java programs: applications and applets. What we've seen above is an example of an application. Like a C++ or Pascal program, the code we've written is executed by the operating system and interacts with us through our shell. In the above case, our program's output was displayed on the command line. Java programs can also be compiled and run on the world wide web, which users can access via. java capable web browsers such as Netscape, Internet Explorer, or Safari. The marquee that is scrolling above is an example of an applet. To see how an applet looks, use the appletviewer program. Supply the appletviewer program the name of the applet you wish to view. For example, if I wanted to see how the marquee would look, I would type at the command line appletviewer Marquee.html, where the file Marquee.html incorporates the Marquee.class file in it via. the applet tag. To see more on how to make web pages that incorporate java, and to see examples of java applications and applets, go to Keller's home page or his directory at /home/keller/public_html, and in particular, check out the following files:
All available versions of Java on Turing are stored in the /usr/local directory.(To see a list try ls -d /usr/local/java*) By default, your account is set to Java 1.4. You can find which version of Java you ar using by typing java -version at the console. If you need to complile or run a program with a different version of Java, create an alias in your zsh file (or .cshrc if your account was created before September 1, 2005):
Replace java_version_dir with the directory for the Java version that you wish to use. You can then compile and run programs using this version of Java with the commands: To change your default version of Java, add the line: After the line: set path= ('usr/local/bin/localpath') in the zsh file (or .cshrc if your account was created before September 1, 2005). If you are having serious problems in getting your java code to compile, make sure you have the same file name as your class name, make sure you are in the right directory, and make sure you're not trying to run an applet from the command line. Don't forget: the consultants are here to help, and you can always ask them if you get stuck! Copyright (c) HMC Computer Science Department.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1
or any later version published by the Free Software Foundation;
with the no Invariant Sections, with no
Front-Cover Texts, and with no Back-Cover Texts.
A copy of the license is included in the section entitled ``GNU Free Documentation License.''
HMC Computer Science Department Contact Information |