Lesson Plan Course Title: Computer Programming Session Title: Your First Java Program: HelloWorld.java 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: Students will write and compile a simple Java program Students will troubleshoot and correct errors in a Java program Students will revise their own program to include specific errors Students will identify specific lines of a program Preparation TEKS Correlations: 130.276.Computer Programming • (1E) Solve problems and think critically; • (7D) Demonstrate skill in program testing; • (7E) Compare computed results with anticipated results to determine the reasonableness of the solutions; • (7F) Troubleshoot technological problems. 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 copy of Lab Handout. IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 1 Equipment 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 MI Introduction (LSI Quadrant I): Before introducing the HelloWorld program, visit Wikipedia.org and search "HelloWorld". Show students that the program is a classic "first" program for any student learning a new programming language. Outline MI Outline (LSI Quadrant II): Instructor Notes: The instructor will introduce the new concepts using the presentation. Outline of each slide shown below: Students will watch the teacher during this section. They should be encouraged to take notes and write comments during the presentation. 1. Explain that “HelloWorld” is the classic first program for any student who is learning a new programming language. It demonstrates 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 IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 2 the program into “blocks”. Every open brace must have a closing brace. Braces are nested inside the program. 6. Line 6 sets up the first line of the main method. This is where the Java runtime looks to begin reading the code for execution. Java reserved words on this line are “public”, “static”, “void”. The word “main” is not reserved, but must be included in your main application program. 7. Line 7 shows the beginning of the second set of curly braces. Indentation helps to organize the code into readable sections. Indentation is not required, but shows good programming style. 8. Line 8 is the actual statement that does something that you can see. The command to show output on the screen in Java is “System.out.println”. The “S” must be capitalized or the compiler will not understand the statement. Your desired output is shown in parentheses and the actual string to be printed is enclosed in quotes. Java requires that statements end with a semicolon. 9. Line 9 is the closing brace to line 7 and Line 10 is the closing brace to line 5. Once again, the indentation helps you to see where the blocks begin and end. 10. Line 10 shows the intended output of the program. When all compiler errors are fixed, the “Hello World!” message should be displayed in the output section of your IDE. 11. At this point, you should type the program and demonstrate to students. Upon completion of a successful "HelloWorld" program, the instructor should introduce errors to the program, describe the errors, and correct the errors. 12. It is helpful to the students for you to demonstrate errors before the students actually code their own program. Show how minor changes can introduce many compiler errors. Show at least 3 compiler errors. Compiler errors can be: misspelled reserved words, missing semicolon, missing quotes, and missing curly braces. Be careful to fix each error as it occurs and let the students IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 3 see only one error at a time. After you have successfully demonstrated a complete program and introduced errors, the students will have the opportunity to create their own “HelloWorld” program. Application MI Independent Practice (LSI Quadrant III): • Students will complete the lab with associated error definitions. 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 MI Informal Assessment (LSI Quadrant III): • MI 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! Formal Assessment (LSI Quadrant III, IV): • Quiz Extension MI Extension/Enrichment (LSI Quadrant IV): • 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. IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 4 Icon MI Verbal/ Linguistic Logical/ Mathematical Visual/Spatial Musical/ Rhythmic Bodily/ Kinesthetic Intrapersonal Interpersonal Naturalist Existentialist Teaching Strategies Personal Development Strategies Lecture, discussion, journal writing, cooperative learning, word origins Reading, highlighting, outlining, teaching others, reciting information Problem solving, number games, critical thinking, classifying and organizing, Socratic questioning Mind-mapping, reflective time, graphic organizers, color-coding systems, drawings, designs, video, DVD, charts, maps Use music, compose songs or raps, use musical language or metaphors Organizing material logically, explaining things sequentially, finding patterns, developing systems, outlining, charting, graphing, analyzing information Developing graphic organizers, mindmapping, charting, graphing, organizing with color, mental imagery (drawing in the mind’s eye) Use manipulatives, hand signals, pantomime, real life situations, puzzles and board games, activities, roleplaying, action problems Reflective teaching, interviews, reflective listening, KWL charts Cooperative learning, roleplaying, group brainstorming, cross-cultural interactions Natural objects as manipulatives and as background for learning Socratic questions, real life situations, global problems/questions Creating rhythms out of words, creating rhythms with instruments, playing an instrument, putting words to existing songs Moving while learning, pacing while reciting, acting out scripts of material, designing games, moving fingers under words while reading Reflecting on personal meaning of information, studying in quiet settings, imagining experiments, visualizing information, journaling Studying in a group, discussing information, using flash cards with other, teaching others Connecting with nature, forming study groups with like minded people Considering personal relationship to larger context IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 5 NAME DATE LAB HelloWorld.java 1. Enter the following program. 2. Compile and run the program. You should have a working program before you go on to the next step. // Name: your name here // Date: today’s date here // Program: HelloWorld.java public class HelloWorld { public static void main (String[] args) { System.out.println ("Hello World!"); } } 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 ________________________________________________________________ d. remove the last quotation mark in the string ________________________________________________________________ e. change main to man ________________________________________________________________ f. change println to bob ________________________________________________________________ g. remove the semicolon at the end of the println statement IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 6 ________________________________________________________________ h. remove the last brace (}) in the program ________________________________________________________________ IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 7 NAME DATE LAB HelloWorld.java Solution 1. Enter the following program. 2. Compile and run the program. You should have a working program before you go on to the next step. // Name: your name here // Date: today’s date here // Program: HelloWorld.java public class HelloWorld { public static void main (String[] args) { System.out.println ("Hello World!"); } } 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____________________________________________________ l. remove the last quotation mark in the string unclosed string literal ';' expected reached end of file while parsing ______________________________________ m. change main to man no compiler errors, but the program will not execute; this is a run-time error ____ n. change println to printline cannot find symbol method printline(java.lang.String) ______________________ IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 8 o. remove the semicolon at the end of the println statement ';' expected _______________________________________________________ p. remove the last brace (}) in the program reached end of file while parsing ______________________________________ IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 9 NAME DATE Hello World Quiz 1 2 3 4 5 6 7 8 9 // Name: J. Programmer public class Quiz { public static void main(String [] args) { System.out.println ("This is a quiz."); } } 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. IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 10 NAME DATE Hello World Quiz Solution 1 2 3 4 5 6 7 8 9 // Name: J. Programmer public class Quiz { public static void main(String [] args) { System.out.println ("This is a quiz."); } } 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 public class ShowBirthday { public static void main(String [] args) { System.out.println ("January 1, 2000"); } } IT: Beginning Computer Programming: First Java Program Lesson Plan Copyright © Texas Education Agency, 2013 11