Use of UncaughtExceptionHandler in java.

Since every thread runs in it’s own stack in java the main thread will not come to know the status of Thread started by it. Programmer can implement an interface named UncaughtExceptionHandler to get a call back from JVM if an Exception occurs in a given thread and its not handled properly. A simple implementation [...]
Continue reading…

 

Comparable VS Comparator in Java.

Java util package provides us number of sorted data structures; one of those is the TreeSet. TreeSet is an implementation of Set and it stores the elements in sorted order. All elements needs to be added into a TreeSet should implement Comparable interface directly or indirectly or the TreeSet should be constructed with an appropriate [...]
Continue reading…

 

PipedReader and PipedWriter in java.

You know the power of pipe (“|”) operator in Unix. It helps you to redirect output from one command to another. PipedReader and PipedWriter classes in java.io package helps you to do the same. It helps you to redirect the read input into writer seamlessly. In unix, two process on different address space can communicate [...]
Continue reading…

 

How to create file lock in java?

When multiple threads work on a shared resource its quiet possible that one thread’s work is over written by another one if the shared resource is modified without a mutually exclusive lock. This can be solved by moving the code responsible for the state change of the shared resource into a synchronized method/block. What if [...]
Continue reading…

 

How to find the compiler version from a class file?

There is a tool called javap to find out the compiler version and much more from a class file. See the below given console output to get more details. javap is located in %JAVA_HOME%/bin.

Continue reading…

 

How to filter files in java?

If you want to list out all files from a given directory or drive you can use the list method in the java.io.File class. Consider a scenario where you wanted to list out all files with specific extension. FileFilter interface will help you to filter files using any criteria you can imagine. Today we will [...]
Continue reading…