java basics part 1

15
S Java Basics Part 1

Upload: kevin-rowan

Post on 17-Feb-2017

138 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Java basics part 1

S

Java BasicsPart 1

Page 2: Java basics part 1

Structure of a Java Class

public class MyClass{

}

Class Definition

Page 3: Java basics part 1

Structure of a Java Class

public class MyClass{

}

Class names always start with an upper case letter

Page 4: Java basics part 1

Structure of a Java Class

public class MyClass{

}

The class begins with an open curly bracket and ends with a closed curly

bracket

Page 5: Java basics part 1

Structure of a Java Class

public class MyClass{

public void myMethod(){

}}

Method Signature

Page 6: Java basics part 1

Structure of a Java Class

public class MyClass{

public void myMethod(){

}}

Method names begin with a lower case letter. Other

words within the name are capitalized.

Page 7: Java basics part 1

Structure of a Java Class

public class MyClass{

public void myMethod(){

}}

The return type is the type of value the method

produces. If it doesn’t produce a value, the return

type is void.

Page 8: Java basics part 1

Structure of a Java Class

public class MyClass{

public void myMethod(){

}}

The method begins with an open curly bracket and ends with a closed curly

bracket

Page 9: Java basics part 1

Structure of a Java Class

public class MyClass{

public void act(){move(5);if( atWorldEdge() ) {turn(12);}}

}

All code inside a method goes between the

method’s curly brackets.

Page 10: Java basics part 1

Structure of a Java Method Call

move(5);

Call the method by using its name

Parameters are typed between the move’s round brackets

Complete Java statements end with a semi-colon.

Page 11: Java basics part 1

Structure of a Java Method Call

atWorldEdge()

Call the method by using its name

If the method does not require parameters, leave the

space between the round brackets empty.

Page 12: Java basics part 1

Structure of a Java Method Call

if( atWorldEdge() )

If the method has a return value, you must do

something with the return value, like use it in an if-

statement.

Page 13: Java basics part 1

Structure of an If-Structure

if( condition ) {true branch

}

Starts with the reserved word if

The condition is enclosed in round brackets.

The statements within the true branch are

enclosed within curly brackets.

The true branch is made up of any valid Java statements,

including other if-statements

Page 14: Java basics part 1

Structure of an If-Structure

if( condition ) {true branch

}

The condition is an expression that is either

true or false.It could be a call to a method that returns a boolean (true or false) value or an expression

that is either true or false (more on that later in the

course).

Page 15: Java basics part 1

Structure of an If-Structure

if( condition ) {true branch

} else {false branch

}

The statements within the true branch will be

executed only if the condition is true

The statements within the false branch will be

executed only if the condition is false