01. pengenalan java
DESCRIPTION
01. Pengenalan JavaTRANSCRIPT
![Page 1: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/1.jpg)
PEMROGRAMAN FRAMEWORK J2EE
PERTEMUAN IPENGENALAN JAVA (I)
![Page 2: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/2.jpg)
Outline
Introduction “Hello world !” Compiling & Running Program Looping dan Branching Variabel dan Tipe Data Operator dan Pemberian Nilai Methods / functions Contoh program
![Page 3: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/3.jpg)
Introduction
Java adalah salah satu bahasa pemrograman tingkat tinggi
Java digunakan dalam banyak aplikasi termasuk games dan embedded system.
Java mirip sekali dengan C/C++. Java dapat diimplementasikan pada
desktop dan web (berupa applet).
![Page 4: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/4.jpg)
Introduction
Java : code once, run anywhere. (platform independent).
Java mendukung penuh konsep OOP. Lebih sederhana daripada C++ : tidak ada
pointer Multithreading Fitur Garbage Collector.
![Page 5: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/5.jpg)
Hello World !
/* Program HelloWorld.java */
class HelloWorld { public static void main (String args[]) {
System.out.println("Hello World!"); }
}
![Page 6: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/6.jpg)
Compiling & Running Program CLASSPATH adalah environment variable yang
merujuk dimana library Java disimpan dalam sistem.
CLASSPATH digunakan dalam compiling dan running program Java.
Set CLASSPATH di Windows
CompilingC:> javac HelloWorld.java
C:> java HelloWorld
Hello World
C:>
C:\> SET CLASSPATH=C:\JDK\JAVA\CLASSES;c:\java\lib\classes.zip
![Page 7: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/7.jpg)
Looping dan Branching
Looping : for, while, do while Branching : switch-case, if-else
![Page 8: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/8.jpg)
Variabel dan tipe data
Variabel di Java bersifat case-sensitive (sama seperti C/C++)
Tipe data : Primitif : byte, short, int, long, float, double,
boolean, char Non-primitif/reference type : all instance of
objects Collection : Array, ArrayList, Dictionary, etc. Enum type. Etc.
![Page 9: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/9.jpg)
Operator dan Pemberian Nilai Operator dan Pemberian Nilai pada Java
sama dengan C/C++ Untuk variabel berupa object, harus
diinisialisasi terlebih dahulu menggunakan keyword new.
![Page 10: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/10.jpg)
Methods
Komponen-komponen methods di Java secara umum Modifiers : public, private Return type Method name Parameter list Exception Method body
Contohpublic double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons) {
//do the calculation here
}
![Page 11: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/11.jpg)
Methods/ Functions
Overloading Overloading memungkinkan kita
mendefinisikan sebuah methods dengan banyak jenis input.
Contohpublic class DataArtist {
...
public void draw(String s) { ... }
public void draw(int i) { ... }
public void draw(double f) { ... }
public void draw(int i, double f) { ... }
}
![Page 12: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/12.jpg)
Contoh Program
Fibonacci Sieve of Erastothenes
![Page 13: 01. Pengenalan Java](https://reader033.vdocuments.pub/reader033/viewer/2022061614/55cf85e0550346484b92529d/html5/thumbnails/13.jpg)
Tugas I
Imagine you need to open a standard combination dial lock but don't know the combination and don't have a pair of bolt cutters. Write a program that prints all possible combinations so you can print them on a piece of paper and check off each one as you try it. Assume the numbers on the dial range from zero to thirty-six and three numbers in sequence are needed to open the lock.
Suppose the lock isn't a very good one and any number that's no more than two away from the correct number in each digit will also work. In other words if the combination is 17-6-32, then 18-5-31, 19-4-32, 15-8-33 and many other combinations will also open the lock. Write a program that prints out a minimal list of combinations you would need to try to guarantee opening the lock.