1 / 7

Building Java Programs Chapter 1

Building Java Programs Chapter 1. Errors. Objectives. Recognize different errors that Java uses and how to fix them. Let’s Get Started. When you write programs, there are three types of errors that you may introduce… what are they? Syntax Errors Logic Errors Runtime Errors.

shika
Download Presentation

Building Java Programs Chapter 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building Java ProgramsChapter 1 Errors

  2. Objectives • Recognize different errors that Java uses and how to fix them.

  3. Let’s Get Started • When you write programs, there are three types of errors that you may introduce… what are they? • Syntax Errors • Logic Errors • Runtime Errors

  4. Syntax error example • Where are the errors in the following program? 1public class Hello { 2pooblic static void main(String[] args) { 3System.owt.println("Hello, world!") 4 } 5 } Compiler output: Hello.java:2: <identifier> expected pooblic static void main(String[] args) { ^ Hello.java:3: ';' expected } ^ 2 errors • The compiler shows the line number where it found the error. • The error messages can be tough to understand!

  5. Logic error example • Where are the errors in the following program? 1public class Hello { 2public static void main(String[] args) { 3System.out.println("Hello, “ • 4 + “world!"); 5} 6} • Compiler output? • Nothing! Only the programmer can catch logic errors. • Program output? • Unexpected: Hello, World!

  6. Runtime error example • Where are the errors in the following program? 1public class Hello { 2 public static void main(String[] args) { • 3 Function1DividedBy0(); 4 } 5 } • Compiler output? • Nothing. (Unless you have a smart compiler!) • Program output? • Crash!

  7. With A partner (or two) • Divide your notebook into three sections: Syntax, Logic, and Runtime. For each section, see how many different types of errors you can come up with. • You can use JGraspto help you think of errors. • Hint: Start from a working version of the Hello.java program. • Here are some examples to get you started • Syntax: Missing a semicolon • Logic: Calling the wrong function • Runtime: Dividing by 0

More Related