Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.

Similar presentations


Presentation on theme: "Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better."— Presentation transcript:

1 Introducing Java Chapter 3 Review

2 Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better develop complex programs. Java is also platform independent meaning it can run on any computer

3 Objects, Classes & Packages Object-oriented languages use classes to define objects. A class defines the type of data and actions associated with an object, but not the actual data for an object. A package groups related classes. A Java application is a package with at least one class.

4 A Java Application A program consists of a set of instructions called statements. A semi-colon is required to indicate the end of a statement. Related statements are enclosed by curly brackets Methods are a named set of statements that perform a single, well-defined task. Comments in an application provide details about the code to the reader.

5 Executing a Java Application The code typed by a programmer is called source code. It is translated to bytecode with a compiler. Program execution occurs when the bytecode is interpreted with a Java Virtual Machine (JVM). If a program contains errors, it will not compile. One type of error is the syntax error, which results when a statement violates the rules of Java.

6 Displaying Output The standard output stream is typically the computer screen and requires the System.out. methods print() and println(). println() puts the insertion point on the next line. These methods require a string argument. If a program contains errors, it will not compile. Escape sequences are used to display special characters. i.e.) \n new line, \t tab (8 spaces), \\ backslash

7 Formatting Output Output can be formatted with the format() method. A format string specifier takes the form: %[alignment][width]s % indicates the start of a specifier [alignment] skip for right alignment, Include a minus sign (–) for left alignment [width] the number of characters to use for output s indicates that the corresponding argument is a string System.out.format("%-10s %8s %8s", "Team", "Wins", "Losses\n");

8 Code Conventions Code conventions are a set of guidelines for writing an application. They are: An introductory comment should begin a program. This comment should include information such as your name, class name, the date, and a brief statement about the program. Package names should begin with a lowercase letter and then an uppercase letter should begin each word within the name. Package names may not contain spaces.

9 Code Conventions Cont’d Class names should be nouns and begin with an uppercase letter and then an uppercase letter should begin each word within the name. Class names may not contain spaces. A comment block should be included before each class and method. A comment block is not typically placed before the main() method. Comments should not reiterate what is clear from the code. Statements in a method should be indented.

10 Code Conventions Cont’d An open curly brace ({) should be placed on the same line as the class or method declaration, and the closing curly brace (}) should be on a separate line and aligned with the class or method declaration.

11 Algorithm Design An algorithm is a list of steps to solve a problem. When written in plain English, with a mixture of code it is called pseudocode. Algorithms can also be presented visually with a flowchart.

12 Flowchart Symbols Start or end process flow of control process Input/output

13 Flowchart Symbols Cont’d Conditional or decision sub routines


Download ppt "Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better."

Similar presentations


Ads by Google