Transient variables in Java

Java’s serialization provides an elegant, and easy to use mechanism for making an object’s state persistent. While controlling object serialization, we might have a particular object data member that we do not want the serialization mechanism to save.   The modifier transient can be applied to field members of a class to turn off serialization ...

The ‘Rare’ static imports

The static import declaration imports static members from classes, allowing them to be used without class reference.   for example: import static java.lang.System.*; class A { public static void main(String args[]) { out.println("project code bank"); } }   output: project code bank   Note : Try to avoid this feature, because over a period you may ...

Synchronized Methods and Synchronized Blocks

If you declare a method to be synchronized, then the entire body of the method becomes synchronized; if you use the synchronized block, however, then you can surround just the “critical section” of the method in the synchronized block, while leaving the rest of the method out of the block.   If the entire method ...

Stubs and Skeletons

Stubs and Skeletons
In the distributed computing environment, stub stands for a client side object participating in the distributed object communication and a skeleton stands for a server side object participating in distributed object communication.  Stub  Skeleton  The stub acts as a gateway for client side objects and all outgoing requests to server side objects that are routed through it. The stub wraps ...

Overloading and Overriding

 S.No.    Overloaded Methods  Overridden Methods  1.  Arguments  Must Change  Must not change  2.  Return Type  Can change  Can’t change except for covariant returns  3.  Exceptions  Can change  Can reduce or eliminate. Must not throw new or broader checked exception  4.  Access Modifiers  Can change  Must not make more restrictive (can be less restrictive)  5. ...

OOPs concepts 1

OOPs concepts
Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects” that have data fields (attributes that describe the object) and associated procedures known as methods.   What is an Object? An object can be considered a “thing” that can perform a set of related activities. The set of activities that the object performs ...

Null Keys or values in HashMap/Hashtable 4

Can java.util.HashMap store null key/value pair? Yes it can, However only one null key is allowed, but can store many null values against non-null keys   Example public class HashMapTest { public static void main(String args[]) { HashMap h = new HashMap(); h.put(null,null); h.put(null, "1"); h.put("1", null); h.put("1", "1"); h.put("2", null); System.out.println(h.get(null).toString()); System.out.println(h.get("1")); System.out.println(h.get("2")); } ...

NoClassDefFoundError and ClassNotFoundException

NoClassDefFoundError and ClassNotFoundException
NoClassDefFoundError is an Error ,occurs when the source  was successfully compiled but at runtime, the required class files were not found. It may also arise when the class is already loaded in different classloader(usually a parent classloader would have loaded the class and hence the class cannot be loaded again) or if an incompatible class definition ...

Marker Interfaces

Marker interfaces are those which do not declare any required methods, but signify their compatibility with certain operations. The java.io.Serializable interface and Cloneable are typical marker interfaces. These do not contain any methods, but classes must implement this interface in order to be serialized and de-serialized.

JVM, JRE, JDK 2

JVM (Java Virtual Machine) is an abstract machine.It is a specification that  provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms (i.e. JVM is plateform dependent).   The JVM performs four main tasks: Loads code Verifies code Executes code Provides runtime environment   JRE is an acronym for ...