I. Running Java A. Getting it ------------------------------------------ GETTING JAVA Already on department Linux machines, in /usr/java/j2sdk/ For home, go to http://java.sun.com and get J2SDK 1.4.1_04 What you get: javac - compiler java - interpreter (virtual mach.) jar - archiver javadoc - HTML page creation ... ------------------------------------------ B. Hello World ------------------------------------------ SUMMARY OF COMILATION AND RUNNING HelloWorld.java | | javac HelloWorld.java v HelloWorld.class | | java HelloWorld v (output) ------------------------------------------ C. setting your CLASSPATH Who can explain what the PATH does in Unix? ------------------------------------------ THE CLASSPATH (ON LINUX) On Linux, cygwin $ printenv CLASSPATH .:... $ java HelloWorld What if "." is not in the CLASSPATH? $ export CLASSPATH="" $ java HelloWorld Using multiple directories: $ ls applogic userinterface $ cd applogic $ export \ CLASSPATH="$HOME/classes/cs362/lectures/objects-classes/applogic" $ javac Message.java $ export \ CLASSPATH=".:$HOME/classes/cs362/lectures/objects-classes/applogic" $ javac Message.java $ cd ../userinterface $ javac HelloWorld.java $ export \ CLASSPATH="$HOME/classes/cs362/lectures/objects-classes/applogic" $ javac HelloWorld.java HelloWorld.java:6: cannot resolve symbol ... ------------------------------------------ So can you summarize how the CLASSPATH works so far? D. packages in Java ------------------------------------------ PACKAGES Goals: prevent name conflicts support large scale development For each name N in package P can refer to N by P.N from outside package Packages contain: classes, interfaces, packages Example: userinterface HelloWorld applogic Message ------------------------------------------ ------------------------------------------ EXAMPLE // Add the following line of code // to put this class in package applogic. package applogic; /** This class knows the message to print. */ public class Message { /** the message */ private String msg; /** Initialize this Message object. */ public Message() { msg = "Hello, class!"; } /** Return the message. */ public String get() { return msg; } } ------------------------------------------ What do we have to do to make the code in HelloWorld work with this? Can you summarize how java and javac use CLASSPATH? E. Eclipse ------------------------------------------ ECLIPSE EDITOR Free, IDE for Java Get it from: http://eclipse.org Already installed on Linux: $ eclipse ------------------------------------------