You are on page 1of 4

Univ. Wisc.

-River Falls

CSIS 235

OOD

Spring 2012

Getting Started with Java Programming using Eclipse


The first step in writing Java programs is to make sure you have a Java compiler a Java Software Development Kit (also called SDK or JDK) on the computer you are using. We will use the standard edition of the Java SDK. We will use either the 6th version of the JDK (called J2SE 6 or Java 1.6) or the newly released 7th version. While we could do everything for this course with just the Java SDK, a nice Integrated Development Environment (IDE) make the process of compiling and running programs easier. There are many good Java IDEs and in this course we will use the Eclipse 3.7 (Indigo) Java development system for the Linux, MacOS X or Microsoft Windows operating systems. You can use any Java compiler you wish but your programs should compile and run under Eclipse using JDK 1.6 (or higher) to get credit for your work. In the Lab (Rm 218) in South Hall and some of the ITS Labs in the Library, click on the Windows Start button, which brings up a menu; click on All Programs and in the menu it displays, click on the item Course Applications which will pop up a menu in which you should choose Computer Science & Information Systems and this will give you another menu in which you should choose Eclipse - Java. On your computer at home or in your dorm room, you will have to download and install the Eclipse 3.7 program for free from the Eclipse web site: http://www.eclipse.org/downloads/index.php For this course, all you need is the Eclipse IDE for Java Developers. To install Eclipse all you have to do is unzip the file you downloaded, and double-click on the file called Eclipse. If you already have a JDK, Eclipse will start up it needs Java to run. If you dont have the Java SDK, download version 1.7 JDK 7, also called Java 7 from: http://www.oracle.com/technetwork/java/javase/downloads/index.html On Windows systems, the 32-bit version of Java JDK SE 6 Update 26 is probably best. To install, double-click the file you downloaded. If you have a Mac OS X system, you may know that they used to come with a JRE but newer versions like Lion require you to download a JRE yourself to be able to run Java applications and applets. Downloading and installing a JDK is sufficient because the JDK includes a JRE. If everything works, when Eclipse starts, you will see a splash screen temporarily followed by a window labeled Workspace Launcher at the top. Eclipse uses one or more of your workspaces or folders where you can store programs. So choose a convenient location, such as your desktop or a USB thumb drive if you have one. Make a note of where the workspace is do make sure it is in your folder (and not someone else's) and then click OK. Page 1 of 4 Revised: 1/24/12

Univ. Wisc.-River Falls

CSIS 235

OOD

Spring 2012

You will most likely see a welcome window that will show up only the first time you use Eclipse. At this point, it would be a good idea to take a look at the overview of Eclipse

or the built-in tutorial or skip these by clicking on the curved arrow in the upper right corner of the screen.

Now you are ready to create your own Java program. Creating a Java Application It is a good idea to set up separate projects for each program called a Java application that you write in this course. When you create a new Java application in a new folder, you will end up with a set of files that are need to run your program. 1. Create the project file, and the necessary subfolders: Click on File and New and then Project . . .. 2. In the New Project window, click on the + sign next to Java and then click on Java Project and click on Next. Type in a name like First for your project. Use the default settings at the next step and click on Finish. This should result in a new project (the example to the right shows a project named CS161).

Page 2 of 4

Revised: 1/24/12

Univ. Wisc.-River Falls CSIS 235 3. Next, set up a package name for your Java program. To do this, right-click on the source folder and choose New and then Package. Enter the name first package names start with a lower-case letter. This step is optional because Eclipse sets you up to have a default unnamed package but it is always good idea to have named packages for your code. Name the package first and click Finish.

OOD

Spring 2012

4. Next, set up a new class in a .java file by rightclicking on the src source folder and choosing New and then Class.

5. You should see the New Java Class window and in it enter first for Package and a name like MyFirstClass (without spaces!) for the class name. Make sure the public
static void main (String[] args) box is checked and click on

Finish. At this point you will be able to edit your MyFirstClass Java class. 6. By default, Eclipse automatically compiles your program as you type it in and so there is no Compile step in Eclipse. 7. If everything went well, you should not have seen any error messages. Now click on Run and then on Run as and Java Application. If everything worked, you should see no error messages.

8. Now change the class code so that it looks like the program shown below to the right or use one of the classes in the course text book and run (step 6) the new program. Page 3 of 4 Revised: 1/24/12

Univ. Wisc.-River Falls

CSIS 235

OOD

Spring 2012

9. Save the file by clicking on the Save icon towards the top of the Eclipse window. 10. Click on the Run button a green triangle towards the top of the Eclipse window. If you see a window asking what kind of program you want your Java program to Run As, choose Java Application.

Make sure you see that something does get printed.

Congratulations! You now have a working Java program.

Page 4 of 4

Revised: 1/24/12

You might also like