01. pengenalan java

13
PEMROGRAMAN FRAMEWORK J2EE PERTEMUAN I PENGENALAN JAVA (I)

Upload: dias-teddo-w

Post on 05-Feb-2016

35 views

Category:

Documents


4 download

DESCRIPTION

01. Pengenalan Java

TRANSCRIPT

Page 1: 01. Pengenalan Java

PEMROGRAMAN FRAMEWORK J2EE

PERTEMUAN IPENGENALAN JAVA (I)

Page 2: 01. Pengenalan Java

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

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

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

Hello World !

/* Program HelloWorld.java */

class HelloWorld { public static void main (String args[]) {

System.out.println("Hello World!"); }

}

Page 6: 01. Pengenalan Java

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

Looping dan Branching

Looping : for, while, do while Branching : switch-case, if-else

Page 8: 01. Pengenalan Java

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

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

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

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

Contoh Program

Fibonacci Sieve of Erastothenes

Page 13: 01. Pengenalan Java

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.