How To Get Operating System Drive Letters in Java

java-thumbnail

This example shows how to list the system drive letters using Java program. File.listRoots() method returns the drive letter from the file system. Lets look at the simple example for listing the operating system’s drive letters for windows. ListOSDrivesExample.java Output…

How To Open Word Document In Java

java-thumbnail

This example shows how to open a word document using Java. If you are working with tools where you have to open the document by clicking on it, you can use the java.awt.Desktop API to easily open the document by passing the file object. Note that this API will open any document passed into the […]

Static Initializer , Instance Initializer And Constructor In Java

java-thumbnail

This example show the order of the Java initialization blocks. Java has static initializer, instance initializer and constructor for initializing the variables. These blocks are used for the different purposes and leads to confusion among the programmers. Order of the execution of these blocks are as follows: All Static Initializers executed in the same order […]

Difference Between HashMap And Hashtable

java-thumbnail

There are few differences between HashMap and Hashtable. This example illustrates the key differences with simple example. Hashtable is synchronized where as HashMap is not synchronized. It is one of the key difference between HashMap and HashTable. HashMap offers better performance than HashTable in the multi-threaded environments. Hashtable does not allow null keys or values. […]

Generic Constructors Example

java-thumbnail

Generic is one of the useful language feature introduced from Java 5.0. There are many great features as part of the Generics is not fully utilized by the programmers. One such instance is the use of generic constructors. This example shows how to use the generic with constructor and takes the different type arguments. In […]

How To Load A Class Using Class.forName()

java-thumbnail

This example shows how to load a class using the Class.forName() method. All the classes in your application or dependent class files are loaded by appropriate class loader prior to using in the application. By default, class files are loaded by JVM when first time accessed by the applications. However, in certain situations you have […]

Instance Initializer In Java

java-thumbnail

In my previous example I have explained how to use static initializer in Java.This example shows how to use the instance initializer block in Java. The following are the few features of instance blocks. Instance initializers are block of code with out any keyword keyword. The code which needs to be initialized will be put […]

How To Get Class Loaded Path

java-thumbnail

This example illustrates how to get the class loaded path. If you are aware of the java.lang.Class, it has methods for knowing the details of a class. There are many details this object can reveal us, one of the method defined in that class is Class.getProtectionDomain() which is useful for getting the source code path […]

How To Get Current Class Loader Name

java-thumbnail

This example shows how to get the name of the class loader and parent class loader for the currently executing class. If you are not aware of the class loaders, please read our previous article about ClassLoader. What is the ClassLoader ? As its name implies, ClassLoader is a class that loads other classes. More […]

How To Get Implementing Interfaces Name For A Class

java-thumbnail

This example illustrates how to get the implemented interfaces names of a particular class. If you are aware of the java.lang.Class, it has methods for knowing the details of a class. One of the method defined in that class is Class.getInterfaces() which is useful for getting all the interfaces names which it is implemented. This […]