Create instance using class name in Java

You can create instance using class name if Java knows about the class (the class is stored somewhere of the classpath, ie) within the application context. Thus, you can get a reference to this Class and instantiate an its object via the Class class. This technique is applied in many frameworks, web container, for example … Read more

Java filefilter example to list files and directories in a directory

The Java filefilter example shows you how to filter directory using java FileFilter. I create a directoryFilter object that implements the FileFilter interface, then I implement the accept method. The method returns true if the passed parameter is a directory and false if it is not a directory. More information, you saw how we could … Read more

Convert Java collections into JSON and JSON to collections

This sample show you how to convert Java collections into JSON string. A collections of fruit is built and converted to json object. Then whereas json object is convert to collections object

This is output of program jsonFruitNames = [“Banana”,”Apple”,”Orange”,”Kiwi”] jsonFruits = [{“name”:”Banana”,”location”:”Cuba”,”recommend”:”Should buy”},{“name”:”Apple”,”location”:”USA”,”recommend”:”Should eat”},{“name”:”Orange”,”location”:”Holland”,”recommend”:””},{“name”:”Kiwi”,”location”:”Sweeden”,”recommend”:””}] fruit.getName() = Banana fruit.getLocation() = Cuba fruit.getRecommend() = Should … Read more

Java FileNameFilter example to list files with specific extension

If you need to pick up specific extensions from the given directory and you ask yourself how to filter files using Java. Should implement java FilenameFilter class and override accept() method. Then pass object to list() method to get specific file extensions. Java FileNameFilter example will show you all these stuffs.

Run the java … Read more

Two ways compare Java Double

This sample shows two ways compare Java Double object with another Double object or two dobule primitive values using methods of java.lang.Double class

Output First number is greater Value c1 = 1 Second number is greater Value c2 = -1

Please share it if you found this useful
Hide Buttons