CS 201 Software Development Methods Spring Tutorial #1. Eclipse

Similar documents
SDKs - Eclipse. SENG 403, Tutorial 2

PART 1. Eclipse IDE Tutorial. 1. What is Eclipse? Eclipse Java IDE

Introduction to Computation and Problem Solving

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

At the shell prompt, enter idlde

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Just Enough Eclipse What is Eclipse(TM)? Why is it important? What is this tutorial about?

GETTING STARTED WITH ECLIPSE Caitrin Armstrong

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

MEDIA COMPUTATION DRJAVA. Lecture 11.3 November 7, 2008

1.00 Lecture 2. What s an IDE?

Introduction to IntelliJ

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Using Eclipse Europa - A Tutorial

Getting Started (1.8.7) 9/2/2009

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

Your password is: firstpw

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

Getting Started with Eclipse for Java

For live Java EE training, please see training courses at

David Scuse Department of Computer Science University of Manitoba. Eclipse 3.1

Using Eclipse for Java. Using Eclipse for Java 1 / 1

Adding Existing Source Code in NetBeans CS288, Autumn 2005 Lab 002

1) Log on to the computer using your PU net ID and password.

Prerequisites for Eclipse

What is Eclipse? A free copy can be downloaded at:

Sun ONE Integrated Development Environment

The Road to CCSv4. Status Update

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

Debugging in AVR32 Studio

Lab Android Development Environment

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

ADT: Eclipse development tools for ATL

Module 3: Working with C/C++

RTMS - Software Setup

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Setup and Getting Startedt Customized Java EE Training:

Laboratory 1: Eclipse and Karel the Robot

Javac and Eclipse tutorial

How to make a "hello world" program in Java with Eclipse *

Module Road Map. 7. Version Control with Subversion Introduction Terminology

GETTING STARTED WITH THE ADOBE INDESIGN CS3 PLUG-IN EDITOR

Lab #1: A Quick Introduction to the Eclipse IDE

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

Figure 1. Simplicity Studio

Creating a new CDC policy using the Database Administration Console

COMP1406 Tutorial 1. Objectives: Getting Started:

Laboratory Assignment #3 Eclipse CDT

ECE QNX Real-time Lab

In this lab, you will build and execute a simple message flow. A message flow is like a program but is developed using a visual paradigm.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

NetBeans IDE Java Quick Start Tutorial

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

Getting Started with Eclipse/Java

An Introduction to Eclipse: Quick Guide. Part 1: Getting Started with Eclipse Part 2: Working with Eclipse Useful Online Guides

COMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE. Instructor: Prasun Dewan (FB 150,

QNX Software Development Platform 6.6. Quickstart Guide

Getting Started with Eclipse for Java

Eng. Mohammed S. Abdualal

Do this by creating on the m: drive (Accessed via start menu link Computer [The m: drive has your login id as name]) the subdirectory CI101.

Drools Tools Reference Guide. Version: CR1

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

Simulator. Chapter 4 Tutorial: The SDL

The NetBeans Debugger: A Brief Tutorial

Read Me First! Start Here. Read Me First! Start Here.

CodeWarrior Development Studio for Power Architecture Processors FAQ Guide

Installing Eclipse. by Christopher Batty and David Scuse. Department of Computer Science, University of Manitoba, Winnipeg, Manitoba, Canada

INF 111 / CSE 121. Homework 3: Code Reading

Introduction to Eclipse

Using Karel with Eclipse

Lecture 1 - Introduction (Class Notes)

Slide 1 CS 170 Java Programming 1 Duration: 00:00:49 Advance mode: Auto

WPS Workbench. user guide. "To help guide you through using the WPS user interface (Workbench) to create, edit and run programs"

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

Struts Tools Reference Guide. Version: beta1

Laboratory Assignment #4 Debugging in Eclipse CDT 1

IBM C Rational Functional Tester for Java. Download Full Version :

Instructions PLEASE READ (notice bold and underlined phrases)

Assignment #4 Minesweeper

Intro to MS Visual C++ Debugging

AndeSight. User Manual. Working with AndESLive. Version 1.0

Workbook A dialog box will appear asking for you to select your "workspace". Leave the default as is, which should be /home/crsid/workspace.

Java with Eclipse: Setup & Getting Started

Module 4: Working with MPI

Imperative and Object Oriented Programming. Tutorial 1. Charlie Abela Department of Artificial Intelligence

RVDS 4.0 Introductory Tutorial

Using Eclipse and the

Software and Programming 1

Express Yourself. What is Eclipse?

Lab 3-2: Exploring the Heap

DS-5 ARM. Using Eclipse. Version Copyright ARM. All rights reserved. ARM DUI 0480L (ID100912)

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

Summer Assignment for AP Computer Science. Room 302

JCreator. Starting JCreator

3 Getting Started with Objects

3. Hello World! for IDEA. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Transcription:

CS 201 Software Development Methods Spring 2005 Tutorial #1 Eclipse Written by Matthew Spear and Joseph Calandrino Edited by Christopher Milner and Benjamin Taitelbaum

ECLIPSE 3.0 DEVELOPING A SIMPLE PROGRAM This tutorial is meant to serve as a step-by-step walkthrough of the process of developing projects including creating/opening, building, and executing in the Eclipse 3.0 Integrated Development Environment (IDE). In 2001, IBM donated $40 million dollars toward the creation of an open-source Java development suite called Eclipse for use with large-scale software projects. The design of Eclipse allows users to easily install custom tools known as plug-ins to complement its functionality. Today, a number of plug-ins are available to assist in the software development process. Eclipse includes a debugger, compiler and jar creator. For the purposes of the class we will use Eclipse 3.0 with the J2SDK 1.5. Note: Completing this walkthrough requires Eclipse 3.0 to be installed on the machine on which you will be working. All computers in Stacks in Thornton Hall and in the CS 201 laboratory (Olsson Hall 001) have this software installed. Last Change: January 25, 2005 Page 2

Definitions and Terminology Project Perspective Window Workbench Run Debug Project Explorer Outline Console Problems Tasks A collection of source code, class files and any accompanying items (jars, images, sounds, etc.). A view that allows a set of windows and information about open projects to be displayed. A GUI object that can contain other GUI objects. The Java editor in Eclipse. Making the class files perform their programmed logic. Walking through the code to find errors. Lists the projects that are currently open, and allows perusal of the contents of each project. Lists the methods, static variables, etc. in the currently open class, clicking on one of these sends the workbench to the definition. Displays the output of a program that was Run. Lists the compilation issues in a table form; double-clicking a problem displays the location of the error. Lists tasks that have been added to the source file, i.e. TODO, FIXME, etc. Last Change: January 25, 2005 Page 3

Part 0: Starting Eclipse To open Eclipse from an ITC lab, choose Start >> S.E.A.S. >> Java Apps >> Eclipse >> Eclipse. In Olsson 001, you should just be able to double click the Eclipse icon. When you first open Eclipse you are greeted with the Welcome splash screen; clicking the Go To Workbench button (upper right corner) takes you to the workbench. Last Change: January 25, 2005 Page 4

The first thing you will want to do is switch the workbench over to the Java Perspective. Do this by Window >> Open Perspective >> Java. Another perspective you will use is the Debug perspective. Switch to it by Window >> Open Perspective >> Debug. Not much to see here at this point, so go back to the Java Perspective. Finally, you can modify the Workbench using the Preferences dialog box, accessed via Window >> Preferences. You will not change any settings now, but you could change autocompletion, editor appearance, code formatting, and other settings from this window. You can save preferences by clicking Export. The next time you use Eclipse, you can Import your epf (Eclipse preferences file). This capability is particularly useful in public labs where the previous user may have different tastes than your own Last Change: January 25, 2005 Page 5

Part I: Creating a Hello World Jar 1. Choose File >> New >> Project, and choose Java Project. Click Next. 2. In New Java Project dialog box enter HelloWorld for the Project name. Select Create project at external location and use a path in your home directory. If you do not do this, you may lose your work! Select Create separate source and output folders (this often makes code management easier). 3. Click Finish (Next would allow you to customize the output folders, project dependencies, libraries, and build/export order, but you do not need to do that). 4. Now you have successfully created our first Java Project and need to add classes. To do this, right-click on the project and choose New >> Class. Last Change: January 25, 2005 Page 6

5. This brings up the New Java Class dialog box. Enter cs201.lab1 as the Package and HelloWorld as the Name. Check public static void main(string[] args). Note that we do not use the default package and instead create a custom package path. This is highly recommended as it helps keep the code more logically separated. 6. Clicking Finish creates the HelloWorld.java file with a main method. 7. Eclipse has a number of useful features to assist developers; one is auto-completion of code. For example, if you type the name of an Eclipse-recognized Java class followed by a., Eclipse will open a popup-menu that lists the methods/variables associated with the class. The list is narrowed as you type more. Once a single item is highlighted, Eclipse shows the JavaDoc for that method/variable. Inside the public static void main method, type System.. A list of all of java.lang.system s static methods/classes/variables appears. On typing o, out is the only possible option. Hit enter, and Eclipse writes the rest of out for you. Last Change: January 25, 2005 Page 7

8. Complete the line of code so it reads System.out.println( Hello Eclipse! ); and select File >> Save. 9. It is now decided that the class name HelloWorld is not as appropriate as HelloEclipse. We ll use this opportunity to refactor our code. To change the name, right-click on the class name in the Package Explorer window and choose Refactor >> Rename. 10. This brings up the Rename Compilation Unit dialog box. Change the name to HelloEclipse and be sure that Update references is checked. This option ensures that all references to your class name are corrected for you so you don t need to tediously update your code. Click OK >> Continue. (don t worry about the warning that comes up). Last Change: January 25, 2005 Page 8

11. Now you are ready to run your program. Highlight HelloEclipse.java in the Package Explorer. On the menu bar, choose Run >> Run As >> Java Application. In the console window, you now see the output of your application. (If we had not included a main class Eclipse would popup a dialog box telling us that the active class contains no main type or class depending on the method of execution). If the Console does not automatically come up, choose Console from the file bar of the bottom window. 12. Now that we have a complete class, we can export it as a jar for easy use. To do this, we will use Eclipse s built in jar export utility. Choose File >> Export. In the Export dialog box choose JAR File and click Next. Now you should see the JAR Export dialog box. If the checkbox next to HelloWorld is gray simply uncheck it and then recheck it. In the window on the right, check.classpath,.project, and Export java source files and resources (the first two are in the upper right window). Enter HelloEclipse.jar as the JAR file and click Next. Last Change: January 25, 2005 Page 9

13. On the next dialog box, accept the defaults and click Next. Finally on the third dialog box choose the cs201.lab1.helloeclipse class as the main class and click Finish. This creates an executable jar file that will simply print out Hello Eclipse! when run. Last Change: January 25, 2005 Page 10

Part II: Debugging So far we have not discussed issues that occur in developing code, namely the two types of problems: syntax and programmatic. Eclipse helps immensely with both of these issues. For syntax problems, Eclipse uses a combination of underlining in red (ala Microsoft Word) and putting icons on both sides of the text editor indicating the positions of the errors (the right side shows the relative position of an error in the active document). Hovering over either side gives a description of the error, and clicking a red box on the right side brings the error to screen and highlights the offending code. For programmatic problems, Eclipse has a Problems window that lists all compilation errors as well as a Debug Perspective that allows one to step through code, insert breakpoints, and watch local variables using the tostring method. Create Problematic class: 1. If it is not already open, reopen your HelloEclipse.java file. 2. Now add a method getoutput() that is static and returns a String as shown and change your main() method to use it. After making these changes, save your file. 3. As you can see, there are two errors, and Eclipse points them out in numerous ways. To correct the first error, left click on the light bulb with the X over it to the left of the BigInteger line. After a moment or so, a window should appear. Select Import BigInteger (java.math). When you save your file, these red lines should go away. 4. Repeat this step for the other error, selecting Change to output. (remember to save again) 5. Now Eclipse shows no errors, so we can run the main method shown above (Run >> Run As >> Java Application). The output is Hello Eclipse, from CS202 But you re in CS201 now, not 202. The error may be obvious to you, but let s step through the code. Last Change: January 25, 2005 Page 11

6. Double-click on the grey bar to the left of the line starting with BigInteger to add a breakpoint. When debugging, Eclipse will run to here and await further instructions. 7. Choose Run >> Debug As >> Java Application. 8. You will be asked to switch to the Debug Perspective. Select Yes. The screen will now look very different. 9. Looking at the Variables window, we see a list of all local, initialized variables (num). Clicking on num gives the tostring of it in the Details (bottom) section of the window. Last Change: January 25, 2005 Page 12

10. Pressing F6 allows you to step line-by-line over your code and any method calls (F5 allows you to walk through each method, but that will not be necessary here). After hitting F6 once, classnum comes up in the variables window. Select it, and you will see that the value is 202, so the error must have occurred on instantiation of classnum. 11. Try removing the + 1 in BigInteger.valueOf(num + 1) and click Save. We return to the original debug line. Repeat step 10, and the value of classnum should now be 201. 12. Terminate the debug session by selecting Run >> Terminate. 13. Return to the Java Perspective and run your main method. The output should now be correct. We have gone over the basics of debugging, but there are two more functions that will be very useful in debugging applications: Run >> Resume (F8) and Run >> Run to Line. The former allows you to let the application run until it hits another breakpoint (at which point you can examine it again). The latter allows you to run to the line that the cursor is on without inserting breakpoints. Conclusion Congratulations! You now have experience with: Starting Eclipse Creating projects and classes Refactoring class names Running classes Creating jar files Debugging both syntax and logic errors Last Change: January 25, 2005 Page 13