lab 01-2 objectives: writing a java program. how to send output to the command line console. ...

106

Upload: winfred-douglas

Post on 18-Jan-2016

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Page 2: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-2

Objectives: Writing a Java program. How to send output to the command line

console. Learn about escape sequences. Learn how to compile, debug, and

execute a Java program.

Page 3: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Console Output

In Java, console output is achieved by calling System.out.print or System.out.println.

• The data to be output is given as an argument in parentheses.

System.out.println(“Blackjack”);

• Every invocation of println ends a line of output.

Blackjack_

Lab 01-3

Page 4: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

println Versus print

The print method is like println, except that it does not end a line• With println, the next output goes on a new line

• With print, the next output goes on the same line

Lab 01-4

Page 5: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ”);

System.out.print(“World”);

Lab 01-5

The print Method

Page 6: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ”);

System.out.print(“World”);

Output

HelloWorld

Lab 01-6

The print Method

Page 7: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ”);

System.out.print(“World”);

Lab 01-7

The print Method

Page 8: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ”);

System.out.print(“World”);

Output

Hello World

Lab 01-8

The print Method

Page 9: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.println(“Hello”);

System.out.println(“World”);

Lab 01-9

The println Method

Page 10: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.println(“Hello”);

System.out.println(“World”);

Output

Hello

World

Lab 01-10

The println Method

Page 11: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

21 is a Blackjack

7

7 is lucky

Lucky number 34

• A plus sign is used to connect more than one item

System.out.println(21 + “ is a Blackjack”);

System.out.println(3 + 4);

System.out.println(3 + 4 + “ is lucky”);

System.out.println(“Lucky number “ + 3 + 4);

The + Symbol

Lab 01-11

Page 12: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

6

Error – the * symbol can not be used with Strings

7 is lucky

Error – the – symbol can not be used with Strings

3

• Be careful when using other math symbols.

System.out.println(3 * 2);

System.out.println(3 * “Hello World”);

System.out.println(11 – 4 + “ is lucky”);

System.out.println(“Lucky number “ + 11 - 4);

System.out.println(15 / 4);

Other Math Symbol

Lab 01-12

Page 13: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Escape Sequences

• Escape sequences are used to print characters that are non-printable. Escape sequences always begin with a \ (backslash) character.

• Common Escape sequences

\n – new line

\” – quote symbol

\t – tab

\\ - backslash

Lab 01-13

Page 14: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Escape Sequences (Cont…)

Output

Hello

World

Lab 01-14

System.out.println(“Hello\nWorld”);

Page 15: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Escape Sequences (Cont…)

System.out.println(“Hello\tWorld”);

Lab 01-15

Output

Hello World

Page 16: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Escape Sequences (Cont…)

System.out.println(“\”Hello\tWorld\””)

Lab 01-16

Output

“Hello World”

Page 17: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Normally program statements execute from top to bottom.

This is called sequential control. Sequential control is the default control structure.

There are other control structures that we will discuss later.

Lab 01-17

Sequential Programming

The order in which statements occur is important.

Page 18: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Sequential Programming (cont…)

What will be output by the following program segment?

System.out.print(“Chester ”); System.out.print(“Nimitz”);

Lab 01-18

OutputChester Nimitz

Page 19: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Sequential Programming (cont…)

Now what will be output by the following program segment?

System.out.print(“Chester\nNimitz”);

Lab 01-19

OutputChesterNimitz

Page 20: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Sequential Programming (cont…)

Now what will be output by the following program segment?

System.out.println(“Chester\\Nimitz”);

Lab 01-20

OutputChester\Nimitz

Page 21: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Sequential Programming (cont…)

Keep in mind as you are programming that where you place a statement determines when it will be executed.

SEQUENTIAL CONTROL

Lab 01-21

Page 22: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Page 23: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation

System.out.print(“Hello ” + 1 + 2);

Lab 01-23

Here is a typical print statement.Here is a typical print statement.

Page 24: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(“Hello ” + 1 + 2);

Lab 01-24

“Hello 1”“Hello 1”

Page 25: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ” + 1 + 2);

String Concatenation (cont…)

Lab 01-25

“Hello 1”“Hello 1”

“Hello 12”“Hello 12”

Page 26: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(1 + 2 + “ Hello”);

Lab 01-26

Here is another typical print statement.Here is another typical print statement.

Page 27: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(1 + 2 + “ Hello”);

String Concatenation (cont…)

Lab 01-27

33

Page 28: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(1 + 2 + “ Hello”);

String Concatenation (cont…)

Lab 01-28

33

“3 Hello”“3 Hello”

Page 29: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(“Hello ” + 3 * 2);

Lab 01-29

Here is another typical print statement.Here is another typical print statement.

Page 30: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(“Hello ” + 3 * 2);

Lab 01-30

Multiplication has a higherprecedence than addition!Multiplication has a higherprecedence than addition!

Page 31: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(“Hello ” + 3 * 2);

Lab 01-31

66

Page 32: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Sequential Programming (cont…)

System.out.print(“Hello ” + 3 * 2);

Lab 01-32

66

“Hello 6”“Hello 6”

Page 33: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(“Hello ” + 6 - 4);

Lab 01-33

Here is another typical print statement.Here is another typical print statement.

Page 34: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(“Hello ” + 6 - 4);

Lab 01-34

“Hello 6”“Hello 6”

Page 35: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

String Concatenation (cont…)

System.out.print(“Hello ” + 6 - 4);

Lab 01-35

“Hello 6”“Hello 6”

Compile Time Error“operator - can not be applied to String, int”

Compile Time Error“operator - can not be applied to String, int”

Page 36: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ” + 6 - 4);

String Concatenation (cont…)

Lab 01-36

How can we “fix” this problem?How can we “fix” this problem?

Page 37: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ” + (6 - 4));

String Concatenation (cont…)

Lab 01-37

Use parantheses!Use parantheses!

Page 38: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ” + (6 - 4));

Sequential Programming (cont…)

Lab 01-38

22

Page 39: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.print(“Hello ” + (6 - 4));

Sequential Programming (cont…)

Lab 01-39

22

“Hello 2”“Hello 2”

Page 40: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Page 41: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-41

Start JCreator. Create a new file called “Lab01.java”. Save the new file in your Lab01 folder.

Top Down Design

Page 42: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-42

Creating A Java Class File

Page 43: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-43

Creating A Java Class File (cont…)

Page 44: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-44

Creating A Java Class File (cont…)

Page 45: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-45

Creating A Java Class File (cont…)

Page 46: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-46

Creating A Java Class File (cont…)

Page 47: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-47

Creating A Java Class File (cont…)

Class names should alwaysbegin with an uppercase letter.Class names should alwaysbegin with an uppercase letter.

Page 48: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-48

Creating A Java Class File (cont…)

Click this button toset the location.Click this button toset the location.

Page 49: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-49

Creating A Java Class File (cont…)

Page 50: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-50

Creating A Java Class File (cont…)

Page 51: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

}

Lab 01-51

Declaring A Java ClassThis class can be usedby other classes!This class can be usedby other classes!

Page 52: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

}

Lab 01-52

Declaring A Java ClassThe keyword class definesthis file as a Java class.The keyword class definesthis file as a Java class.

Page 53: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

}

Lab 01-53

Declaring A Java ClassUser defined name. Class names shouldalways begin with an uppercase letter.User defined name. Class names shouldalways begin with an uppercase letter.

Page 54: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

}

Lab 01-54

Declaring A Java Class

The body of every class beginsand ends with a set of curly brackets.The body of every class beginsand ends with a set of curly brackets.

Page 55: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-55

The main Method

• In Java, you need to have a method named main in at least one class.

• This method must appear within a class, but it can be any class.

• A class containing a main method is a program. Every program has a main method but not every class is a program.

Page 56: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

}}

Lab 01-56

The main Method (cont…)

Curly brackets are used to define blockstatements. Methods, like classes, areblock statements and must begin andend with a set of curly brackets.

Curly brackets are used to define blockstatements. Methods, like classes, areblock statements and must begin andend with a set of curly brackets.

Page 57: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

}}

Lab 01-57

The main Method (cont…)

The main method is static.The main method is static.

Page 58: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

System.out.println(“Main Method!”);}

}

Lab 01-58

The main Method (cont…)

Page 59: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-59

Compiling A Java Class File

Page 60: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-60

Compiling A Java Class File

Page 61: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-61

Running A Java Program

Page 62: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-62

Running A Java Program

Page 63: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

System.out.println(“Main Method!”);}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-63

The main Method (cont…)

output is not staticoutput is not static

Page 64: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

System.out.println(“Main Method!”);}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-64

The main Method (cont…)

Run the programRun the program

Page 65: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-65

The main Method (cont…)

Page 66: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

System.out.println(“Main Method!”);}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-66

The main Method (cont…)

output did not executeoutput did not execute

Page 67: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-67

The main Method (cont…)

Page 68: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-68

The main Method (cont…)

How do we get from hereHow do we get from here

Page 69: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-69

The main Method (cont…)

How do we get from here to thereHow do we get from here to there

Page 70: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

output();}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-70

The main Method (cont…)

A method call to outputA method call to output

Page 71: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-71

The main Method (cont…)

Page 72: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-72

The main Method (cont…)

Page 73: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-73

The main Method (cont…)

error: non-static method output() cannot be referenced from a static context

error: non-static method output() cannot be referenced from a static context

Page 74: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-74

The main Method (cont…)

Double click on the first line of the error.Double click on the first line of the error.

Page 75: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-75

The main Method (cont…)The editor will send the cursor to

the line that contains the error.

The editor will send the cursor to the line that contains the error.

Page 76: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Static methods are class methods. Non-static methods are instance methods. Class methods can not call instance methods – however instance methods can call class methods. More on this topic later.

To be able to call output we need an instance of the class Lab01.

Lab 01-76

The main Method (cont…)

Page 77: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-77

The main Method (cont…)

Page 78: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();

}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-78

The main Method (cont…)

lab is an object. An object is an instance of a class.

lab is an object. An object is an instance of a class.

Page 79: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(“Hello World”);

}}

Lab 01-79

The main Method (cont…)

We can call output using lab which is an instance of the class Lab01

We can call output using lab which is an instance of the class Lab01

Page 80: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-80

Run The Program

Page 81: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(“Hello\nWorld”);

}}

Lab 01-81

The main Method (cont…)

Page 82: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(“Hello\\World”);

}}

Lab 01-82

The main Method (cont…)

Page 83: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(“Hello World” + 1 + 2);

}}

Lab 01-83

The main Method (cont…)

Page 84: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-84

The main Method (cont…)

Page 85: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Control Structures

Lab 01-85

Page 86: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Sequential ControlBranchingConditionsLooping

Lab 01-86

Control Structures

Page 87: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

How The Program Executes.

Lab 01-87

Page 88: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-88

The main Method (cont…)

Page 89: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-89

The main Method (cont…)

Page 90: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-90

The main Method (cont…)

Page 91: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-91

The main Method (cont…)

Page 92: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-92

The main Method (cont…)

Page 93: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-93

The main Method (cont…)

Page 94: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-94

The main Method (cont…)

Page 95: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public class Lab01{

public static void main(String[ ] args){

Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(1 + 2 + “Hello World”);

}}

Lab 01-95

The main Method (cont…)

Page 96: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Page 97: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Refers to the order in which the individual statements of a program are executed or evaluated

Lab 01-97

Control Structures

Page 98: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Lab 01-98

• Sequential (Default)• Branching• Conditional• Repetition (looping)

Control Structures

Page 99: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Sequential Control:Statements are executed in the order in which they are written.

Lab 01-99

Control Structures

Page 100: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.println(“ABC”);System.out.println(“DEF”);

Lab 01-100

Control Structures

Page 101: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

System.out.println(“ABC”);System.out.println(“DEF”);

Lab 01-101

Output:ABCDEF

Control Structures

Page 102: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Branching:Allows the flow of execution to jump to a different part of the program.

Lab 01-102

Control Structures

Page 103: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public static void main(String[] args) {Lab01 lab = new Lab01();lab.output();

}

public void output() {System.out.println(“Hello World”);

}

Lab 01-103

Control Structures

Page 104: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

public void methodA() {methodB();methodC();

}

public void methodB() {System.out.print(“Hello ”);

}

public void methodC() {System.out.print(“World”);

}Lab 01-104

Control Structures

Page 105: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,

Questions?

Lab 01-105

Page 106: Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,