Thursday, August 7

Difference between ClassNotFoundException vs NoClassDefFoundError

ClassNotFoundException Vs NoClassDefFoundError


ClassNotFoundException :  ClassNotFoundException occurs when class loader could not find the required class in class path. So, basically you should check your class path and add the class in the classpath.

NoClassDefFoundError : This is more difficult to debug and find the reason. This is thrown when at compile time the required classes are present , but at run time the classes are changed  or removed or class's static initializes threw exceptions. It means the class which is getting loaded is present in classpath , but one of the classes which are required by this class , are either removed or failed to load by compiler .So you should see the classes which are dependent on this class.

Tuesday, August 5

Why Map dosen't implement Collection Interface?

Why doesn't Map extend Collection?

Reson 1)

Collection assume elements of one value. Map assumes entries of key/value pairs. They could have been engineered to re-use the same common interface however some methods they implement are incompatible e.g.
Collection.remove(Object) - removes an element.
Map.remove(Object) - removes by key, not by entry.

You could model a Map as a collection of entries, which is what Map.entrySet() does.

There are some methods in common; size(), isEmpty(), clear(), putAll/addAll() but these are unlikely to have much value as a stand alone interface. (Again Map.entrySet() can be used instead)

 

 Reson 2)

This was by design. We feel that mappings are not collections and collections are not mappings. Thus, it makes little sense for Map to extend the Collection interface (or vice versa).

Monday, August 4

Concept of Serialization

 What is Serialization?

Serialization is an API for encoding an objects as byte-stream and reconstructing objects from their byte-stream encodings. The serializing is process of encoding objects as byte-stream and reverse process is called deserializing.

Implementation Of Serializable

Implementation Serializable to an object allow's class instances to be serialized can be as simple as adding the words 'implements Serializable' to its declaration.

Ads Inside Post