Download presentation
Presentation is loading. Please wait.
Published byTobias Randall Modified over 6 years ago
1
Debugging 9/22/15 & 9/23/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010
2
Exam I Next week. Tu 9/29/15 & W 9/30/15
3
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.
4
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.
5
Syntax Errors Error that keeps the program from compiling.
Missing or Extra Semicolons Spelling and Capitalization Missing quote, parenthesis, or braces Missing operators Missing concatenation in println Unintialized Variables Not assigned value Example:DebugSyntax
6
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
7
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
8
Using eclipse Debugger
Can set breakpoints. Right-click in bar left of code. “Debug as”. Execution stops at breakpoint. Green arrow to continue execution. Can inspect variable contents. “variables” tab Java button to get back to normal mode.
9
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 execution errors?
10
Class DecimalFormat Class DecimalFormat enables control of output
In java.text package. Specify a string pattern to describe desired format DecimalFormat formatter = new DecimalFormat("0.000"); System.out.println(formatter.format(val));
11
Class DecimalFormat 0 – digit, leading and trailing zeros
# -- digit, no leading and trailing zeros % -- percentage $ -- at beginning displays dollar sign
12
Class DecimalFormat DecimalFormat
13
Program Problem Write a program to input a temperature between 30.0 and degrees. Output the temperature to the nearest tenth degree My version: DecimalDemo.java
14
Participation Write a program to input a cash award between $0.00 and $ Use a DecimalFormat to control the output. Output the number to the nearest cent. While writing the program, try setting a breakpoint and inspecting some variables.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.