CSC223 2004F, Class 3: Polymorphism (More Or Less), Day 2 Admin: * Common courtesy dictates that you send me an email message whenever you miss a class. * Eboards restarted. Let me know what you think. * Help needed at 11:00 with 152. * Quiz! Overview: * Using Java packages. * The Candy Machine Problem, revisited * Solution one: Java Introspection * Solution two: An important design pattern * Improving solution two: Anonymous inner classes Look, here's some important information about your quizzes! * A few of you had an interesting idea for #1. * Few of you could relate Scheme to Java. * None of you know what the import statement does. What does the import statement is like C's #include statement, which shoves code from the other file into the current file. WRONG! Allows those other classes to be used within your program. close, but WRONG! Import statements ONLY provide programmers with a shorthand. import a.really.long.package.name.Class = "Whenever I say Class, I mean a.really.long.package.name.Class" Avoid import package.* because they are likely to confuse your reader --- /Detour: Bang commands in the shell/ !letters = "redo last command that begins with letters" /Packages in Java/ * Allow overlap of names by giving us a more qualified namespace. * The import statement simplifies the nameing complexity this leads to. * Students early in their programming careers have difficult. * What should I name my package? * "Party line": edu.grinnell.cs223.yourname.project * "Lazy line": project * "CS223 line": cs223.yourname.project * Where do files go? In *nix systems, the directory must match the package name cs223.caseevan.hw3 In cs223/caseevan/hw3 * To run the class that includes the main, you must type the *fully qualified name* of that class. * You also need to tell the java compiler and interpreter where to look for packages. The environment variable CLASSPATH tells it where to look.