Object Oriented Programmingandiwre.itmaranatha.org/download/pbojava/01 Pengenalan Java dan...
Transcript of Object Oriented Programmingandiwre.itmaranatha.org/download/pbojava/01 Pengenalan Java dan...
Object Oriented Programming
Week 1
• Rules, contact, reference
• Java dan OOP
Dr. Andi Wahju R.E, MSSE © 2013
Contact me
• Name: Dr. Andi Wahju R.E, BSEE, MSSE
• E-mail: [email protected]
• fb: www.facebook.com/andi.emanuel• fb: www.facebook.com/andi.emanuel
• Website: http://andiwre.itmaranatha.org
Manfaat Mata Kuliah
• Mahasiswa dapat mempelajari konsep pemrograman berorientasi objek (objectoriented) yang berbeda dari konsep oriented) yang berbeda dari konsep pemrograman prosedural dan dapat diaplikasikan dalam kasus real
Target Mata Kuliah
• Mahasiswa memiliki kemampuan pemrograman berorientasi objek untuk menganalisa dan memecahkan kasusmemecahkan kasus
Buku referensi
• Deitel, P., & Deitel, H. (2011). Java How To Program (9th ed.). Prentice Hall.• Horstmann, C. S., & Cornell, G. (2008). Core Java Fundamentals (8th ed., Vol. I). California: Prentice Fundamentals (8th ed., Vol. I). California: Prentice Hall.• McLaughlin, B. D., Pollice, G., & West, D. (2007). Head First Object Oriented Analysis and Design.California: O'Reilly.• O'Docherty, M. (2005). Object-Oriented Analysis and Design Understanding System Development with UML 2.0.West Sussex: John Wiley & Sons, Ltd.
Kriteria Penilaian
Praktikum12%
Bobot Penilaian
UTS30%
UAS30%
Responsi12%
Tugas Besar16%
Other28%
Tugas Besar
• Kelompok 3 – 4 orang (tentukan ketua)
• Cari sebuah kasus dalam dunia nyata (masing-masing kelompok harus berbeda)masing kelompok harus berbeda)
• Analisa kasus tersebut dengan pendekatan berorientasi objek
• Buatlah progres kerja setiap minggu dan laporkan
• Dipresentasikan di akhir perkuliahan sebelum UAS
Tugas Besar cont.
• Dokumen
▫ Ukuran kertas A4 dengan:
� Margin kiri: 4 cm� Margin kiri: 4 cm
� Margin atas, kanan, bawah: 3 cm
▫ Judul bab: Calibri 14 pt center
▫ Font laporan: Calibri 11 pt
▫ Judul sub bab: Cambria 11 pt
▫ Caption gambar / tabel: Calibri 9 pt center
Tugas Besar cont.
• Dokumen
▫ Penomoran halaman
� Halaman dengan judul bab: tengah bawah� Halaman dengan judul bab: tengah bawah
� Halaman lainnya: kanan atas
▫ Daftar isi: nomor halaman = angka romawi (i, ii, dst)
Tools
• Jdk7u6 (Java development kit)
• Notepad++, EditPlus
Aturan Perkuliahan
• Kehadiran > 75%• Keterlambatan max 15 menit (jika lebih tidak diizinkan masuk) � jam esiadiizinkan masuk) � jam esia• Gunakan pakaian rapi & sepatu• Seluruh HP / alat komunikasi▫ Silent▫ Tidak diletakkan di meja / di atas PC / di laci keyboard
• Dilarang makan / minum• Dilarang main game
Materi Perkuliahan
Minggu Materi
1 Pengenalan Java dan OOP
2 Percabangan dan pengulangan
3 Encapsulation, Overloading3 Encapsulation, Overloading
4 Array of Object
5 Inheritance
6 Polymorphism
7 (TBA)
UTS
Materi Perkuliahan cont.
Minggu Materi
8 Advanced class
9 Abstract class
10 Interface10 Interface
11 Exception
12 Package, Packaging & (Java Swing)*
13 Presentasi tugas besar
14 Review
UAS
Java Release
• Sun Microsystem � Oracle
▫ Java 2 Standard Edition (J2SE) � JSE
▫ Java 2 Enterprise Edition (J2EE) � JEE▫ Java 2 Enterprise Edition (J2EE) � JEE
▫ Java 2 Micro Edition (J2ME) � JME
Java Certification Path
• Oracle Certified Associate
• Oracle Certified Proffesional
• Oracle Certified Master• Oracle Certified Master
HelloWorld
Object Oriented
• Objek
▫ Seluruh benda di sekitar Anda
▫ Benda memiliki state dan behaviour▫ Benda memiliki state dan behaviour
� Dogs: state (name, color, breed) dan behaviour(barking, wagging tail)
� Sepeda: state (current gear, current speed) dan behaviour (changing gear, applying brakes)
▫ Mengidentifikasi state dan behaviour adalah langkah awal dan terbaik dalam cara berpikir OO
Object Oriented cont.
• Objek software
▫ Memiliki konsep yang sama dengan objek di dunia nyatanyata
▫ Menyimpan state pada fields / variable
▫ Menggunakan method / function untuk mengekspresikan behaviour
▫ Method akan beroperasi pada state dan merupakan mekanisme utama dalam komunikasi antar objek
Object Oriented cont.
Object Oriented cont.
• Dalam dunia nyata � banyak objek yang sama
▫ Cnth: terdapat jutaan sepeda yang masing-masing sepeda dibuat dari blueprint yang samasepeda dibuat dari blueprint yang sama
• Dalam OO, sepeda yang dimiliki merupakan instance dari class bernama Bicycle
Object Oriented cont.
Object Oriented cont.
Konsep OO
1. Enkapsulasi
2. Inheritance (pewarisan)
3. Polymorphism3. Polymorphism
Enkapsulasi
• Pembungkusan atribut dan method
▫ public
▫ protected▫ protected
▫ private
▫ default access modifier
Inheritance
• Pewarisan atribut dan method dari sebuah classke class lainnya
• Keywords: extends• Keywords: extends
Polymorphism
• Kemampuan sebuah objek untuk memiliki lebih dari satu bentuk
Java Programming Rules
• Class name = File name
▫ HelloWorld �HelloWorld.java
• Case sensitive• Case sensitive
• Class name tidak diawali angka dan tidak terdapat –
• Akhir baris perintah � gunakan semicolon (;)
Java Naming Rules
Type Rules Example
Class Nama class harus merupakan kata benda. Jika nama class terdiri dari dua kata atau lebih, maka setiap huruf dari kata tersebut akan menjadi huruf besar
class Personclass ImageSprite
tersebut akan menjadi huruf besar
Interface Sama seperti class interface Storing
Method Penamaan method menggunakan kata kerja. Jika terdiri dari dua kata atau lebih, gunakan camelCase
run()getPersonName()getBackground()
Java Naming Rules cont.
Type Rules Example
Variable Cara penamaan untuk variable menggunakan camelCase. Gunakan nama yang pendek namun mencerminkan arti / kegunaan.
int myAgedouble personHeight
mencerminkan arti / kegunaan.
Constant Penamaan konstanta seluruhnya menggunakan huruf besar dan jika terdiri dari dua atau lebih kata, dipisahkan menggunakan _
int MIN_WIDTH = 4
Java Primitive Data Type
Type Bits Bytes
Minimum Range Maximum Range
byte 8 1 -128 or -27 127 or 27-1
short 16 2 -32,768 or -215 32,767 or 215-1short 16 2 -32,768 or -215 32,767 or 215-1
int 32 4 -2,147,483,648 or -231 2,147,483,647 or 231-1
long 64 8 -263 263-1
float 32 4 -3.4E38 3.4E38
double 64 8 -1.7E308 1.7E308
char 16 2 n/a n/a
boolean 8 1 n/a n/a
String Data Type
• Not primitive � data reference
• Berisi karakter angka, numeric, karakter khusus
• Menggabungkan string � gunakan +• Menggabungkan string � gunakan +
Arithmetic Operator
Operator Name Description
+ Addition Add two operands
- Substraction Subtract the right operand from the left
* Multiplication Multiplies the right operand and left operand* Multiplication Multiplies the right operand and left operand
/ Division Divides the right operand into the left operand
Arithmetic Operator cont.
Operator Name Description
% Modulus Returns the value that is left over after dividing the right operand into the left operand
++ Increment Adds 1 to the operand (x = x + 1)++ Increment Adds 1 to the operand (x = x + 1)
-- Decrement Subtract 1 from the operand (x = x – 1)
- Negative sign Change a positive value to negatif and vice versa
Assignment Operator
Operator Name Description
= Assignment Assign a new value to the variable
+= Addition Adds the operand to the starting variable value of the variable and assigns the result to the of the variable and assigns the result to the variable
-= Substraction Substracts the operand from the starting value of the variable and assigns the result to the variable
Assignment Operator cont.
Operator Name Description
*= Multiplication Multiplies the operand by the starting value of the variable and assigns the result to the variable
/= Division Divides the operand by the starting value of the /= Division Divides the operand by the starting value of the variable and assigns the result to the variable
%= Modulus Derives the value that is left over after dividing the right operand by the value in the variable, and then assigns this value to the variable
Boolean Expression
Operator Name Description
== Equality Returns a true value if both operands are equal
!= Inequality Returns a true value if the left and right operands are not equaloperands are not equal
> Greater than Returns a true value if the left operand is greater than the right operand
Boolean Expression cont.
Operator Name Description
>= Greater than or equal
Returns a true if the left operand is greater than or equal to the right operand
< Less than Returns a true value if the left operand is less < Less than Returns a true value if the left operand is less than the right operand
<= Less than or equal Returns a true value if the left operand is less or equal to than the right operand
Question