BUILDING JAVA PROGRAMS CHAPTER 1 ERRORS. 22 OBJECTIVES Recognize different errors that Java uses and how to fix them.

Slides:



Advertisements
Similar presentations
Your First Java Program: HelloWorld.java
Advertisements

Chapter 2: Your First Program! Hello World: Let’s Program  All programs must have the extension.java  Our first program will be named: HelloWorld.java.
Building Java Programs Chapter 1 Introduction to Java Programming.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Java Overview February 4, /4/2004 Assignments Due – Homework 1 Due – Reading and Warmup questions Project 1 – Basic Networking.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 1: Introduction to Java Programming.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
1 Classes begin with capital letters (i.e. UrRobot). Methods, objects, and variable names begin with lower case (camelCase) Use indentation to line up.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in In the Java programming language: A program is made.
CS 112 Introduction to Programming Lecture 3: Java Methods Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
Programming Concept Chapter I Introduction to Java Programming.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
Copyright 2009 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Repetition Statements while and do while loops
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Review :chapters What is an algorithm? A step by step description of how to accomplish a task. For example, Adding 3 numbers N1, N2 and N3 Add.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
CS 112 Introduction to Programming Lecture 3: Java Methods Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
AP Computer Science A – Healdsburg High School 1 Unit 2 - Structure of a Java Program - Documentation - Types of Errors - Example.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
Copyright 2010 by Pearson Education CSE 142, Spring 2012 Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: 1.1 -
Welcome to CSE 142! Zorah Fung University of Washington, Summer Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
Computer Programming Your First Java Program: HelloWorld.java.
CompSci 230 S Programming Techniques
Chapter 1 – Introduction
The eclipse IDE IDE = “Integrated Development Environment”
John Woodward A Simple Program – Hello world
Chapter 1 Introduction to Computers, Programs, and Java
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Intro to Java.
Comp Sci 200 Programming I Jim Williams, PhD.
Benson Limketkai and Marty Stepp University of Washington, Spring 2010
Writing Methods.
How to Run a Java Program
Benson Limketkai University of Washington, Spring 2011
Exercise 11.1 Write a code fragment that performs the same function as the statement below without using the crash method Toolbox.crash(amount < 0,
Building Java Programs
Java Intro.
How to Run a Java Program
CS110D Programming Language I
class PrintOnetoTen { public static void main(String args[]) {
Building Java Programs
Welcome to CSE 142!.
CSE 142, Summer 2012 Building Java Programs Chapter 1
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
CSE 142, Spring 2012 Building Java Programs Chapter 1
Debugging Exercise 00 Try compiling the code samples.
CSE 142, Winter 2014 Building Java Programs Chapter 1
How to Run a Java Program
Presentation transcript:

BUILDING JAVA PROGRAMS CHAPTER 1 ERRORS

22 OBJECTIVES Recognize different errors that Java uses and how to fix them.

33 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

44 SYNTAX ERROR EXAMPLE Where are the errors in the following program? 1 public class Hello { 2 pooblic static void main(String[] args) { 3 System.owt.println("Hello, world!") 4 } 5 } Compiler output: Hello.java:2: 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!

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

66 RUNTIME ERROR EXAMPLE Where are the errors in the following program? 1 public 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!

77 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 JGrasp to 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