java basics part 1
TRANSCRIPT
S
Java BasicsPart 1
Structure of a Java Class
public class MyClass{
}
Class Definition
Structure of a Java Class
public class MyClass{
}
Class names always start with an upper case letter
Structure of a Java Class
public class MyClass{
}
The class begins with an open curly bracket and ends with a closed curly
bracket
Structure of a Java Class
public class MyClass{
public void myMethod(){
}}
Method Signature
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.
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.
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
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.
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.
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.
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.
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
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).
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