• Tidak ada hasil yang ditemukan

Index of /OOP

N/A
N/A
Protected

Academic year: 2017

Membagikan "Index of /OOP"

Copied!
43
0
0

Teks penuh

(1)

O

BJECT

O

RIENTED

D 2

O

BJECT

O

RIENTED

P

ROGRAMMING

Day 2 :

(2)

T

OPIK

:

M k k t di fil b

| Menggunakan komentar di file sumber.

| Membedakan antara valid dan invalid identifiers.

| Mengetahui Java technology keywords.g gy y

| Mengetahui 8 tipe data primitif.

| Mendefinisikan literal value untuk tipe data numerik dan

tekstual tekstual.

| Mendefinisikan primitive dan reference variable.

| Mendeklarasikan variabel bertipe class.p

| Membuat obyek dengan menggunakan operator new.

| Mengetahui nilai inisialisasi default.

St t t t d t i il i d i b l b ti

| State-state pada saat assign nilai pada variabel bertipe

class

(3)

S

OURCE

F

ILES

J fil d i h h

| Java source files must end with the .java

extension.

Th t l l l t k il ti

| Three top-level elements known as compilation

units may appear in a file. y Package Declaration

y Package Declaration

y Import Statements

(4)
(5)

C

LASS

F

UNDAMENTALS

:

MAIN METHOD

| The main() Method

public static void main(String[] args)

• Public : met hod main() dapat diakses oleh apa saj a, t ermasuk j ava t echnology int erpret er.

• St at ic : keyword ini berf ungsi unt uk memberi t ahu kompiler bahwa

t h d i bi l g g dig k d l t l g met hod main bisa langsung digunakan dalam cont ex class yang bersangkut an. Unt uk mengeksekusi/ menj alankan met hod yang bert ipe st at ic, t idak diperlukan inst ance nya.

• Void : menunj ukkan bahwa met hod main() t idak mengembalikan nilai • Void : menunj ukkan bahwa met hod main() t idak mengembalikan nilai • Main : merupakan nama met hod ut ama dari program j ava

• St ring [ ] args: Menyat akan bahwa met hod main() menerima single

paramet er yait u args yang bert ipe array. Digunakan pada saat memasukkan paramet er pada saat menj alankan program.

(6)
(7)
(8)
(9)

J

AVA

K

EYWORDS AND

R

ESERVED

W

ORDS

| are considered as reserved keywords

| may not be used as identifiers.

| None of the reserved words have a capital letters

| None of the reserved words have a capital letters

| 2 keyword that are reserved in Java but which are not used : const dan

goto

abstract do implements private this

boolean double import protected throw

break else instanceof public throws

byte extends int return transient

case false interface short true

catch final long static try

char finally native strictfp void

class float new super volatile

continue for null switch while

(10)
(11)
(12)
(13)

Public class TestDog{

public static void main(String args[]){ Dog d = new Dog();

d.setWeight(42);

System.out.println(“Dog d’s weight is “ + d.getWeight()); }

(14)

| Modifier : public, private, protected, dan default

| Constructor adalah bukan method, sehinggagg tidak punya return valuesp y dan

(15)

Note: Note:

• Jika kita mendeklarasikan constructor pada suatu class yang sebelumnya tidak mempunyai constructor,

k d f l l b k hil

maka default constructor class tersebut akan hilang.

(16)

I

DENTIFIERS

| Nama yang digunakan oleh programer untuk memberi nama

| Nama yang digunakan oleh programer untuk memberi nama

pada variable, class, atau method.

| Can start with a Unicode letter, underscore (_), or dollar sign ($)

| Are case-sensitive and have no maximum length

| Are case-sensitive and have no maximum length

| Examples:

1. foobar // legalg

2. BIGinterface // legal: embedded keywords

3. // are OK.

4. $incomeAfterExpenses // legal

5 3 d 5 // ill l t t ith

5. 3_node5 // illegal: starts with a digit

6. !theCase // illegal: must start with

(17)

P

RIMITIVE

T

YPES

| The Java programming language defines eight

primitive types: y Logical b l

y Logical - boolean

y Textual - char

y Integral -Integral bytebyte, , shortshort, , intint, and , and longlong

(18)
(19)

L

ITERALS

| is a value

(20)

L

OGICAL LITERALS

Th d t t h t lit l d

| The boolean data type has two literals, true and false.

| For example the statement: | For example, the statement:

1. boolean isBig = true;

2 b l i i l f l

2. boolean isLittle = false;

(21)

T

EXTUAL

L

ITERALS

6

| The range: 0 ~ 216 - 1.

| Java characters are in Unicode character (16-bit

(22)

CHAR LITERALS

| Expressed by enclosing the desired character in

single quotes (‘ ‘).

E l

| Example:

char c = ‘w’;

E U i d l ifi d i f

| Express as a Unicode value specified using four

hexadecimal digits, preceded by \u

E l

| Example:

(23)

CHAR LITERALS

y ‘\b’ for backspacep

y ‘\f’ for formfeed

y ‘\’’ for single quote

y ‘\”’ for double quote

(24)

STRING

LITERALS

| Is not a primitive data type; it is a class

| Represent sequences of characters

| Has its literal enclosed in double quotes (“ ”)

| Example:

String s = “Characters in strings are 16-bit Unicode.”;

(25)

INTEGRAL

LITERALS

Æ

BYTE

,

SHORT

,

INT

INTEGRAL

LITERALS

Æ

BYTE

,

SHORT

,

INT

AND LONG

E d i d i l t l h d i l

| Expressed in decimal, octal, or hexadecimal.

2 The decimal value is 2

077 The leading 0 indicates an octal value 0xBAAC The leading 0x indicates a

hexadecimal value

| Specify a long integer by putting an 'L' or 'l' after

the number.

y 'L' is preferred as it cannot be confused with the digit '1'.

y Example:

long x = 25L;g ;

(26)
(27)

FLOATING-POINT

LITERALS

Fl ti i t lit l i l d ith d i l

| Floating point literal includes either a decimal

point or one of the following:

y E or e (add exponential value)

y F or f (float)

y D or d (double)

3.14 Æ a simple floating point value (a double) p g p ( )

6.02E23 Æ a large floating point value

2.718F Æ a simple float size value

123.4E306D Æ a large double value

| Default is double

| Specify a float by putting an ‘F' or ‘f' after the

b

number.

y Example:

(28)

N

OTE

:

(29)
(30)
(31)
(32)
(33)
(34)
(35)
(36)
(37)
(38)

A

RGUMENT

P

ASSING

| The Java programming language only passes

arguments by value

Wh bj t i t i d

| When an object instance is passed as an

argument to a method, the value of the argument is a reference to the object

is a reference to the object

| The contents of the object can be changed in the

(39)

> java PassTest > java PassTest I nt value is: 11

(40)
(41)
(42)

G

ARBAGE

C

OLLECTION

All t d th t i l d d h ld b

| Allocated memory that is no longer needed should be

deallocated

| In other languages, deallocation is the programmer's

responsibility

| The Java programming language provides a system-level

thread to track memory allocation y

| Garbage collection:

y Checks for and frees memory no longer needed

y Is done automatically

y Is done automatically

y Can vary dramatically across JVM implementations

| “run the garbage collector.”

(43)

Referensi

Garis besar

Dokumen terkait

mengalami kerusakan atau mempunyai perubahan-peruabahan kimiawi sehingga tidak dapat dipergunakan, maka kerugian perusahaan akan menjadi semakin besar dengan semakin besarnya

However, 7 days feeding of CS at both dosages didn’t have any effect on the weights of testis, seminal vesicle and prostate gland compared to control in immature mice (p >

Pasar Modern Thamrin Plaza memberikan dampak negatif (perubahan penurunan) terhadap omzet penjualan, keuntungan, jumlah pegawai dan penjualan fisik pedagang pasar tradisional Pasar

Menunjang program kesehatan lainnya dalam usaha pencegahan penyakit, peningkatan dan pemulihan kesehatan, individu dan keluarga. Kesehatan Usia Lanjut, kegiatan yang dilakukan

Apabila Indonesia tidak memiliki daya tawar yang tinggi dari aspek kekuatan militer khususnya Angkatan Laut, muncul peluang akan terulangnya kembali tindakan-tindakan pelecehan dan

[r]

Konsep yang akan diusulkan dalam perencanaan pengembangan tata hijau dikawasan ini adalah menjadikan kawasan ini menjadi lahan konservasi yang memiliki peran

Penelitian ini bertujuan untuk mengembangkan silabus ESP (Bahasa Inggris untuk Keperluan Khusus) untuk mahasiswa keperawatan STIKES Al-Irsyad Cilacap. Analisis kebutuhan dilakukan