Lab Exercise 1
Lab Exercise 1
Lab Exercise 1
Lesson Duration:
2 hours
Performance Objective:
Upon completion of this assignment, the student will be able to write, compile, and troubleshoot
a Java program.
Specific Objectives:
Preparation
Instructor/Trainer
References:
Content-developer knowledge
Instructional Aids:
Instructional Presentation
Lab Handout: HelloWorld
Lab Solution
Lab Quiz
Lab Quiz - Solution
Materials Needed:
Each student will need a computer with Java installed and/or an IDE installed (JCreator,
Eclipse, etc.). There is no charge for these programs.
The instructor should also have the IDE installed, and be able to use a projector for
demonstration.
Introduction
Outline
The instructor will introduce the new concepts using Students will watch the
the presentation. Outline of each slide shown below: teacher during this section.
They should be encouraged
1. Explain that HelloWorld is the classic first
to take notes and write
program for any student who is learning a
comments during the
new programming language. It demonstrates
presentation.
that you can put together a small program,
compile it, and run with intended results.
2. The entire HelloWorld program is shown with
10 lines of code. You can choose to type it in
at this point, or to evaluate line-by-line. You
can use your choice of IDE (Integrated
Development Environment) to type, compile,
and run your program.
3. Comments give information to the reader;
they are ignored by the compiler. Comments
are indicated by the double-slashes at the
beginning of the line. The comments should
be new color depending on the IDE used.
4. Program declaration is the required first line
of the program. It shows the name of the
program, and must match the file name as it
is saved. On this line, public and class are
reserved words and will be a different color in
your IDE. HelloWorld is a user-defined
word and shows the name of the program.
5. Curly braces are used to separate parts of
Application
MI Independent Practice (LSI Quadrant III):
Summary
MI Review (LSI Quadrants I and IV):
Students will play with more errors. Ask them to see how many different
errors they can find. Also, ask them to create an error and have their
neighbor fix the error.
Evaluation
The instructor will walk around the room and observe the students during the
lab. Encourage students to fix their own errors. Be careful not to give too
much advice!
Quiz
Extension
Students should practice fixing their own errors. This step is critical in future
programs where they find themselves stumped and are not able to read the
error messages effectively.
LAB HelloWorld.java
3. Introduce the following errors into the program above. Make the changes ONE AT A TIME;
recompile; record the error message on this paper. Fix the previous error each time before
you go to the next. If no error happens, explain why.
a. ____________________________________________________________________ cha
nge HelloWorld to helloworld
________________________________________________________________
b. ____________________________________________________________________ cha
nge Hello to HELLO
________________________________________________________________
c. ____________________________________________________________________ re
move the first quotation mark in the string
________________________________________________________________
3. Introduce the following errors into the program above. Make the changes ONE AT A TIME;
recompile; record the error message on this paper. Fix the previous error each time before
you go to the next. If no error happens, explain why.
i. _____________________________________________________________________ cha
nge HelloWorld to helloworld
class helloworld is public; should be declared in a file named helloworld.java ___
j. _____________________________________________________________________ cha
nge "Hello World!" to "HELLO WORLD"!
no error because strings can contain any combination of characters and symbols
k. ____________________________________________________________________ re
move the first quotation mark in the string
')' expected
Yes. This one change
unclosed string literal
prompted 3 errors!
not a statement____________________________________________________
1 // Name: J. Programmer
2
3 public class Quiz
4 {
5 public static void main(String [] args)
6 {
7 System.out.println ("This is a quiz.");
8 }
9 }
Write the line number associated with the phrase: (numbers may be used more than
once or not at all)
1. ____ program declaration
2. ____ statement
3. ____ comment
4. ____ shows the name of the program
5. ____ declares the main method
6. ____ shows the text that will be displayed
7. ____ ends the main method
8. ____ gives information to the reader
9. ____ shows that the program is available to the public
10. ____ shows the name of the programmer
Write a complete program to display your birthday. Include comments with your name,
date, and program name.
Write the line number associated with the phrase: (numbers may be used more than
once or not at all)
1. ___ 3 program declaration
2. ___ 7 statement
3. ___ 1 comment
4. ___ 3 shows the name of the program
5. ___ 5 declares the main method
6. ___ 7 shows the text that will be displayed
7. ___ 8 ends the main method
8. ___ 1 gives information to the reader
9. ___ 3 shows that the program is available to the public
10. ___ 1 shows the name of the programmer
Write a complete program to display your birthday. Include comments with your name,
date, and program name. Name the program ShowBirthday.
// Name: J. Programmer
// Date: today's date
// Program: ShowBirthday.java