What is the difference between an instance variable and a static variable? How does a local variable compare to an instance or a static variable? Give an example where you might use a static variable?

Static variables Instance variables Class variables are called static variables. There is only one occurrence of a class variable per JVM per class loader. When a class is loaded the class variables (aka static variables) are initialized. Instance variables are non-static and there is one occurrence of an instance variable… Continue reading

What is the main difference between shallow cloning and deep cloning of objects?

The default behavior of an object’s clone() method automatically yields a shallow copy. So to achieve a deep copy the classes must be edited or adjusted. Shallow copy: If a shallow copy is performed on obj-1 as shown in fig-2 then it is copied but its contained objects are not…. Continue reading

How can you improve Java I/O performance?

Java applications that utilize Input/Output are excellent candidates for performance tuning. Profiling of Java applications that handle significant volumes of data will show significant time spent in I/O operations. This means substantial gains can be had from I/O performance tuning. Therefore, I/O efficiency should be a high priority for developers… Continue reading

How does the new I/O (NIO) offer better scalability and better performance?

Java has long been not suited for developing programs that perform a lot of I/O operations. Furthermore, commonly needed tasks such as file locking, non-blocking and asynchronous I/O operations and ability to map file to memory were not available. Non-blocking I/O operations were achieved through work around such as multithreading… Continue reading

Explain the Java I/O streaming concept and the use of the decorator design pattern in Java I/O?

Java input and output is defined in terms of an abstract concept called a “stream”, which is a sequence of data. There are 2 kinds of streams. Byte streams (8 bit bytes) -> Abstract classes are: InputStream and OutputStream Character streams (16 bit UNICODE) -> Abstract classes are: Reader and… Continue reading

How would you exclude a field of a class from serialization or what is a transient variable?

Transient variables cannot be serialized. The fields marked transient in a serializable object will not be transmitted in the byte stream. An example would be a file handle, a database connection, a system thread etc. Such objects are only meaningful locally. So they should be marked as transient in a… Continue reading