Professional Documents
Culture Documents
Basic Java Dan ADT
Basic Java Dan ADT
Basic Java Dan ADT
and Algorithms
V1.0
Outline
Members of a class
in Java:
Class in Java
Instance
Method
variable
Class and Objects Example
An web application with some of web robot.
object object
- name:
- color:
+ sayHello( )
+ introduceSelf( )
WebRobot
Contoh Lain Pendefinisian Class
For accessing the methods and instance variable are performed with the dot (“.”)
operator
Reference Illustration
Modifiers
Access • Public
Control • Protected
• Private
Modifier
• Static
Other
• Abstract
Modifiers • Final
Constructors
Boolen
int length() String concat()
equals(Object)
static String
char charAt(int String
copyValueOf(char[]
index) toLowerCase()
data)
String
String trim()
toUpperCase()
Review Materi AlPro
int snowLevel = 3;
Switch Statements
Loop
while loop condition is true. It tests the condition before executing the
loop body.
for loop
• Execute a sequence of statements multiple times and
abbreviates the code that manages the loop variable.
do..while loop
• Like a ‘while’ statement, except that it tests the condition at
the end of the loop body.
For-Each
• This is mainly used to traverse collection of elements
including arrays.
For-Each Syntax
Loop Control Statements
METHODS
Creating Method
Method is a collection of statements that are grouped
together to perform an operation.
Syntax:
Other syntax:
Method Example
Method Calling
For using a method, it should be called. There are two
ways in which a method is called i.e., method returns a
value or returning nothing (no return value).
ARRAY
Array
Achieve by:
– Threat function as black box
– Give specification of its purpose
input output
Black box
Restricting visibilities
Information of implementation
details to where
Hiding needed
Parts of ADT
Declaration of Declaration of
data (values) operations
Primitive Data Type
+ *
integer
- /
~ boolean
||
&&
Primitive ADT
• Types of Operation
– Constructor: object creator
int x[ ] = {1,2,3,4}
– Mutator: object updater
x[3] = 10
– Accessor: object querier
int y = … x[3] …
– Destroyer:object terminator
garbage colector
ADT Example
real
add(c)
Complex(r,i)
complex
minus(c)
times(c)
Imajiner
Complex number
ADT Example
Class Complex {
private … constructor
TERIMA KASIH
References
• https://www.tutorialåspoint.com/java/index.htm