Notes on HelloWorld.java P. Conrad 01/02/2006 (1) The file must be named the same as the class. (2) Execution starts in the main. (3) To compile use: javac HelloWorld.java This produces HelloWorld.class (4) To run, use java HelloWorld Common mistakes: ============== (1) Having a class named HelloWorld but calling the file hello.java The class name and the filename must match. (2) Trying to compile with javac HelloWorld (3) Trying to run with one of the following java HelloWorld.java java HelloWorld.class If javac or java produce "command not found" ============================================ You need to add the Java Development Kit (JDK) to your path. For information on how to do that: * for strauss.udel.edu, check the directory topics/java/compilingOnStrauss Basic Java Concepts: Source vs. object, bytecodes, JVM, public static void ========================================================================== (This is stuff you should already know from CISC370; I provide it as a reminder in case CISC370 was "a while ago", and you need some prompting to get back in the Java game.) The HelloWorld.java file is the source file The HelloWorld.class file is the result of compling into bytecodes Bytecodes are like "machine independent instructions" Bytecodes are interpreted (executed) by the Java Virtual Machine (JVM) when you type "java classname". The three keywords in front of main have these meanings: public the function must be public, or can't access it outside the class static the function isn't tied to a specific instance of the class void the function doesn't return anything to the caller