BelajarJava.Com


Iterate ArrayList menggunakan Iterator Class

Posted in Fundamental by jolly on the March 25th, 2009

Short video above show you, how to iterate an arraylist collection using Iterator class. Enjoy it!

Menentukan format angka.

Posted in Fundamental by jolly on the March 5th, 2009

Suatu saat anda perlu untuk menuliskan angka yang selalu terdiri dari beberapa digit. Misalnya anda diminta agar berapapun angka tersebut akan tampil 5 digit. Contohnya:

00001 atau 00010 atau 00121

Salah satu caranya dengan menggunakan Class NumberFormat. Berikut ini contoh kodenya.

  1. NumberFormat nf = NumberFormat.getNumberInstance();
  2. // agar format angka selalu terdiri dari 5 digit
  3. nf.setMinimumIntegerDigits(5);
  4. // nilai false agar tidak melakukan pengelompokan dalam ribuan.
  5. nf.setGroupingUsed(false);
  6. nf.format(1230);
  7.  

Suatu saat anda akan memerlukan source code ini. Jika anda menggunakan bahasa pemrograman Java. Enjoy :D

Mengambil angka tahun, bulan dan tanggal secara terpisah.

Posted in Fundamental by jolly on the March 5th, 2009

Saya mencoba mencari-cari bagaimana mendapatkan tahun saja (waktu sekarang) atau bulan saja atau tanggal saja. Beberapa fungsi sederhana yang dapat dipakai sudah diprecated atau tidak relevan lagi, walaupun masih bisa dipakai. Sehingga saya pakai kelas Calendar. Berikut ini kodenya:

  1. Calendar c = Calendar.getInstance();
  2. c.get(Calendar.YEAR)
  3.  

Keluaran dari kode diatas adalah 2009, tahun saat ini. Jika anda ingin tanggal cukup mengganti YEAR menjadi DATE, ingin bulan ganti jadi MONTH.

How To Create New Object

Posted in Fundamental by jolly on the January 21st, 2009

First of all, for someone new with Java programming language must be have no idea what is “Object” term in the title means. Java programming language is Object Oriented Programming (OOP) base, it works like a real life in the world. So, what is the object in the real life? I’am an object, every people is object, your nokia N series is object, my SonyEricsson is object. We can say everything in our world is an object. There is higher level than object, that is Class and an object is representation of Class. This is my best analogy to describe the relation of class and object. In the real world, Human categorized as class and individu named Simon for example categorized as object. So let say that “Simon is an Object of Human Class“. Human typically has attributes such as two arms, two eyes, one nose, has hair and so on, so that Simon as an object of Human has them too.

In OOP also has Class and Object term and the relation between both of them already explained above. Simon in reality is God’s hand-made but sure Simon also can make his object to. Let say Simon is Java Programmer and he want to create an object. In Java language, to create an object you have to have a Class first, so Simon create his class named Human then he may start to create a new object from it. (more…)