Kenapa perlu interface?
Salah satu konsep sederhana - yang penting - dalam pemrograman java adalah interface. Jadi, kenapa perlu ada interface dalam pemrograman java?
Saya akan memberikan gambaran untuk mempermudah melihat konsep ini secara utuh dan tetap terbayangkan saat anda membaca lebih lanjut mengenai penjelasannya. Perhatikan gambar di bawah ini:

stupidcow
Sesuai dengan namanya interface (antarmuka), sesuatu yang yang langsung berhadapan dengan kita (dalam kehidupan nyata) dan menghubungkan kita dengan sesuatu. Sedangkan dalam pemrograman java adalah (more…)
Iterate ArrayList menggunakan Iterator Class
Short video above show you, how to iterate an arraylist collection using Iterator class. Enjoy it!
How To Create New Object
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…)
Singleton Pattern
It’s often situation when we write an application code that is we need only one object for several class in an application. For example, an application that working with database should be has only one Database Connection, only one object shared throughout the application. For this case we need a class design pattern which create an object once and share an instance of the object across the entire application.
So, how to create an singleton class? before we write singleton class, let’s take a look to the class bellow, say MyConnection class:
package belajarjavadotcom.post.singleton; public class MyConnection { private static MyConnection connection = new MyConnection(); private MyConnection() { } public static MyConnection getConnection() { return connection; } }
We need to get connection object to create a connection to database, but connection field in MyConnection class has been set as private but it’s static. So, the only way get reference to MyConnection object is make a call to the static method, that is getConnection(). It will look like this
MyConnection.getConnection();
This is the problem, when client calls MyConnection.getConnection() multiple times. Every call of method, create new object of class. We do not wish it will work in that way. So to ensure that class does not create a new object and clients still use the same instance of object. (more…)




