Static Nested classes are inner classes which are declared inside another class and also declared with static keyword. The main difference between inner class and static nested classes is that inner classes are non-static and static nested classes are static. Also known as static classes. Static nested classes can be accessed using the enclosing class …
Java
Java InputStreamReader Example
InputStreamReader is bridge between bytes and streams. This usually reads the bytes from the source files and convert them to the characters with the specified charset. Which charset has to be used will be specified with the name. In this example I have used “UTF-8” charset. This exampls shows how to use InputStreamReader for reading …
How To Count Files In A Directory Using Java
This example shows how to count the number of files in a folder. File class defines a method list() which returns the array of file names in the directory. By getting the length of that array would mean the number of files in the folder. Lets look at the simple example. CountFilesExample.java
How To Open Word Document In Java
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 …
Difference Between HashMap And Hashtable in Java
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. If you want to make HashTable thread-safe, use …
Generic Constructors Example
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()
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
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 …