Java FileWriter V/S BufferedWriter.

Today we will look at java character stream writer. Standard implementation FileWriter class is used to write character stream into the underlying file system. FileWriter class provides API to write character by character, character array and String. BufferedWriter is a process stream used to decorate the IO stream FileWriter. The process stream BufferedWriter helps to […]
Continue reading…

 

Format date using thoughtworks Date Converter.

Today we will look at one very useful utility class named DateConverter which is part of the thoughtworks xstream library . This class can parse date from almost any given format. In the below given example the DateConverter class takes two constructor arguments, first one is default date format and second one is an array […]
Continue reading…

 

How to reload property file in java at runtime?

I have found a good utility class which is part of the apache configuration jar to reload the property or resource file without restarting the JVM or Application Server. FileChangedReloadingStrategy class can be used to reload the property/resource file at runtime if there is any modification is done in the property file. In the below […]
Continue reading…

 

How to find the heap memory usage of your JVM instance?

Java JMX API has very simple API to find out the memory usage of a JVM instance. In the below given example we will find the memory usage of a JVM instance.

Console output

Continue reading…

 

java 7 supports multiple exception handling in same catch block.

One of the most useful feature added as part of java 7 Coin project is capability to handle more than on exception in same catch block. Less non business code makes code more readable.

Continue reading…

 

Wildcard File Filter in java.

Apache common give a useful class named WildcardFileFilter to filter/open files using a wildcardfilter. A simple example of wild card filter is *_2012-01-10*.txt.

Continue reading…

 

How to find all live threads in JVM?

Java JMX API provides you some useful classes to find out details about your JVM. One of those classes is ManagementFactory, This class provides API to find meta data about the JVM. In the below given example we will find all the live threads in the JVM and its state.

Console output.

Continue reading…

 

How to convert native character to unicode and unicode to native?

Java provides a simple tool named native2ascii to convert native to ASCII and ASCII to native. Native characters are represented in ASCII using its Unicode equivalent. You can find the native2ascii tool in the JAVA_HOME/bin To convert native to ascii you can use the below given command. /local/opt/java/bin/native2ascii -encoding utf8 source-file target-file source file should […]
Continue reading…