When you need some sort of ordering for the classes which you define, you will be going either for a comparable or comparator interface. Consider this example package test; import java.util.*; public class TreeSetTest { private static Set<Person> s = new TreeSet<Person>(); public static void main(String a[]){ s.add(new Person(20)); s.add(new Person(30)); s.add(new Person(10)); s.add(new Person(50)); [...]
Archive | Java RSS feed for this section
What is super and this keyword in java?
February 21, 2013
keyword : this ‘this’ is used for pointing the current class instance. It can be used with variables or methods. Look into the following example: class Test{ private int i=10; public void m(){ System.out.println(this.i); } } In the above code this is used for the current instance. Since this is instance of a class it [...]
How to use BitWise shift operator in Java?
February 21, 2013
They are called shift operators and they operate by shifting the number of bits being specified as an operand in the operation. >> —> Right shift Operator << —> Left Shift Operator >>> —-> Right bit with zero fill operator. The first two maintain the MSB when shifting thereby they maintain the sign of the [...]
What is difference between equals() and == ?
February 21, 2013
Explanation : 1 They both differ very much in their significance. equals() method is present in the java.lang.Object class and it is expected to check for the equivalence of the state of objects! That means, the contents of the objects. Whereas the ‘==’ operator is expected to check the actual object instances are same or [...]
Difference Between List and ArrayList ?
February 21, 2013
List is an interface and ArrayList is an implementation of the List interface. The arraylist class has only a few methods in addition to the methods available in the List interface. There is not much difference in this. The only difference is, you are creating a reference of the parent interface in the first one [...]
What is the difference between JRE,JVM and JDK?
February 21, 2013
JDK (Java Development Kit) Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc… Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method. You need [...]
How to use Socket API for creating Client-Server application in Java
August 20, 2012
In this example we make use of ServerSocketChannel and SocketChannel to create a simple Echo application where in the Server would print the data sent by the client. The code is explained with the required comments: and the client which connects to the server is:
How to use ByteBuffer in Java?
August 7, 2012
ByteBuffer API has been in Java since 1.4. The name itself suggests that these contain bytes of data. The data to be stored in the buffer can be Integer (int, long), Characters (char), Floating value (double), all these are converted into bytes before being stored in the buffer array. ByteBuffer can be of two types- [...]
Developing Concurrent applications using ExecutorService Framework in Java
July 1, 2012
We all have used Thread, Runnable to develop multi-threaded applications in Java. While we used Thread and Runnable we had a lot of work to do in terms of assigning the task to the Thread, starting the thread to waiting for it to complete the execution to get the result from each thread. In Java [...]
Java HelloWorld vs Scala HelloWorld
June 17, 2012
As a first step into learning Scala and as one who is familiar with Java, let us compare the customary Helloworld programs in Java and Scala. You might already know that to run a Java program, there must be a public class with a main method that takes one parameter, a String[], and has a void return [...]






February 21, 2013
0 Comments