1 / 30

JAVA APPLET

JAVA APPLET. Creating Web Application using Java Applet. Introduction to Java (2 nd part). Tipe Data Pada Java. Tipe Data Pada Java. Contoh. Tata Cara Penulisan. Penulisan variabel (wajib) : Serangkaian Unicode karakter yang diawali dengan huruf.

Download Presentation

JAVA APPLET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA APPLET Creating Web Application using Java Applet Introduction to Java (2nd part)

  2. Tipe Data Pada Java

  3. Tipe Data Pada Java

  4. Contoh

  5. Tata Cara Penulisan Penulisan variabel (wajib) : • Serangkaian Unicode karakter yang diawali dengan huruf. • Bukan keyword Java, boolean true/false, & null. • Harus unique dalam sebuah scope. Boleh sama jika memiliki scope yang berbeda.

  6. Konvensi Penulisan Konvensi penulisan untuk method dan field (tidak wajib tapi direkomendasikan) : • Nama variabel diawali huruf kecil, dan nama class diawali huruf kapital. • Nama method  klausa kerja dan ditulis dengan diawali oleh huruf kecil untuk kata pertama dan huruf besar untuk setiap huruf pertama dari kata-kata berikutnya, jika ada. Contoh : hitungLuas(), hitungKell(), selesai(). • Field static ditulis dengan menggunakan huruf kapital semua. Contoh : MAX_PANJANG, LEBAR, PHI • Field biasa tidak dibuat public melainkan diakses dan diubah dengan melalui pemanggilan method method.

  7. Contoh public class MaxVariablesDemo { public static void main(String args[]) { //integers byte largestByte = Byte.MAX_VALUE; short largestShort = Short.MAX_VALUE; int largestInteger = Integer.MAX_VALUE; long largestLong = Long.MAX_VALUE; //real numbers float largestFloat = Float.MAX_VALUE; double largestDouble = Double.MAX_VALUE; //other primitive types char aChar = 'S'; boolean aBoolean = true;

  8. System.out.println(“max byte = " + largestByte); System.out.println(“max short = " + largestShort); System.out.println(“max integer = " + largestInteger); System.out.println(“max long = " + largestLong); System.out.println(“max float = " + largestFloat); System.out.println(“max double = " + largestDouble); if (Character.isUpperCase(aChar)) { System.out.println("The character " + aChar + " is uppercase."); } else { System.out.println("The character " + aChar + " is lowercase."); } System.out.println("The value of aBoolean is " + aBoolean); } }

  9. Operator

  10. Operator

  11. Operator

  12. Operator

  13. Operator

  14. Operator

  15. Assignment Operator

  16. Additional

  17. Additional

  18. ARRAY public class ArrayDemo { public static void main(String[] args) { int[] anArray; anArray = new int[10]; for (int i = 0; i < anArray.length; i++) { anArray[i] = i; System.out.print(anArray[i] + " "); } } }

  19. ARRAY public class ArrayOfStringsDemo { public static void main(String[] args) { String[] anArray = { "String One", "String Two", "String Three" }; for (int i = 0; i < anArray.length; i++) { System.out.println(anArray[i].toLowerCase()); } } }

  20. Statement Conditional dan Looping

  21. do…while & while…do do…while syntax do { statement(s) } while (expression); while…do syntax : while (expression) { statement }

  22. for… The for statement syntax : for(init; termination; inc) { statement } To the infinity… for ( ; ; ) { // infinite loop ... }

  23. if…else… • Syntax : if (expression) { statement(s) }[else { statements (s) }]

  24. Example of if…else… public class IfElseDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } }

  25. Bentuk Lain if.. else • ?: operator syntax condition? statement1 : statement2; Jika condition bernilai true, maka statement1 akan dieksekusi. Sebaliknya, bila bernilai false maka statement2 akan dieksekusi.

  26. Switch • switch statement syntax : switch (integer expression) { case integer expression: statement(s); break; ... default: statement(s); break; }

  27. Contoh public class SwitchDemo { public static void main(String[] args) { int month = 8; switch (month) { case 1: System.out.println("January"); break; case 2: System.out.println("February"); break; case 3: System.out.println("March"); break; case 4: System.out.println("April"); break; case 5: System.out.println("May"); break; case 6: System.out.println("June"); break; case 7: System.out.println("July"); break; case 8: System.out.println("August"); break; case 9: System.out.println("September"); break; case 10: System.out.println("October"); break; case 11: System.out.println("November"); break; case 12: System.out.println("December"); break; default: System.out.println("Heh!?"); break;} } }

  28. Introduction to Exception • Untuk menangani kesalahan dalam program, Java menyediakan sebuah mekanisme yang disebut exception. • Ketika sebuah error muncul, program akan mengeluarkan exception. • Dengan adanya exception berarti program tidak berjalan dengan semestinya (misalnya file yang akan dibaca tidak ditemukan, dll), maka JVM akan mencari exception handler.

  29. Bentuk Umum • Exception handler adalah kode yang akan menangani masalah yang bersangkutan. • Ada banyak jenis exception, seperti FileNotFoundException, IOException, dll. • Syntax : try { statement(s) } catch (exceptiontypename) { statement(s) } finally { statement(s) }

More Related