Java Lab 0: Hello World

  1. Navigate to the c:\java folder on your computer and create a folder to store the work you will do in this class. The name of the folder should have no spaces and include part of your name or a nickname, so you will recognize it as yours in future classes.
  2. Go to Start Menu->Programs->Accessories and click on Notepad. This opens up Notepad which is the editor we�ll be using to write your source code for now. Type this code below into Notepad:
    
    public class HelloWorld { 
        public static void main(String[] args) {
            System.out.println("Hello, World!"); 
        } 
    }
    
    
  3. Save the file as HelloWorld.java in your home directory you created in step 1. Navigate to your home directory and make sure that the file ends with .java. If it ends with .java.txt then delete the .txt part
  4. Go to Start Menu->Programs->Accessories and click on Command Prompt or MSDOS Prompt. This is the command prompt where you�ll be running the commands to compile and run your programs. At the prompt, change to your home directory by typing the following command and pressing enter (where yourname stands for the name you gave your folder): cd c:\java\yourname
  5. Compile the source code you wrote in Step 2 by now typing the following command at the prompt and pressing enter: javac HelloWorld.java If running this command prints any errors to the command prompt window, then you either did not copy the code in Step 2 correctly or you did not give the file the right name in Step 3. Make sure each is copied precisely, character by character, with correct capitalization, and then try to recompile. If it compiles successfully, it will print out nothing and simply show the next prompt.
  6. Now run your program by executing the following command at the command prompt: java HelloWorld What do you see?
  7. Now change the HelloWorld code so that it prints out �Goodbye, World!� instead. This should be done by changing only one line of your program. Compile and run your program and see what it prints out.
Hosted by www.Geocities.ws

1