Java basics part 1
-
Upload
kevin-rowan -
Category
Education
-
view
135 -
download
1
Transcript of Java basics part 1
![Page 1: Java basics part 1](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/1.jpg)
S
Java BasicsPart 1
![Page 2: Java basics part 1](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/2.jpg)
Structure of a Java Class
public class MyClass{
}
Class Definition
![Page 3: Java basics part 1](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/3.jpg)
Structure of a Java Class
public class MyClass{
}
Class names always start with an upper case letter
![Page 4: Java basics part 1](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/4.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/5.jpg)
Structure of a Java Class
public class MyClass{
public void myMethod(){
}}
Method Signature
![Page 6: Java basics part 1](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/6.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/7.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/8.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/9.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/10.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/11.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/12.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/13.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/14.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062412/58a664391a28ab1c5b8b6b43/html5/thumbnails/15.jpg)
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