Generics are a feature of generic programming which was introduced in Java 5. This allows a type or method to work with various object types while providing compile-time type safety. For example, collection framework supports generics. We can use Hashset, ArrayList, HashMap etc. to store various type of objects, and while retrieving the data we don't need to type cast. In Java 5, java rewrote the collection framework to incorporate the generics. Here is an
Read more 0java
A resource is an object that must be closed once the program is finished or done using it, for example, file resource, JDBC database connection resource, socket connection resource etc. Prior to Java 7, there was no auto resource management, we open the resource in a try block and close the resource in finally block. For example: try{ //open resources }catch(IOException){ //Exception handling }finally{ //close resource } In the above approach there were few drawbacks:
Read more 0In Java volatile keyword is used to guarantee memory visibility of a variable. When a variable is marked as volatile, it will be stored in main memory. Every read & write is performed on main memory instead of CPU cache. In case of without volatile instance variable, read/write are always performed on CPU cache not directly on main memory, in such cases when multiple threads are performing read/write on multiprocessor system there are possibilities that
Read more 0