Presentation is loading. Please wait.

Presentation is loading. Please wait.

SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.

Similar presentations


Presentation on theme: "SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program."— Presentation transcript:

1

2 SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program

3 Code Listing: Parts of a Java Program Reminder: The names of Java source files end with.java Closer examination of program, line by line : 1.// marks the beginning of a comment, the compiler ignores everything from the double slashes to the end of the line. Purpose is to document the code 2 Chapter 2: Parts of a Program

4 Code Listing: Parts of a Java Program Line 2: Blank – Known as “white space,” to make the program easier to read Line 3: class header (click to read more) 3 Chapter 2: Parts of a Program Marks beginning of a “class definition” public is an access specifier class is written in all lower case, Java keyword, beginning of a class definition Simple – name of the class, usually in Book title - upper case (user defined)

5 Code Listing: Parts of a Java Program Line 4. The Left brace is like the left cover of a book, it is the beginning of the class definition 4 Chapter 2: Parts of a Program Left brace – open brace

6 Code Listing: Parts of a Java Program Line 5: A method header A group of one or more programming statements that has a name. public static void main(String[] args) 1. public - methods are public or private, public ones are available from outside the class 2. static - all lower-case 3. void – methods can be used to return a value, if it does NOT return a value it is void 4. main – all lower case, every Java application has to have a least one main, but it can call other classes and instantiate objects from classes known to the project (see import) 5. Parameters 5 Chapter 2: Parts of a Program every Java application has to have one main,

7 Code Listing: Parts of a Java Program Line 6: Another left brace, but this marks the beginning of the method body 6 Chapter 2: Parts of a Program

8 Code Listing: Parts of a Java Program Line 7 Java statement, ends with a semicolon System – group of classes out – output class println – method that prints (outputs) a line of output and advances the cursor to the next line down String literal – all the characters within the quotation marks, put into the output “stream” just as it appears. Line 8: a closing or right brace, ends the main method 7 Chapter 2: Parts of a Program

9 Code Listing: Parts of a Java Program Line 9: closes the class 8 Chapter 2: Parts of a Program

10 Code Listing: Parts of a Java Program Summary of Simple program, Comments (remarks in Visual Basic) do not end with a semicolon, they are ignored by the compiler. Class headers and method headers do not end with a semicolon Use left and right braces to begin or end a class or method definition. 9 Chapter 2: Parts of a Program

11 Review Chapter 2: Parts of a Program 10 Java is case sensitive All Java programs must be stored in a file with a name that ends with the.java extension Comments are ignored A.java file can have many classes but only one public class Every Java application must have a method called main For every left brace there must be a right Statements end with semicolon


Download ppt "SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program."

Similar presentations


Ads by Google