Run the “Hello, World” Java program

Launch the eclipse.exe application by double-clicking on it. If you don’t see the window with the Welcome tab in the upper left corner, pull down the Help menu and select Welcome. Click on the green checkmark (with pencil with green eraser) to go to Tutorials. Click on Create a Hello World application.

The right panel contains a series of six steps marked with isosceles right triangles. Here are hints to help you follow them. Remember, the name of the project and class, HelloWorld, is one word with no space. The H and W must be uppercase, and the rest lowercase. Email me if you get into trouble: mark.meretzky@nyu.edu

  1. Introduction.
    The first step should already be open. After you read it, click on the triangle to close it.
  2. Open the Java perspective.
    You are already in the Java perspective if the window title bar says Java – Eclipse SDK.
  3. Create a Java project.
    The “New Java Project ” button has a blue folder with a J+. After you press the Finish button, a HelloWorld project should appear in the Package Explorer in the left panel. If the Package Explorer is not visible,
    WindowShow ViewPackage Explorer
    Also, a HelloWorld folder will appear in your workspace folder.
  4. Create your HelloWorld class.
    The “New Java Class” button has a C+ in a green circle. The name of the class and the name of the Source folder should both be HelloWorld.
    Ignore the message that says “The use of the default package is discouraged.” Remember to check the checkbox for
    public static void main(String[] args).

    After you press the Finish button, a HelloWorld.java file should appear in the Java editor (the central panel). The default package and HelloWorld.java file will also be listed in the Package Explorer on the left. The HelloWorld class and its main method will be listed in the Outline window. If the Outline is not visible,
    WindowShow ViewOutline
    Also two files, HelloWorld.java and HelloWorld.class will appear in your HelloWorld folder.

  5. Add a print statement.
    Insert your new statement
    System.out.println("Hello world!");
    
    in the empty line immediately under the // TODO comment. (You can remove the comment.) To indent your statement the same distance as the comment, use the Tab key or pull down the Source menu and select Format.

    If the Java editor is too cramped, maximize it by clicking on the larger icon at the right end of its title bar. To restore it to its original size, click on the icon that looks like two rectangles.

    Anything you do wrong will be underlined with a red zigzag. For example, the S in System must be uppercase, and the L in println must be a lowercase letter L and not the digit 1. (The ln stands for “line”). Don’t be unnerved if it displays the word out in blue italics; it’s only trying to be helpful. The " character is a double quote, not a pair of single quotes. The computer won’t be satisfied until you have typed the semicolon at the end of the statement.

    To save your changes after you have inserted the println statement, pull down the File menu and select Save. If there are error messages, they will appear in the bottom center window; click on the Problems tab. If you don’t see it,
    WindowShow ViewProblems
    Correct them and save again.

    If you want to print the HelloWorld.java file, click on it in the Java editor, pull down the File menu, and select Print….

  6. Run your Java application.
    If you don’t see the Package Explorer in the left panel,
    WindowShow ViewPackage Explorer
  7. Your HelloWorld class in the Package Explorer has an uppercase C in a green circle. If you don’t see it, open the HelloWorld.java icon in the Package Explorer by clicking on its minus sign (on Mac, rightward-pointing triangle). On a Mac you have no right mouse button, so hold down the control key as you click on the HelloWorld in the Package Explorer. If it says “Select resources to save”, just press OK.

    You should have a Console window at the bottom center. If you don’t see it,
    WindowShow ViewConsole
    The output of your Java program (the words “Hello world!”) will appear in the Console.

    You can maximize and restore the Console just as you maximized and restored the Java editor. To print the output, copy and paste the words into a document (e.f., in Notepad) and print the document.

    Before running the program again, you may want to erase the output. Click on the Console icon of a sheet of paper with an X in the lower right corner.