Oopwithjava 1
Oopwithjava 1
Ajib Susanto
[email protected]
[email protected]
http://ajibsusanto.net
@ajibsusanto / 085876247118
1 ajib fik udinus
Materi Diskusi
1. Konsep Pemrograman dan Paradigmanya
Tingkat Bahasa Pemrograman, Paradigma Pemrograman,
Tool Pemrograman
2. Konsep Dasar Pemrograman Berorientasi Obyek:
Kelas (Class), Obyek (Object), Pengkapsulan
(Encapsulation), Pewarisan (Inheritance), Polymorphisme
3. Konsep Lanjut Pemrograman Berorientasi Obyek:
Constructor, Destructor, Overloading, Overriding, Keyword
This, Multithreading, Package, Interface, Exception
Compiler:
#include <stdio.h>
0001010000
1100101000
main() 0100010010
{ C Compiler 01010101010
printf(“Hallo”); 1010010
}
Java compiler
memproduksi Byte code
(.class)
Java
Virtual Hasilnya adalah Program
Machine Execution
Bentuk program:
1. GUI application public class biasanya
menggunakan JFrame
2. “Text based” Console Application public class
adalah class yang sederhana
16
GUI Version “Hello World!”
// HeloGUI.java
// Simple GUI Hello World Program
import javax.swing.*;
17
How Java Works? Jalankan dengan:
Kompiler memproduksi
Bytecode (Class)
Java bytecode
(HelloWorld.class)
C:\javac HelloWorldApp.java
/**
* The HelloWorld class implements an applet that
* simply displays "Hello World!".
*/
public class HelloWorld extends Applet {
public void paint(Graphics g) {
// Display "Hello World!"
g.drawString("Hello world!", 50, 25);
}
} C:\appletviewer Hello.html
<HTML>
<HEAD>
<TITLE>A Simple Program</TITLE>
C:\javac HelloWorld.java </HEAD>
<BODY>
Here is the output of my program:
<APPLET CODE="HelloWorld.class"
WIDTH=150 HEIGHT=25>
</APPLET>
</BODY>
</HTML>
Mendeklarasikan Variabel
Variabel : entitas penyimpanan data yang paling elementer
Variabel lebih mengacu ke alokasi memory daripada nilai data
Penamaan Variabel :
Contoh nama variabel yang valid :
@2var
_status
tanggal
jumlahBarang
nama_kecil
final_test
int_float
Methods The first letter should be lowercase, and then normal camelCase rules should be
used. In addition, the names should typically be verb-noun pairs. For example:
getBalance
doCalculation
setCustomerName
Aritmatika Unary
Operator ‘&’
31 30 29 28 27 7 6 5 4 3 2 1 0
0 0 00 0 00 00 1 10 0 = 12
31 30 29 28 27 7 6 5 4 3 2 1 0
1 1 11 1 11 11 0 01 1 = - 13
&
31 30 29 28 27 7 6 5 4 3 2 1 0
0 0 00 0 00 00 0 00 0 =0
Operator ‘~’
Contoh 1:
int c = 12 * 3 +5 / (8 - 3) ;
Urutan Operasinya :
int c = 12 * 3 + 5 / 5 ;
int c = 36 + 5 / 5;
int c = 36 + 1 ;
int c = 37;
Contoh 2:
int c = 3 + 4 >> 1 + 1 << 1;
Urutan Operasinya :
int c = 7 >> 1 + 1 << 1;
int c = 7 >> 2 << 1;
int c = 1 << 1;
int c = 2;
Promosi
proses pengubahan representasi bit variabel primitif dari representasi bit yang
lebih rendah ke representasi bit yang lebih tinggi
Promosi karena assigning tipe data dengan representasi bit
yang lebih tinggi ke yang lebih rendah
Contoh :
short a = 12;
int b = a ; // nilai a promosi ke integer
Promosi karena assigning tipe data integral ke tipe data
floating-point
Contoh :
int a = 30;
float b = a ;
Type-Casting
proses pengubahan representasi bit variabel primitif dari
representasi bit yang lebih tinggi ke representasi bit yang lebih
rendah.
Syntax :
identifier = (target_type) value ;
Contoh :
int num1 = 34;
int num2 = 45;
short num3 = (short)(num1 + num2 );
Keterangan : (num1 + num2) menghasilkan nilai integer. Agar nilainya
dapat di-assign ke num3, dilakukan casting dengan pernyataan :
(short) (num1+num2)
Contoh :
int num1;
long num2 = 123987654321L;
num1 = (int)(num2);
Dokumentasi Program
Java Fundamental – Oracle Academy
Sertifikat Java
Bamboomedia.net -> Java & Oracle