Wrapper Classes Debugging Interlude 1 2/12/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010
Objectives Define the terms bug and debugging. Explain what a compile-time error is. Explain what an execution-time error is. Give examples of compile-time errors. Give example of execution-time errors. Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010
Bugs and Debugging Bug Debugging Debugger Any error in a program. Grace Hopper's team logged a "bug" in 1945 Debugging Fixing errors. Debugger Special software to help fix programs. Usually part of IDEs like eclipse. Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010
Syntax Errors Error that keeps the program from compiling. Missing or Extra Semicolons Spelling and Capitalization Missing quote, parenthesis, or braces Missing operators Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010
More Syntax Errors Missing concatenation in println Unintialized Variables Not assigned value DebugSyntax Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010
Execution-Time Errors Logical Errors in a program Examples Incorrect Arithmetic. Divide by zero. Bad input. Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010
Debugging Techniques Visually inspect the code (not every test requires modifying/running the code). Manually set a variable to a value. Insert print statements to observe variable values. Comment out unused code. Example in DebugExecution.java
Using eclipse Debugger Can set breakpoints. Can inspect variable contents.
Questions What is the difference between a syntax error and a execution error? Does Java always give helpful error messages? What can you do to help debug logic errors?