Well-behaved objects Debugging. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Prevention vs Detection.

Slides:



Advertisements
Similar presentations
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Advertisements

Comp1004: Building Better Classes I Testing and Debugging Partly based on BlueJ Book – Chapter 6.
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
Objects First with Java A Practical Introduction using BlueJ
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Understanding class definitions Looking inside classes 3.0.
Well-behaved objects Improving your coding skills 1.0.
Testing and Debugging. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling (Reminder) Zuul Assignment Two.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Object interaction Creating cooperating objects 3.0.
Make Sure You Know All This!. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 2 Objects and Classes.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Object interaction Creating cooperating objects 5.0.
Object interaction Creating cooperating objects 5.0.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
CS1101: Programming Methodology Aaron Tan.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
Using a Debugger. SWC What is ”debugging”? An error in a computer program is often called a ”bug”… …so, to ”debug” is to find and get rid of errors in.
Testing. Definition From the dictionary- the means by which the presence, quality, or genuineness of anything is determined; a means of trial. For software.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles Modified from the Slides made by Sylvia Sorkin, Community College of Baltimore.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
COS 260 DAY 5 Tony Gauvin.
The Software Development Process
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
©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.
OOPDA Intro 5.0. Topics Website and Syllabus Rowan VPN and H:drive BlueJ application and projects Programming Style (Appendix J) Javadoc (Appendix I)
Testing. Have you contacted your project members lately?
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
1 COS 260 DAY 15 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz Today –Chapter 6 Assignment 4 posted –Due Nov 9 Capstone progress reports are due –Brief.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Chapter – 8 Software Tools.
Bugs CS100 how to prevent them, how to find them and how to terminate them.
Chapter 1: Introduction to Computers and Programming.
Chapter 6 Testing and running a solution. Errors X Three types Syntax Logic Run-time.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability © 2017 Pearson Education, Inc. Hoboken,
Objektorienterad programmering d2, förel. 6
Objects First with Java
SOFTWARE TESTING Date: 29-Dec-2016 By: Ram Karthick.
14 Compilers, Interpreters and Debuggers
Objects First with Java Creating cooperating objects
Dept of Computer Science University of Maryland College Park
C++ Plus Data Structures
Objektorienterad programmering d2, förel. 6
CS1101X Programming Methodology
Testing and Debugging.
CS 153: Concepts of Compiler Design November 30 Class Meeting
COS 260 DAY 17 Tony Gauvin.
Objects First with Java
COS 260 DAY 16 Tony Gauvin.
Debugging 9/22/15 & 9/23/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
COS 260 DAY 15 Tony Gauvin.
COS 260 DAY 16 Tony Gauvin.
Testing, debugging, and using support libraries
Objects First with Java Creating cooperating objects
Objects First with Java Creating cooperating objects
Presentation transcript:

Well-behaved objects Debugging

2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Prevention vs Detection (Developer vs Maintainer) We can lessen the likelihood of errors. Use software engineering techniques, like encapsulation. We can improve the chances of detection. Use software engineering practices, like modularization and documentation. We can develop detection skills.

3 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Debugging techniques Manual walkthroughs Print statements Debuggers

4 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Modularization and interfaces Applications often consist of different modules. –E.g. so that different teams can work on them. The interface between modules must be clearly specified. –Supports independent concurrent development. –Increases the likelihood of successful integration.

5 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Modularization in a calculator Each module does not need to know implementation details of the other. –User controls could be a GUI or a hardware device. –Logic could be hardware or software.

6 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Method signatures as an interface // Return the value to be displayed. public int getDisplayValue(); // Call when a digit button is pressed. public void numberPressed(int number); // Call when a plus operator is pressed. public void plus(); // Call when a minus operator is pressed. public void minus(); // Call to complete a calculation. public void equals(); // Call to reset the calculator. public void clear();

7 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Debugging It is important to develop code-reading skills. –Debugging will often be performed on others’ code. Techniques and tools exist to support the debugging process. Explore through the calculator-engine project.

8 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Manual walkthroughs Relatively underused. –A low-tech approach. –More powerful than appreciated. Get away from the computer! ‘Run’ a program by hand. High-level (Step) or low-level (Step into) views.

9 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Tabulating object state An object’s behavior is usually determined by its state. Incorrect behavior is often the result of incorrect state. Tabulate the values of all fields. Document state changes after each method call.

10 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Verbal walkthroughs Explain to someone else what the code is doing. –They might spot the error. –The process of explaining might help you to spot it for yourself. Group-based processes exist for conducting formal walkthroughs or inspections.

11 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Print statements The most popular technique. No special tools required. All programming languages support them. Only effective if the right methods are documented. Output may be voluminous! Turning off and on requires forethought. –can be turned on and off using Boolean variable

12 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Choosing a test strategy Be aware of the available strategies. Choose strategies appropriate to the point of development. Automate whenever possible. –Reduces tedium. –Reduces human error. –Makes (re)testing more likely.

13 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Debuggers Debuggers are both language- and environment-specific. –BlueJ has an integrated debugger. Support breakpoints. Step and Step-into controlled execution. Call sequence (stack). Object state.

14 Debugger – cont’d Undoubtedly useful facility but should be used in a methodical fashion. E.g. 1.From the symptoms observed, infer where the bug lies – possibly within 2 or 3 methods 2.Place breakpoints at the entry and exit of suspected methods 3.Run the program. When the program stops examine the values of the methods’ arguments and subsequently any return value. Identify the appropriate method. 4.Re-run the program stopping at the erroneous method and then single step through it until the cause has been identified.

15 Example E.g.Suppose we wish to monitor the determination of an average in the studentAverage project. Create a student object “Alan” and submit a mark 50 Open Editor on class Student and place breakpoint next to: i.e. click in margin alongside line. Call submitMark and enter 60. submissions += 1;

16 Debugger example 1.Start

17 Example – 2 2.Click to move on to next statement.

18 Example – 3 3.Click to move on to next statement.

19 Example – 4 4.When the method has been completed, execution will be stopped to await the next method call. call submitMark, again, and enter 100. then continue step by step with or continue to the end with finally click

20 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Review Errors are a fact of life in programs. Good software engineering techniques can reduce their occurrence. Testing and debugging skills are essential. Make testing a habit. Automate testing where possible. Practice a range of debugging skills.