1 / 12

Computer Programming

Computer Programming. Your First Java Program: HelloWorld.java. 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!"); } }.

Download Presentation

Computer Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Programming Your First Java Program: HelloWorld.java

  2. 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!"); • } • } IT: Beginning Computer Programming- First Java Program

  3. 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 IT: Beginning Computer Programming- First Java Program

  4. 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”. IT: Beginning Computer Programming- First Java Program

  5. 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. IT: Beginning Computer Programming- First Java Program

  6. 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. IT: Beginning Computer Programming- First Java Program

  7. 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. IT: Beginning Computer Programming- First Java Program

  8. 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. IT: Beginning Computer Programming- First Java Program

  9. 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. IT: Beginning Computer Programming- First Java Program

  10. Running the Program When you run the program, Hello World! Should display in the output window. IT: Beginning Computer Programming- First Java Program

  11. 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. IT: Beginning Computer Programming- First Java Program

  12. Ending the Lesson Play around making changes and noting the errors. Do not introduce more than one error at a time! IT: Beginning Computer Programming- First Java Program

More Related