|
CS 111 - Introduction to Computer Science
Eclipse Hello World Tutorial |
This tutorial walks you through the process of creating your first "Hello,
world!" application (http://en.wikipedia.org/wiki/Hello_world_program)
in Java.
- Open Eclipse:
- Start a terminal window by dragging to the bottom of the
screen and selecting “Terminal Emulator”.
- In that terminal window, type “eclipse &”.
- Wait for Eclipse to start up. Do not download/upgrade
anything if asked. If you do not go to the Workbench
automatically, select Workbench (“Go to workbench”).
- If you're not already in the Java perspective, in the main
menu select Window → Open Perspective
→ Java.
- Create a Java Project:
- Before creating a Java class, we need a project to put it in. In
the main menu, select File → New
→ Java Project.
- Enter “hw1” for the project name.
- Under “Project Layout”, you should have selected “Use project folder
as root for sources and class files”. If this is not selected:
- Click the “Configure defaults” link for Project Layout.
- Under “Source and output folder”, select “Project”.
- Click “Apply” and “OK”.
- Make sure you now have selected “Use project folder as root for
sources and class files” under “Project Layout” on the previous
screen.
- Click “Finish”.
- Create a Java Class:
- In the main menu, select File →
New → Class.
- Under Source Folder, enter the name of your project (“hw1”).
- Under Package, enter nothing. Eclipse will warn you that using
the default package is not recommended, but for our purposes, you should
always use the default package.
- Under Name, enter “Hello”. Case matters. Class names should
generally start with a capital letter, along with first letters of
subsequent words (with no spaces in between).
- Under “Which method stubs would you like to create?”, check “public
static void main(String[] args)”.
- Click “Finish”
- Write the program code:
- Within the main method curly brackets, add the following line:
System.out.println("Hello, world!");
- Save your changes (Control-S); the class will automatically
compile.
- Click the green right-arrow Play button to run the program in the
bottom console window.
Congratulations! You have successfully created your first "Hello, world!"
application!