Introduction to Java and Eclipse



Similar documents
GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

For Introduction to Java Programming, 5E By Y. Daniel Liang

- User input includes typing on the keyboard, clicking of a mouse, tapping or swiping a touch screen device, etc.

VHDL Test Bench Tutorial

How to test and debug an ASP.NET application

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Slave Computer 1 Slave Computer 2

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

Code::Blocks Student Manual

Java Troubleshooting and Performance

Monitoring, Tracing, Debugging (Under Construction)

Before you can use the Duke Ambient environment to start working on your projects or

SQL Injection Attack Lab Using Collabtive

10 STEPS TO YOUR FIRST QNX PROGRAM. QUICKSTART GUIDE Second Edition

LAB 6: Code Generation with Visual Paradigm for UML and JDBC Integration

Introduction to Eclipse

3. Mathematical Induction

Q N X S O F T W A R E D E V E L O P M E N T P L A T F O R M v Steps to Developing a QNX Program Quickstart Guide

Python Documentation & Startup

WebSphere Business Monitor

Integration for X-Tools and X32

CATIA Tubing and Piping TABLE OF CONTENTS

Analysis of Micromouse Maze Solving Algorithms

REMOTE DEVELOPMENT OPTION

Creating a table of contents quickly in Word

Installation and User Guide Zend Browser Toolbar

TeamViewer & DynGate Manual V 2.0

How to access Answering Islam if your ISP blocks it

Application Note C++ Debugging

Rako Lighting Driver. For use with: Driver software written and provided by:

Slides prepared by : Farzana Rahman TESTING WITH JUNIT IN ECLIPSE

Setting up a Scheduled task to upload pupil records to ParentPay

Developing In Eclipse, with ADT

Debugging with TotalView

Approach of Unit testing with the help of JUnit

<Insert Picture Here> What's New in NetBeans IDE 7.2

Back-up Server DOC-OEMSPP-S/2014-BUS-EN-10/12/13

GPU Tools Sandra Wienke

How To Monitor Your Server In Rumpus (Femalese) On A Pc Or Mac Or Macbook Or Ipa (For Pc) On Pc Or Ipad (For Mac) On Your Pc Or Pc Or Pf (For

Setting Up Database Security with Access 97

LAB THREE STATIC ROUTING

Lecture 11: Tail Recursion; Continuations

Getting Started with Amazon EC2 Management in Eclipse

CooCox CoIDE UserGuide Version: page 1. Free ARM Cortex M3 and Cortex M0 IDE: CooCox CoIDE UserGuide

Eclipse installation, configuration and operation

Expert Reference Series of White Papers. The Basics of Configuring and Using Cisco Network Address Translation

Learn how to create web enabled (browser) forms in InfoPath 2013 and publish them in SharePoint InfoPath 2013 Web Enabled (Browser) forms

Karolinska Institutet, Stockholm, Sweden INSTRUCTIONS HOW TO USE THE THESIS TEMPLATE IN WORD 2010/2013 FOR WINDOWS

Creating 2D Isometric Drawings

Retrieving and Installing MaintainJ plug-ins (drop-ins) and graphics library

MAIL MERGE TUTORIAL. (For Microsoft Word on PC)

Editors Comparison (NetBeans IDE, Eclipse, IntelliJ IDEA)

COMMONWEALTH OF PA OFFICE OF ADMINISTRATION. Human Resource Development Division. SAP LSO-AE Desk Guide 15 T H J A N U A R Y,

File by OCR Manual. Updated December 9, 2008

Adobe ColdFusion Builder

Using Git for Project Management with µvision

A QUICK OVERVIEW OF THE OMNeT++ IDE

Microsoft Word 2011: Create a Table of Contents

Debugging Java Applications

The Matrex Client/Server Specification 1.1

Creating tables of contents and figures in Word 2013

RTOS Debugger for ecos

Figure 1: Graphical example of a mergesort 1.

Training Simulator and Demo Software

Introduction to Programming System Design. CSCI 455x (4 Units)

Exploring Web Testing Tools For Use In A Classroom

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

Java Application Developer Certificate Program Competencies

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

TestManager Administration Guide

The New ABAP Debugger - An Introduction. Boris Gebhardt Christoph Stoeck SAP AG

Release Notes LS Retail Data Director August 2011

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

The ADT Binary Search Tree

HP WebInspect Tutorial

Development_Setting. Step I: Create an Android Project

Apache Configuration

TabletWorks Help Index 1

Department of Veterans Affairs. Open Source Electronic Health Record Services

Android Studio Application Development

Software Construction

Managing Your Class. Managing Users

Debugging Multi-threaded Applications in Windows

This presentation introduces you to the new call home feature in IBM PureApplication System V2.0.

Installing and using XAMPP with NetBeans PHP

Using the Query Analyzer

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Integrated Error-Detection Techniques: Find More Bugs in Java Applications

Week 2 Practical Objects and Turtles

Gadget: A Tool for Extracting the Dynamic Structure of Java Programs

Nios II IDE Help System

Content Author's Reference and Cookbook

TIPS & TRICKS JOHN STEVENSON

Step 2: Headings and Subheadings

AliOffice 2.0 Installation Guide

Transcription:

Algorithms and Data-Structures Exercise Week 0

Outline 1 Introduction Motivation The Example 2 Setting things up Setting command line parameters in Eclipse 3 Debugging Understanding stack traces Breakpoints 4 Final Remarks

Motivation This is supposed to be a reiteration - of course, you already know Java These are useful techniques - you should know them, as they apply to software development in general These are just suggestions - you are free to do it your own way, the result counts

The Example The Traveling-Salesman-Problem Given a set of cities and the distances between them, find the shortest route that visits each city exactly once. Solution This problem is NP-complete - but since it is just an example we use brute force anyway We need to read in a file that gives us the cities and their distances Also, we want to fix a starting city Both, the file and the starting city should be command-line arguments The result is a path - an ordered list of cities we visit

Setting command line parameters in Eclipse Suppose we have written a class CostMatrix that has a static method parse for parsing the input file Then our main could look something like this:

Setting command line parameters in Eclipse If we run this (Run -> Run), we get an error: We have to tell Eclipse to pass the appropriate command-line arguments to our application

Setting command line parameters in Eclipse We can configure this in the Run Configurations:

Setting command line parameters in Eclipse The appropriate tab is fittingly called Arguments: Note that you have to run the program once for Eclipse to generate a default run configuration (it will have the same name as the project)

Understanding stack traces Sometimes there are errors in our programs - if we are lucky, the program crashes Java will present us with a stack trace in this case: Each level of the stack trace represents an active function call at the time of the crash We do not only know in which function the program crashed, but also where this function was called from The larger a program gets, the more valuable this information becomes

Understanding stack traces Since it is a stack trace, the most recent call is at the top (you will learn about stacks in detail later this semester) In Eclipse, you can click on the source-links to get to the point of the error or call Let s look at this stack trace in detail and see what it tells us

Understanding stack traces The error happened in the function CostMatrix.getCost that returns the distance between two cities:

Understanding stack traces This method was called from the overloaded method CostMatrix.getCost that calculates the cost of a route:

Understanding stack traces This method was called from getbestroute:

Understanding stack traces Which called itself recursively:

Understanding stack traces In normal Java-applications, the first call always comes from main:

Breakpoints Unfortunately, this is not enough information to solve the problem We need information about the runtime-state We can get this using the debugger along with a breakpoint A breakpoint marks a point in our program, at which we want to pause the execution in order to inspect the state of the program

Breakpoints To set a breakpoint at a specific line in the code, go to that line (by clicking on the link in the stack trace) and toggle a breakpoint: The dot on the left side indicates a breakpoint on that line

Breakpoints If we execute our program as usual, nothing special will happen, because breakpoints only have an effect in debug-mode:

Breakpoints Eclipse will ask you if you want to switch into the Debug-perspective - you should do that The program will then run until it hits the breakpoint (which will be immediately in our simple example) In the Debug-view (top left), we can see the current call-stack:

Breakpoints In the top right, the Variables-view shows us all variables that are currently in scope, and their current values: This tells us that getcost was just called with the parameters "Berlin" and "Dresden"

Breakpoints If we move one step up in the call-stack (you can click on each call in the current call-stack), we see this: The surrounding call to getcost was called to calculate the total cost for the route [Berlin, Dresden, Hamburg]

Breakpoints First, lets try to reproduce the crash by stepping through the program: Step Over executes the program until the next line of code in the current function (or, if the function returns, it goes on to the point it was called from) Alternatively, we could use Step Into (the symbol left of Step Over), to also step into any functions called in the current line

Breakpoints As we can see, the error did indeed occur: So, what happened in this line? One of the calls to cities.get must have returned null

Breakpoints If we inspect cities in the Variables-view, we see the problem: Neither "Dresden" nor "Berlin" are in cities - this should not happen

Breakpoints So, how to fix this problem? First, check if input data is parsed correctly - this can be done by setting a breakpoint directly after the code that loads the data: Everything looks fine - so apparently, some entries get removed from cities at some point in the program We can go through the program step-by-step to find the line that deletes the cities

Breakpoints This way, we finally find the cause of the problem:

Breakpoints The fix is, to make a copy of cities before modifying it:

Breakpoints In general, we can of course do this without a debugger, by inserting print-statements throughout our code Debuggers take some getting used to, but once you get the hang of it, you will find it much easier and cleaner There are much more features (for instance Watchpoints to break when a variable is accessed or modified)

Extra Hint - Use Assertions! Use assertions to check if certain assumptions or pre-/post-condition are hold true: This assertion will throw an AssertionError if localbestroute does not contain the same amount of cities as cities Assertions are intended to protect you from programmer mistakes (speak your own mistakes)

Resources These slides will be uploaded to the website of this exercise http://icsa.uwgb.edu/~songh/sc/eclipsedebuggertutorial/ There will be a screencast demonstrating the example on the website