0% found this document useful (0 votes)
50 views28 pages

Tugas Besar Dokumentasi Dan Program: Fakultas Ilmu Komputer

This document contains source code and documentation for a Java programming assignment. It includes 19 sections covering topics like "Hello World", data types, operators, selection/branching, loops, functions, arrays, exceptions, overriding/overloading, interfaces/abstract classes, generics, stacks, sockets, applets, Swing, and JDBC. For each topic there is source code with comments, output examples, and brief explanatory information. The document appears to be serving as an example portfolio for a university-level Java programming course project.

Uploaded by

Ryan Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views28 pages

Tugas Besar Dokumentasi Dan Program: Fakultas Ilmu Komputer

This document contains source code and documentation for a Java programming assignment. It includes 19 sections covering topics like "Hello World", data types, operators, selection/branching, loops, functions, arrays, exceptions, overriding/overloading, interfaces/abstract classes, generics, stacks, sockets, applets, Swing, and JDBC. For each topic there is source code with comments, output examples, and brief explanatory information. The document appears to be serving as an example portfolio for a university-level Java programming course project.

Uploaded by

Ryan Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 28

TUGAS BESAR

DOKUMENTASI DAN PROGRAM


PEMROGRAMAN JAVA LANJUT

Disusun oleh :
[13020130103] [RYAN FADEL AHMAD]

PROGRAM STUDI TEKNIK


INFORMATIKA
FAKULTAS ILMU KOMPUTER
UNIVERSITAS MUSLIM
INDONESIA
1

2015

DAFTAR ISI

Isi (Inti Pembahasan)


1. Hello World

Source Code
package HelloWorld;
/**
*
* @author Ryan FA
*/
public class Hel {
public static void main(String[] args){
System.out.println("Hello World...!" + "\nI'm Ryan (13020130103)");
}
}

Result
Hello World...!
I'm Ryan (13020130103)

Information
method println() digunakan untuk menampilkan text

2. Tipe Data dan Variabel


Source Code

package TipeData_Variabel;
/**
*
* @author Ryan FA
*/
public class Huh {
public static void main (String[]args){
String nama = "Ryan";
System.out.println("Nama: "+nama);
}
}

Result
Nama: Ryan

Information

3. Konstanta dan Static


Source Code

package Konstanta_Static;
/**
*
* @author Ryan FA
*/
public class Heh {
public static double ipk;
public static final String NAMA_MHS = "Ryan Fadel Ahmad";
public static void main(String[] args){
ipk = 3.75;
System.out.println("Mahasiswa bernama "+NAMA_MHS+" ");
System.out.println("mempunyai IPK "+ipk);
}
}

Result
Mahasiswa bernama Ryan Fadel Ahmad
mempunyai IPK 3.75

Information

4. Operator: relational, aritmatik, logika


Source Code

package Operator;
import java.util.Scanner;
/**
*
* @author Ryan FA
*/
public class Hai {
public static void main (String[]args){
Scanner input = new Scanner(System.in);
System.out.print("Masukkan nilai: ");
int masuk = input.nextInt();
if (masuk<100 && masuk>70){
System.out.println("GOL");
}else if (masuk<=70){
System.out.println("NDA GOL");
}else
System.out.println("AW");
}
}

Result
Masukkan nilai: 80
GOL

Information

5. Seleksi/Percabangan
Source Code

package Percabangan;
/**
*
* @author Ryan FA
*/
public class Hui {
public static void main(String[] args){
int anInt = 0;
if (anInt==0)
System.out.println("Variabel anInt bernilai nol");
else
System.out.println("Variabel anInt tidak bernilai nol");
}
}

Result
Variabel anInt bernilai nol

Information

6. Perulangan
Source Code

package Perulangan;
/**
*
* @author Ryan FA
*/
public class Hoi {
public static void main (String[]args){
int a = 1;
do{
System.out.print(a);
a++;
}while(a<=9);
}
}

Result
123456789

Information

7. Fungsi dan Rekursif


Source Code

package Fungsi_Rekursif;
import java.util.Scanner;
/**
*
* @author Ryan FA
*/
public class Hoe {
public static void main (String[]args){
Scanner input = new Scanner(System.in);
System.out.print("Enter an index for a Fibonacci number: ");
int index = input.nextInt();
System.out.println("The Fibonacci number at index "+index+" is
"+fib(index));
}
public static long fib(long index){
if (index==0)
return 0;
else if (index==1)
return 1;
else
return fib(index-1)+fib(index-2);
}
}

Result
Enter an index for a Fibonacci number: 2
The Fibonacci number at index 2 is 1

Information

8. Array
Source Code

10

package Array;
/**
*
* @author Ryan FA
*/
public class Heo {
public static void main (String[]args){
int [] deret = new int [5];
deret[0] = 99;
deret[1] = 49;
deret[2] = 12;
deret[3] = 7;
deret[4] = 69;
System.out.println("Deret ke 3 bernilai: "+deret[2]);
}
}

Result
Deret ke 3 bernilai: 12

Information

9. Stream I/O
Source Code

11

package StreamIO;
import java.io.*;
/**
*
* @author Ryan FA
*/
public class Hail {
/**
* @param args
*/
public static void main(String[] args) {
BufferedReader data;
PrintWriter hasil;

double[] angka = new double[1000];


int banyakAngka;
try {
data = new BufferedReader(new FileReader("data.dat"));
}
catch (FileNotFoundException e) {
System.out.println("Tidak bisa menemukan data.dat!");
return;
}
try {
hasil = new PrintWriter(new FileWriter("hasil.dat"));
}
catch (IOException e) {
System.out.println("Tidak bisa membuka hasil.dat!");
System.out.println(e.toString());

12

try {
data.close();
}
catch (IOException f) {
System.out.println("Tidak bisa menutup data.dat");
}
return;
}
String baris = null;
try {
banyakAngka = 0;
while ((baris = data.readLine()) != null) {
angka[banyakAngka] = Double.parseDouble(baris);
banyakAngka++;
}
for (int i = banyakAngka-1; i >= 0; i--)
hasil.println(angka[i]);
System.out.println("Selesai!");
}
catch (IOException e) {
System.out.println("Kesalahan baca/tulis");
}
catch (NumberFormatException e) {
System.out.println("Kesalahan format: " + e.getMessage());
}
catch (IndexOutOfBoundsException e) {
System.out.println("Terlalu banyak angka.");
System.out.println("Penulisan dihentikan.");
}
finally {
try {
data.close();

13

}
catch (IOException e) {
System.out.println("Tidak bisa menutup data.dat");
}
hasil.close();
}
}
}

Result
Tidak bisa menemukan data.dat!

Information

10.

Exception

Source Code

14

package Exception;
/**
*
* @author Ryan FA
*/
public class TesException {
public static void main (String[]args){
try{
System.out.println(args[1]);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Exception Caught");
}
}
}

Result
Exception Caught

Information

11.

Overriding dan Overloading

Source Code
//Load.java
package Overriding_Overloading;

15

/**
*
* @author Ryan FA
*/
public class Load{
public void tambah1(){
int a=5, b=10;
System.out.println("Hasil Pertambahann dari metod tambah1 ke-1 =
"+(a+b));
}
public void tambah1(int x, int y){
System.out.println("Hasil Pertambahann dari metod tambah1 ke-2 = "+
(x+y));
}
public void Sapa(){
System.out.println("Ryan Fadel Ahmad");
}
}
//Ride.java
package Overriding_Overloading;
/**
*
* @author Ryan FA
*/
public class Ride extends Load{
@Override
public void Sapa(){
System.out.println("Amani Nurul Khusna");
}
}
//main.java

16

package Overriding_Overloading;
/**
*
* @author Ryan FA
*/
public class Main {
public static void main(String [] args){
Load pp;
pp = new Load();
pp.tambah1();
pp.tambah1(5,5);
Load ss;
Ride nn;
ss = new Load();
nn = new Ride();
ss.Sapa();
nn.Sapa();
}
}

Result
Hasil Pertambahann dari metod tambah1 ke-1 = 15
Hasil Pertambahann dari metod tambah1 ke-2 = 10
Ryan Fadel Ahmad
Amani Nurul Khusna

Information

17

12.

Interface dan Abstract Class

Source Code
package Interface_Abstrak;
/**
*
* @author Ryan FA
*/
interface Bahan {
String perunggu = "perunggu";
String emas = "emas";
String marmer = "marmer";
String perak = "perak";
String kayu = "kayu";
}
abstract class BahanObject {
String bahan;
}
class BahanObjects {
public static void main(String args[]) {
Bola bola = new Bola(Bahan.kayu);
Koin koin = new Koin(Bahan.perak);
Cincin cincin = new Cincin(Bahan.emas);

18

System.out.println(bola.bahan);
System.out.println(koin.bahan);
System.out.println(cincin.bahan);
}
}
class Bola extends BahanObject {
Bola(String bahan) {
this.bahan = bahan;
}
}
class Koin extends BahanObject {
Koin(String bahan) {
this.bahan = bahan;
}
}
class Cincin extends BahanObject{
Cincin(String bahan) {
this.bahan=bahan;
}
}

Result
kayu
perak
emas

Information

19

13.

Java Generic

Source Code
package JavaGeneric;
/**
*
* @author Ryan FA
*/
import java.util.*;
public class Generic{
public static void main(String args[]){
ArrayList<String> list=new ArrayList<String>();
list.add("rahul");

20

list.add("jai");
String s=list.get(1);//type casting is not required
System.out.println("element is: "+s);
Iterator<String> itr=list.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
}

Result
element is: jai
rahul
jai

Information

14.

Multithread dan Sinkronisasi

Source Code

Result
Information

21

15.

Struktur Data: Stack

Source Code
package Stack;
import java.util.Scanner;
import java.util.Stack;
/**
*
* @author Ryan FA
*/
public class NewClass {
static Stack zen = new Stack();
static Scanner in = new Scanner(System.in);

22

static String a;
static String arr;
static int max_st;
static int i=0;
static int top =-1;
static void pushh(Stack zen, String a){
zen.push((a).toString());
System.out.println("Stack: " + zen);
}
public int find(){
return (int) (top=top+1);
}

static void popp(Stack zen, String a ){


a = (String) zen.pop();
System.out.println("stack: " + zen);
}
public static void main(String[] args) {
System.out.print("Masukkan Max_Stack : ");
max_st=in.nextInt();
for (int i = 0; i < max_st; i++) {
System.out.print("PUSH -> ");
a=in.next();
pushh(zen, a);
}
System.out.println("POP = y / anykeys=stop");
while(!a.equals("n")){
System.out.print("POP ->

");

a=in.next();
if (a.equals("y") && !zen.isEmpty()) {
popp(zen, a);
}else{
System.out.println("apa stack kosong?

"+zen.isEmpty());

break;

23

}
System.out.println("apa stack kosong?

"+zen.isEmpty());

if (zen.isEmpty()) {
System.out.println("stop");
break;
}
}
}
}

Result
Masukkan Max_Stack : 4
PUSH -> 1
Stack: [1]
PUSH -> 2
Stack: [1, 2]
PUSH -> 3
Stack: [1, 2, 3]
PUSH -> 4
Stack: [1, 2, 3, 4]
POP = y / anykeys=stop
POP ->

stack: [1, 2, 3]
apa stack kosong?
POP ->

false

stack: [1, 2]
apa stack kosong?
POP ->

false

stack: [1]
apa stack kosong?
POP ->

false

stack: []
apa stack kosong?

true

stop

Information

24

16.

Java Socket

Source Code

Result
Information

25

17.

Java Applet

Source Code

Result
Information

26

18.

Java Swing

Source Code

Result
Information

27

19.

JDBC

Source Code

Result
Information

28

You might also like