What is a final modifier? Explain other Java modifiers?

A final class can’t be extended i.e. A final class can not be subclassed. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (i.e. it is a constant). Modifier Class Method Variable static A static inner class is just an inner class associated with the class, rather than with an instance of the class. A static method is called by classname.method (e.g Math.random()), can only access static variables. Class variables are called static variables. There is only one occurrence of a class variable per JVM per class loader. abstract An … Click here to continue…..

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 in each class instance (i.e. each object). Also known as a member variable or a field. A static variable is used in the singleton pattern. A static variable is used with a final modifier to define constants. Local variables Instance and static variables Local variables have a narrower scope than … Click here to continue…..

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. The contained objects Obj-1 and Obj-2 are affected by changes to cloned Obj-2. Java supports shallow cloning of objects by default when a class implements the java.lang.Cloneable interface. Deep copy: If a deep copy is performed on obj-1 as shown in fig-3 then not only obj-1 has been copied but … Click here to continue…..

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 looking to optimally increase performance. The basic rules for speeding up I/O performance are Minimize accessing the hard disk. Minimize accessing the underlying operating system. Minimize processing bytes and characters individually. Let us look at some of the techniques to improve I/O performance. Use buffering to minimize disk access and … Click here to continue…..

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 or using JNI. The New I/O API (aka NIO) in J2SE 1.4 has changed this situation. A server’s ability to handle several client requests effectively depends on how it uses I/O streams. When a server has to handle hundreds of clients simultaneously, it must be able to use I/O services … Click here to continue…..