• Tidak ada hasil yang ditemukan

Index of /Prakt_PJK

N/A
N/A
Protected

Academic year: 2017

Membagikan "Index of /Prakt_PJK"

Copied!
45
0
0

Teks penuh

(1)

O

BJECT

O

RIENTED

O

BJECT

O

RIENTED

P

ROGRAMMING

Day 3 :

(2)

TOPIK

M b d k t i t d l l i b l

| Membedakan antara instance dan local variabel.

| Urutan pemrosesan

| Unary operator

| Unary operator

| Arithmetic operator

| Shift operator: <<, >>, dan >>>

| Comparison operator

| Bitwise operator: &, ^, dan |.

Sh t Ci it t

| Short – Circuit operator

| Conditional operator : ?

| Assignment operator

| Assignment operator

(3)
(4)
(5)
(6)
(7)

E

VALUATION

O

RDER

1 i t [] { 4 4 }

1. int [] a = { 4, 4 }; 2. int b = 1;

3. a[b] = b = 0; 3. a[b] b 0;

Note: untuk assignment berlaku

aturan asosiatif Γ† dari kanan ke

aturan asosiatif Γ† dari kanan ke

kiri.

1. a[b] Γ† a[1] 2. b = 0

(8)

T

HE

U

NARY

O

PERATORS

| Dibutuhkan hanya satu operan.

1. Operator increment dan decrement : ++ dan

-2. Operator unary plus dan minus : + dan –

3. Operator bitwise inversion : ~

4. Operator boolean complement : !

(9)
(10)

-T

HE

U

NARY

O

PERATORS

: +

DAN

-1. X = -3;

2 Y + 3; 2. Y = + 3;

(11)

T

HE

U

NARY

O

PERATORS

Th Bit i I i O t

| The Bitwise Inversion Operator: ~

y converting all the 1 bits in a binary value to 0s and all the 0 bits to 1s.

E l

Example:

00001111 Γ† 11110000

| The Boolean Complement Operator: !

| The Boolean Complement Operator: !

y inverts the value of a boolean expression.

Example:

Γ†

(12)
(13)

M

ENCARI NILAI BINER SUATU BILANGAN NEGATIF

| Tulis biner positifnya

| Kurangi dengan 1

| Kurangi dengan 1

(14)

M

ENCARI NILAI DESIMAL SUATU BILANGAN BINER NEGATIF

| Negasikan bilangan biner tersebut

(15)

T

HE

U

NARY

O

PERATORS

:

CAST

Γ†

(

TYPE

)

| Casting digunakan untuk melakukan konversi tipe secara eksplisit ke dalam type baru yang ada dalam tanda ()

dalam tanda ().

| Akan dilakukan pengecekan tipe terlebih dahulu.

| Contoh:

| Contoh:

(16)

T

HE

U

NARY

O

PERATORS

:

CAST

Γ†

(

TYPE

)

| Bisa diaplikasikan pada tipe obyek.

1. Vector v = new Vector();

2. v.add(β€œHello”);

(17)

T

HE

A

RITHMETIC

O

PERATORS

| The Multiplication and Division Operators: * and /p p

y multiply or divide two integers, the result will be

calculated using integer arithmetic in either int or long representation.

y Issues:

| Loses precision. int x = 7; int y = 4;

int result = x/ y;

| The result will be bigger than the maximum number

(overflow) (overflow)

byte x = 64; byte y = 4;

(18)

T

HE

M

ODULO

O

PERATOR

: %

| Adalah sisa pembagian

| Bisa diaplikasikan pada:

y Bilangan integer

y Bilangan floating - point

Example:

7 % 4 // 3

x = 7 % 4; //so x = 3

(19)

T

HE

A

DDITION AND

S

UBTRACTION

O

PERATORS

: +

AND

-| Digunakan untuk melakukan operasi penambahan dan pengurangan.

C t ti Γ† + Γ† bi j di k t k

(20)

A

RITHMETIC

E

RROR

C

ONDITIONS

| Integer division by zero ( ArithmeticException)

| Floating-point calculations represent l i th IEEE 754 i fi it i

range values using the IEEE 754 infinity, minus infinity, and Not a Number (NaN) values.

| Overflow

(21)

T

HE

S

HIFT

O

PERATORS

:

| Shift operator:p

y << : left shift

y >> : sign right shift

y >>> : unsigned right shift

y >>> : unsigned right shift

| Fundamentals of Shifting

y moving the bit pattern left or right.

li d f i l l

y applied to arguments of integral types only.

| Pada operator << dan >>>: Nilai bit yang baru adalah 0

| Pada operator >> : Nilai bit yang baru

tergantung pada bit yang akan digeser, jika nilainya :

nilainya :

y 1 Γ† negatif, maka nilai baru adalah 1

(22)
(23)
(24)
(25)
(26)

T

HE

C

OMPARISON

O

PERATORS

| Menghasilakn boolean result

| Menghasilakn boolean result.

| Yang termasuk comparison operator:

y Ordinal comparison: < <= > >=

y Ordinal comparison: <, <=, >, >=

y The instanceof Operator

Tests the class of an object at runtime. Tests the class of an object at runtime.

y The Equality Comparison Operators: == and !=

Test for equality and inequality, respectively, returning a b l l

(27)

O

RDINAL COMPARISON

i t 9

int p = 9; int q = 65; int r = 12; int r 12;

float f = 9.0f; char c = β€˜A’;

Berikut ini akan menghasilkan true: <

(28)

O

PERATOR INSTANCEOF

β€’

Operator instance of digunakan untuk mengecek

β€’

Operator instance of digunakan untuk mengecek

class suatu obyek.

(29)

O

PERATOR INSTANCEOF

β€’ Hasil:

Is b a Button? true

Is b a Component? true

β€’ Argumen sebelah kiri adalah object reference expression.

(30)

E

QUALITY OPERATORS

y Equality can be tested with the operators equals and not equals:

= = Γ† l

β—¦ = = Γ† equals

β—¦ != Γ† not equals

y There are four different types of entities that can

y There are four different types of entities that can be tested:

β—¦ Numbers

β—¦ Characters

β—¦ Boolean primitives

(31)

E

QUALITY FOR

P

RIMITIVES

class ComparePrimitives{

public static void main(String [] args) { System.out.println(β€˜a’ ==β€˜a’);

System.out.println(β€˜a’ ==β€˜b’); System.out.println(5 != 6);

System.out.println(5.0 == 5L); System.out.println(true==false); }

(32)

E

QUALITY FOR

R

EFERENCE

V

ARIABLES

import java.awt.Button; class CompareReference {

public static void main(String [] args) { Button a = new Button(β€œExit”);

Button b = new Button(β€œExit”); Button c = a;

System.out.println(a==b); System.out.println(a==c); }

(33)

T

HE

B

ITWISE

O

PERATORS

:

&

, ^,

AND

|

P id l i l AND OR d XOR ti

(34)
(35)
(36)
(37)
(38)

T

HE

S

HORT

-C

IRCUIT

L

OGICAL

O

PERATORS

O t && d ||

y Operators && and ||

y Applicable only to boolean values and not integral types.

y For an AND operation, if one operand is false, the result p , p , is false, without regard to the other operand.

y For an OR operation, if one operand is true, the result is true, without regard to the other operand., g p

|Jadi, untuk nilai boolean x:

y false && X = false

(39)
(40)
(41)
(42)
(43)

T

HE

C

ONDITIONAL

O

PERATOR

:

?:

| known as the ternary operator

| known as the ternary operator

| takes three operands

| code simple conditions (if/else) into a single

| code simple conditions (if/else) into a single expression.

| Example:

a = x ? b : c;

| Aturan:

y Tipe data b dan c harus sama dengan tipe data a

y Tipe data b dan c harus sama dengan tipe data a

y Tipe ekspresi x harus boolean

y Jika ekspresi x benar maka akan menghasilkan b

(44)
(45)

T

HE

A

SSIGNMENT

O

PERATORS

| set the value of a variable or expression to a new value.

E l

| Example:

1. byte x = 2;

2 3

2. x += 3;

Referensi

Garis besar

Dokumen terkait

An argument of SL is truth-functionally valid if and only if there is no truth-value assignment on which all the premises are true and the conclusion is

One needs to know if an insurance company goes broke what is the guaranteed cover per person per insurance company is available .One should not invest more than that in the fixed

Adapun nilai TRUE at au FALSE dapat diny at ak an dengan suat u nilai pada t ipe dat a lainny a.. Sedangk an nilai TRUE m erupak an nilai selain nilai FALSE at au 0 ( bisa posit

For example, if a binary operator has a floating-point operand, the computation is done using floating-point arithmetic and the result is a floating-point value.. The meaning and

ο‚· If only time data that differs from the work schedule is recorded for an employee, this is negative time management.  False 

𝛿π‘₯ = 𝛿– π‘₯, 𝛿π‘₯ behaves as if it were an even function true, false e.. ..., FT is Fourier transform

Tabel Confusion Matrix Predicted Class Positive Negative True Class Positive True Positive TP False Negative FN Negative False Positive FP True Negative TN RESULT AND DISCUSSION

β€’ Four interpretations of a screening drug test are possible: – a true-positive result occurs when the test correctly detects the presence of a drug – a false-positive result is one