meeting -*- outline -*- Bring computer * Running Java Goal is to deal with practical matters, running Java, and Eclipse Tell them to read the course web page about running Java: http://www.cs.iastate.edu/~cs362/running_java.shtml ** 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.2 What you get: javac - compiler java - interpreter (virtual mach.) jar - archiver javadoc - HTML page creation ... ------------------------------------------ ** Hello World Write, compile, and run the simpliest program ------------------------------------------ SUMMARY OF COMILATION AND RUNNING HelloWorld.java | | javac HelloWorld.java v HelloWorld.class | | java HelloWorld v (output) ------------------------------------------ ** setting your CLASSPATH Q: Who can explain what the PATH does in Unix? note diff between : on linux and ; on Windows. CLASSPATH is similar, but used to find Java classes. ------------------------------------------ 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 ... ------------------------------------------ Q: So can you summarize how the CLASSPATH works so far? ** packages in Java change the package, and show what happens ------------------------------------------ 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 ------------------------------------------ Typical implementation is that each package is a directory on a file sys, but can also have packages stored in a database ------------------------------------------ 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; } } ------------------------------------------ This example would have to be in a directory named applogic Q: What do we have to do to make the code in HelloWorld work with this? change the references to applogic or use import. compare to friends in C++ Show how to compile this, and what changes are needed to CLASSPATH Q: Can you summarize how java and javac use CLASSPATH? ** Eclipse ------------------------------------------ ECLIPSE EDITOR Free, IDE for Java Get it from: http://eclipse.org Already installed on Linux: $ eclipse ------------------------------------------ do the same stuff as above, under Eclipse Talk about views, perspectives, and editors Show how to manipulate projects: - open/close - adding libraries, - changing launch configurations