Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming Your First Java Program: HelloWorld.java.

Similar presentations


Presentation on theme: "Computer Programming Your First Java Program: HelloWorld.java."— Presentation transcript:

1 Computer Programming Your First Java Program: HelloWorld.java

2

3 HelloWorld.java // 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!") }

4 Comments // Name: your name here // Date: today’s date here
// Program: Hello World Lines 1-3 are comments. Comments begin with //. Comments are ignored by the compiler. Used to give information to the reader.

5 Program Declaration public class HelloWorld
Line 4 is the program declaration. “public” is a key word indicating that the class file is usable by the public. “class” indicates that the file is a program. Classes are the building blocks of Java. “HelloWorld” is the name of the file. Java is case-sensitive. The file must be saved as “HelloWorld.java”.

6 Braces { Line 5 begins the program with an opening curly brace({).
Braces enclose statements that make up a programming block. Each opening brace must have a matching closing brace.

7 The Main Method public static void main (String[] args)
Line 6 is the main method declaration. A method contains programming statements. Every Java application must have a “main” method. (String[] args) is the parameter for the main method. Parameters will be discussed in detail later.

8 Braces { Line 7 begins the main method with an opening curly brace({).
Braces enclose statements that make up a programming block. Each opening brace must have a matching closing brace.

9 The Main Method System.out.println ("Hello World!")
Line 8 prints a line of text. The text that will be printed is enclosed in parentheses. The statement ends with a semicolon. “Hello World” is the text that will be displayed. Text enclosed in quotes is called a string.

10 Closing Braces } Line 9 and 10 close the braces that were opened on lines 5 and 7. Indenting is not necessary but helps to make the program more readable.

11 Running the Program When you run the program, Hello World!
Should display in the output window.

12 Introducing Errors Programmers are always fixing errors.
We will explore a few types of errors. Line 6: public static void main (String[] args). Change it to: public static vod main (String[] args). Compile and you will see the error: “cannot find symbol class vod” – therefore you need to correct the spelling. This is a compile-time error.

13 Ending the Lesson Play around making changes and noting the errors.
Do not introduce more than one error at a time!


Download ppt "Computer Programming Your First Java Program: HelloWorld.java."

Similar presentations


Ads by Google