Invoking constructor using java reflection.

Invoking non parameterized and parameterized constructors in java is possible thru reflection API. This helps the programmers to instantiate classes which are configured in a property file or in database on the runtime. Below given example demonstrate the power of jave reflection API, program creates instances using parameterized and non parameterized constructors. Code snippet to […]
Continue reading…

 

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 save binary files into MongoDB using java driver?

MongoDB GridFS is a specification for storing large files. (16 MB or more) All MongoDB drivers support GridFS. GridFS split the file into many chunks and store each chunk in each document. GridFS stores documents in two collections. Chunk Collection. File Collection. The first collection stores the binary chunk and the second collection store the […]
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…

 

How to increase connection pool size in JBoss?

You can increase the connection pool size in JBoss application server in simple three steps. 1. Figure out the datasource.xml from JBOSS_HOME/SERVER_INSTANCE/deploy. In case of Oracle the file will be named as oracle-ds.xml. 2. Add below given tags into the xxxx-ds.xml file. 3. Restart the JBoss application server. You can verify the pool size in […]
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…