1 / 13

Elemen Dasar Java

Elemen Dasar Java. As’ad Djamalilleil http://kampusku.uni.me asad.kom@gmail.com. Keyword di Java. Tipe Data. Bilangan bulat (integer) byte (8-bit)  -128 s/d 127 short (16-bit)  -32768 s/d 32767 char (16-bit)  0 s/d 65535 int (32-bit)  -2147483648 s/d 2147483647

sara-bishop
Download Presentation

Elemen Dasar Java

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. Elemen Dasar Java As’ad Djamalilleil http://kampusku.uni.me asad.kom@gmail.com

  2. Keyword di Java

  3. Tipe Data Bilangan bulat (integer) • byte (8-bit)  -128 s/d 127 • short (16-bit)  -32768 s/d 32767 • char (16-bit)  0 s/d 65535 • int (32-bit) -2147483648 s/d 2147483647 • long (64-bit) -9223372036854775808 s/d 9223372036854775807

  4. Bilangan real • float (32-bit)  single-precision • double (64-bit)  double-precision Logic • boolean  true/false Literal • String

  5. Nilai Bilangan bulat (integer) • Desimal contoh : 4 -45 1230 -34567 • Oktal contoh : 0777 0004 0345 • Heksadesimal contoh : 0xFF 0x3F4D Bilangan real • Pecahan (untuk tipe float perlu ditambahkan notasi F dan untuk double D, setelah nilainya. contoh : 0.2345F 123.453D -34.67F • Eksponen contoh : 10E05 1.5e12 3.45e-5 Logic • Boolean contoh : true false

  6. Karakter nilai berupa karakter harus diapit dengan tanda petik tunggal (single-quote) Contoh : ‘A’ ‘g’ ‘.’ ‘@’ ‘5’ String nilai berbentuk string (lebih dari satu karakter) harus diapit dengan tanda petik ganda (double-quote) Contoh : “AB” “Dunia dalam berita” “345”

  7. Aturan pemberian nama : • Nama dapat berupa kombinasi huruf, angka, dan underscore • Nama tidak boleh diawali dengan angka • Tidak boleh sama keyword

  8. Deklarasi & Inisialisasi Variabel tipeData namaVariabel ; tipeData namaVar1, namaVar2, …. ; tipeData namaVariabel = nilai; tipeData namaVar1 = nilai, namaVar2 = nilai , …. ;

  9. Constant/Konstanta di Java • Deklarasi konstanta di Java menggunakan keyword final. Contoh: final double PI = 3.14; final int JUM_MHS = 40;

  10. Type-casting • Type-casting  mengubah sebuah nilai dengan tipe data tertentu ke dalam tipe data yang lain. byte  short, char, int, long, float, double short  int, long, float, double char  int, long, float, double int  long, float, double long  float, double float  double

  11. Type-casting dapat juga dilakukan secara ekplisit Contoh: int x; x = (int) (7.0 / 3); ekspresi 7.0 / 3 menghasilkan nilai bertipe real sedangkan x bertipe integer. Agar x dapat menyimpan hasil perhitungan, maka nilainya harus di-casting terlebih dahulu menjadi bertipe integer, dengan konsekuensi hilangnya tingkat presisi dari nilai tersebut. Pada akhirnya x akan menyimpan nilai 2.

  12. Tanda komentar // baris ini merupakan contoh komentar /* blok ini, yang dapat terdiri dari beberapa baris, juga merupakan contoh komentar dalam program */

More Related