Author: Loh Jianxiong Christopher Contributions: Chua Jie Sheng, Li Mengran, Peh Shao Hong, Oo Theong Siang, Tong Chun Kit, Tania Chattopadhyay.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 1 Creating an Application: The AppBuilder for Java IDE.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Chapter 2 Creating a Research Paper with Citations and References
Using XCode © 2013 Surajit A Bose De Anza College.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
Java Integrated Development Environments: ECLIPSE Part1 Installation.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Introduction to OBIEE: Learning to Access, Navigate, and Find Data in the SWIFT Data Warehouse Lesson 5: Navigation in OBIEE – Touring the Catalog Page.
What is so good about Archie and RevMan 5
Eclipse IDE. 2 IDE Overview An IDE is an Interactive Development Environment Different IDEs meet different needs BlueJ and DrJava are designed as teaching.
03 Using Eclipse. 2 IDE Overview An IDE is an Interactive Development Environment Different IDEs meet different needs BlueJ and DrJava are designed as.
Chapter 4 Code Editor Goals and Objectives Program more efficiently? How can you speed up your development process? Do you want to learn useful shortcuts.
XP New Perspectives on Introducing Microsoft Office XP Tutorial 1 1 Introducing Microsoft Office XP Tutorial 1.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Using Eclipse. What is Eclipse? The Eclipse Platform is an open source IDE (Integrated Development Environment), created by IBM for developing Java programs.
Chapter 1a© copyright Janson Industries RAD ▮ Explain Eclipse, RAD, and their relationship ▮ Basic RAD concepts ▮ How to install RAD ▮ How to import.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Author: Loh Jianxiong Christopher Editors: Chua Jie Sheng, Li Mengran, Peh Shao Hong, Oo Theong Siang.
1 Development Environments AUBG, COS dept Lecture Title: Dev Env: Eclipse (Extract from Syllabus) Reference:
XP New Perspectives on Microsoft Access 2002 Tutorial 21 Microsoft Access Tutorial 2 – Creating And Maintaining A Database.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
CPSC1301 Computer Science 1 Overview of Dr. Java.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
Debugging Dwight Deugo Nesa Matic
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
Active-HDL Interfaces Debugging C Code Course 10.
(for Visual C++) Created by Daniel Lee, Li Mengran (past tutors) Contributions: Loke Yan Hao (current tutor)
Unit 1: Java and Eclipse The Eclipse Development Environment.
9/2/ CS171 -Math & Computer Science Department at Emory University.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Using This PowerPoint This PowerPoint presentation assumes your Computer Science teacher has provided you with the InstallingJava folder, which contains.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Eclipse Project. Installing Visit to download a copy for your home computerhttp:// –Get Release version 3.0 (or.
Microsoft Word 2010 Chapter 2 Creating a Research Paper with Citations and References.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Netbeans QuickStart. Creating a project File->New Project –For now you want General->Java Application –Then fill in the project details.
Editing and Debugging Mumps with VistA and the Eclipse IDE Joel L. Ivey, Ph.D. Dept. of Veteran Affairs OI&T, Veterans Health IT Infrastructure & Security.
1 Using an Integrated Development Environment. Integrated Development Environments An Integrated Development Environment, or IDE, permits you to edit,
Author: Loh Jianxiong Christopher Contributions: Chua Jie Sheng, Li Mengran, Peh Shao Hong, Oo Theong Siang, Tong Chun Kit, Tania Chattopadhyay.
Debugging with Eclipse
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Eclipse.
The eclipse IDE IDE = “Integrated Development Environment”
ATS Application Programming: Java Programming
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Debugging Dwight Deugo
Eclipse Navigation & Usage.
Testing and Debugging.
Computer Programming I
Using Visual Studio with C#
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Debugging with Eclipse
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Using Eclipse.
Debugging Dwight Deugo
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Debugging with Eclipse
Workshop for Programming And Systems Management Teachers
Presentation transcript:

Author: Loh Jianxiong Christopher Contributions: Chua Jie Sheng, Li Mengran, Peh Shao Hong, Oo Theong Siang, Tong Chun Kit, Tania Chattopadhyay

Introduction to Eclipse A powerful IDE (Integrated Development Environment) Provides many features and tools to aid in software development Download the latest version of Eclipse from: “Eclipse IDE for Java Developers” should be sufficient for this module This tutorial has two parts: Part A: Setting up a project Part B: Debugging 2

Starting Eclipse When you first start Eclipse, you will be asked to set a workspace folder, which is the location where all your project related files will be stored 4

Creating HelloWorld Project 5 On the top menu bar, click: File  New  Project. [For Mac Users] If New menu is empty, right click on a blank area of the Package Explorer. (See Next Slide)

Creating HelloWorld Project (Mac Users) 6 Right-click on the blank area of Package Explorer, click: New  Project.

Hello World! 7 Select “Java Project” from the wizard, and click “Next>”

HelloWorld 8 Type in our project name “HelloWorld” and click “Finish”.

The Workbench 9 The package explorer pane displays the various files (some source, some bytecode) included in your project in the form of a tree. Click the triangular buttons to the left of the individual folders to expand or collapse them. (If a folder is empty, the expand/collapse button is not displayed) This is the editor area. Since no file is opened, it’s blank. The Outline pane displays an outline of a structured file that is currently open in the editor area, and lists structural elements. This is where various output from the IDE are displayed. We are currently at the Problems pane. That should bring you to the ‘Workbench’. It has following main components. Task list is the place where you can assign tasks within the project.

Adding a new class 10 Right click on the folder “src” and select New -> Class Now, let us add a new class to our project.

Name the new class 11 In the Name field, type in “HelloWorld” Then press “Finish”.

Start Editing 12 To star editing, double click “HelloWorld.java” in Package Explorer to open it up in the editor pane.

Eclipse Code-Assist Now write the main function as shown and type in: System.out.println(“Hello World!”); 13 When typing code, the code-assist window pops up to help the user. This is called the ‘code assist’ feature. Double-clicking a selection (or press Enter at it) will have Eclipse fill in the rest of the code automatically.

Outline Pane 14 Notice that the Outline pane gives a structural view of “HelloWorld.java”, that it contains the class “HelloWorld”, in which there is a function “main”.

Save File A ‘*’ preceding the class name indicates that the class is not saved. 15 To save HelloWorld.java, select File -> Save or press Ctrl+S.

Running HelloWorld To run our project, select Run -> Run As -> Java Application Note: In Eclipse, there is no need to compile before running (compilation is done automatically as you type). 16

Note: If the file is not saved If you run an unsaved file, the ‘Save and Launch’ window appears. Select the classes you want to save and click ‘Ok’. 17

Output Program output is displayed below the editor window under the ‘Console’ tab 18

To View the Console If the console is not visible, click: Window  Show View  Console. 19

Error Detection and Correction in the left margin means there is an error on that line. Red squiggly lines ( ) indicates where the error is. Moving the mouse over either will bring up a description of the error. For example, had we forgotten to type the semicolon (;), we’d see this error below. 20

Error Detection and Correction Sometimes Eclipse can attempt to correct errors. This is available when a light bulb icon ( ) is displayed on the left margin. Click the light bulb icon to open the suggestion box. We can pick a suggestion listed and Eclipse will do the correction accordingly. 21

Auto Formatting Select Source  Format or press Ctrl+Shift+F. Eclipse will auto format your code according to Java conventions. 22

Eclipse Debugger Eclipse contains a powerful debugger that enables us to easily find and fix problems. It lets us suspend a program during execution, in order to allow the user to step through the code line by line. We will demonstrate the basic functionality of the debugger first and then debug a buggy program. 24

Create a new class called Search. To demonstrate the functions of the Debugger, we will be using this piece of code: public class Search { public static void main(String[] args) { int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; boolean result = searchArray(array, array.length, 15); System.out.println(result); } public static boolean searchArray(int[] a, int length, int x) { boolean isFound = false; for (int index = 0; index < length; index++) { if (a[index] == x) { isFound = true; } return isFound; } 25

Breakpoints Before we can begin debugging, we need to set a breakpoint. Whenever the debugger encounters a breakpoint, the program will be suspended to allow the user to start debugging. To set a breakpoint, double click on the left margin in the editor window. To remove a breakpoint, double click on it again. If no breakpoint is set, the debugger will automatically suspend only if it encounters an exception during runtime. 26 Here a breakpoint has been set next to the main method. When we start the debugger, the program will suspend when it reaches this point in the code.

Running The Debugger To run the Debugger, select Run -> Debug As -> Java Application This brings Eclipse to the Debug Perspective 27

If the ‘Confirm Perspective Switch’ window appears, click ‘Yes’. 28

Perspectives Now the IDE is in debug ‘perspective’. A perspective is a set of views and windows. It provides the user with the necessary views and windows for a certain task. The default perspective that we have seen so far is the ‘Java’ perspective, and is used for coding. When Eclipse debugger is run, the workbench automatically switches to the ‘Debug’ perspective. 29 Notice how this changed from ‘Java’ to ‘Debug’

Debug Perspective 30 Program stack frame Variables associated with current stack Editor window. The next line to be executed is highlighted These are the main components of the debug perspective.

Stepping Through Code 31 These 3 buttons, “Step Into”, “Step Over” and “Step Return”, allows the user to Navigate through the code Step Into (F5) : Moves into the method or constructor at the current line Step Over (F6): Executes current line and suspend at the next line Step Return (F7): Executes until the current function returns and pauses immediately

Step Over 32 Using Step Over, the debugger will go through the code one line at a time

Step Over 33 Using Step Over, the debugger will go through the code one line at a time

Step Over 34 Using Step Over, the debugger will go through the code one line at a time

Step Into 35 If there is a method or constructor in the current line, Step Into can be used to move into the method

Step Into 36 If there is a method or constructor in the current line, Step Into can be used to move into the method

Step Return 37 If we are in the middle of a method execution, Step Return will execute until the end of current method and returns to the next line of the calling method.

Step Return 38 If we are in the middle of a method execution, Step Return will execute until the end of current method and returns to the next line of the calling method.

Stepping Through Code 39 The program stack frame can help us understand and find out where we are in the current program execution. As calls to methods are made, they are added on top of the ‘stack’. As methods are exited, they are removed from the ‘stack’ From the above example, we can see that we are currently executing the searchArray method, and that it was called by the main method

Stepping Through Code 40 As we step through the code, the variables window automatically updates the values of each variable. Highlighted rows show the variables which changed. We can select different stack frames here to inspect

Expressions The variables window automatically keeps track of variables in the current scope of execution. Eclipse can also keep track of expressions, for example we can add a[index], or a[index]==x to the expressions window to examine its value at any time during execution 41 To add an expression to the expression window, highlight it in the editor window of the Debug Perspective, right click and select Watch.

Expressions 42 Expressions may also be added manually, by clicking “Add new expression”

Conditional Breakpoints Conditional breakpoints may be used to give the user more flexibility when debugging To set conditions on a breakpoint, select the “Breakpoints” tab, right click on a breakpoint, and select “Breakpoint Properties…” 43

Conditional Breakpoints 44 Hit count: This option will only suspend the program after the breakpoint has been hit a specified number of times. This is useful when large loops are involved. Conditional: This option will only suspend the program if the specified condition is true, or if the value of the condition changes.

Self-test Assignment: Buggy Sort Now time to get our hands dirty. Create a new Java project. Add a new class called “BuggySort” Copy the contents of BuggySort class in the next slide into the “BuggySort” class your created. It is supposed to print an array, sort it then print the sorted array. Now run the program. 45

46 public class BuggySort { public static void printArray(int[] arr, int startIndex, int endIndex) { int i; for (i = startIndex; i <= endIndex; i++) { System.out.print(arr[i] + " "); } System.out.println(); } public static void bubbleSort(int[] arr, int startIndex, int endIndex) { int i, j, temp; for (i = endIndex; i > startIndex; i--) { for (j = startIndex; j < i; i++) { if (arr[j] > arr[j + 1]) { temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } public static void main(String args[]) { int data[] = { 45, 2, 33, 11, 5, 9, 7, 21, 10, 67, 99, 123, 42, 81, 100, 54 }; System.out.println("our numbers:"); printArray(data, 0, 15); System.out.println(); bubbleSort(data, 0, 15); System.out.println("after sorting:"); printArray(data, 0, 15); System.out.println(); }

Expected output and Actual output 47 Expected output that we’d like to see Actual output: The program actually hangs after printing the initial array Now press the red rectangular button to stop execution

Start Debugging 48 Since the initial array is printed with no problem. We suspect that it’s the sorting function that enters an infinite loop, causing the program to hang. Set a breakpoint at the start of the outer loop, and start debugging by selecting Run -> Debug As -> Java application

Step through the inner loop once 49 Now the program pauses at the starting point of the outer loop. We want to check the loop indices as the loops step through iterations. So, step through the inner loop once and pause at the start of the inner loop.

Check loop indices 50 Current loop indices i and j have values of 15 and 0 respectively, which are correct. As we step over the wrapping up of the loop, we notice the value of i has changed from 15 to 16, as highlighted by the IDE with the yellow color. This is wrong, we were expecting j to increment.

Locating and correcting the error 51 As we examine the code more closely, we find that what should have been “j++” was wrongly typed as “i++”. Correct it, remove the breakpoint and run again, we should see the program behave correctly.