You might find the
Basic Eclipse Tutorial
screencast helpful.
Eclipse is an Integrated Development Environment
(IDE). An IDE is a program that provides the ability to edit, compile,
and run source code.
Eclipse
is one of the most popular IDEs for the Java programming language.
It is free and developed in Java. Other popular IDEs include
NetBeans
and
IntelliJ
.
Installing Eclipse
-
Visit
http://www.eclipse.org/downloads/
and select
Eclipse IDE for Java Developers
.
-
Download and install the software.
Eclipse on the Lab Computers
Eclipse is available on both the windows and linux partitions in the CS labs.
Getting Started
-
Launch eclipse.
-
You will first be prompted to select a workspace. Click
Browse
, and select the directory where you would like to store your work for CS 112. It is recommend you use a directory such as
coursework/cs112
. Eclipse will automatically create folders for each project (e.g., program) you create.
-
Select
OK
.
-
You will see a screen with several buttons. Select the arrow
which will take you to the
workbench
.
-
The
Project Explorer
box will list all of your projects. The large editor box on the upper
right will display your code. The bottom right contains several tabbed
panes to display error messages and also the output of your programs.
Creating a Project
-
You will need to create a new project for each new program you write.
-
Select
File->New->Project
.
-
Click the arrow next to the
Java
folder, select
Java Project
and click
Next
.
-
Choose a name for your project. It is recommended that you use a name such as "Lab1" or "ConnectFour".
-
Click
Finish
.
-
Select
Yes
it if asks you to open the
Java perspective
.
-
You should now see a folder in the
Package Explorer
pane with the name you choose for your project.
-
If you navigate to the project folder from the command line (e.g.,
cd coursework/cs112/Lab1
) you will see two subfolders:
src
and
bin
.
src
is where all of your .java files will be stored.
bin
is where all of the .class files created by the compiler will be stored.
Creating New Classes
-
If you click the arrow next to the folder in the
Package Explorer
you will see a
src
folder.
-
Right-click on the src folder and select
New->Class
.
-
In the
Name
field, type the name of the class (e.g., Player).
-
If you wish to use packages, type the name of the package in the
Package
field.
-
If you wish to create a main method in the new class, select the box next to "public static void main(String[] args)".
-
Click
Finish
.
A new class will appear under the src folder and the class will open in
the editor box. The basic framework for the class will be in place.
Editing and Compiling
-
Type your code in the editor window.
-
As
you type, Eclipse will automatically compile your code for you. Errors
are denoted with a red squiggly line and a red X to the left of the
line on which the error occurs. Clicking the X reveals suggestions for
correcting the error. You can also select the
Problems
tab on the bottom right and see more information about the errors in the code.
Running
-
To run your program, you can do one of the following:
-
Right-click on the project folder and select
Run As->Java Application
.
-
Select
Run
from the menu bar.
-
Output will be displayed in the
Console
tab at the bottom of the screen. If the Console tab does not appear, select
Window->Show View->Console
.
|
|