|
|
|
|
||
|
|
Programming Errors |
|
||
|
|
Introduction In
this lab we will write some simple Java programs and explore the different
types of errors that you will encounter as you develop and write programs. The
three types of errors that are typically encountered in writing programs are
the following: ·
compile time errors ·
runtime errors ·
logical errors Compile
time errors occur when you are attempting to compile your program and the IDE
reports an error. It will usually give
the line number at which the error occurred.
An example would be a failure to put a semicolon at the end of a
statement. A runtime error occurs while you are executing your program. A typical runtime error would be division
by zero. A logical error is when your
program executes, but fails to produce the desired result. Sometimes the errors of each type can be
difficult to correct, but often time the logical errors are the most
difficult because they are the hardest to see. |
|
||
|
|
Procedure Create a New Project and Test Errors of Different Types 1. As in the previous exercise, create a
new project labeled "ErrorTest". 2. Create a new class in the project as
in the previous exercise. 3. Copy the following code and use it to
replace the code that the IDE gives
4. Compile and execute the code. 5. Change the name of the class to
"ErrTest" and compile and run. What happens? If there is an error what
type of error is it? 6. Delete the semicolon from the line ' System.out.println("Now is the time");'. and compile and
run. What happens? If there is an error what type of error is
it? 7. Change the spelling of one of the
words in the line ' System.out.println("for all good men to");' and compile
and run. What happens? If there is an error what type of error is
it? 8. Delete one of the quotation marks in
the line ' System.out.println("come to the aid of");' and compile
and run. What happens? If there is an error what type of error is
it? 9. Change "println"
to "print" in the line ' System.out.println("come
to the aid of");' and compile and run.
What happens? If there is an
error what type of error is it? 10. Change "static" to "Static" in the line ' public
static void main (String args[])' and compile
and run. What happens? If there is an error what type of error is
it? 10. Add a semicolon after the line ' public
static void main (String args[])' and compile and run.
What happens? If there is an
error what type of error is it? |
|
||
|
|
Programming Assignment 1. Write a program to print the poem of
your choice on the screen. (it must not be the same
as your neighbors!) 2. Turn in a program listing your source
code as with the first exercise. Be
sure to modify the output window properties to change the background and
foreground colors. |
|
||
|
|
Questions 1. What is the function of having a
"main" method?. 2. What do you think the function of the
"(String[] args)"
is?. 3. What is the difference between RAM
and ROM? 4. How do you suppose that you might get
the computer to print quotation marks on the screen? 5. What are the reserved words in the
above listing? |
|
||
|
|
|
|