Posts

Most ignored concept in java but very important from interview point of view : SerialVersionUID

Believe me or not, serialVersionUID is the most ignored concept in java. But as you get familiar with it, you will get to know how important and how powerful this concept is. So, lets deep dive to understand the  serialVersionUID   concept. Prerequisite You need to have prior knowledge of serialization and deserialization to understand the  serialVersionUID   concept better.  What is serialVersionUID? When we serialize an object, JVM generates one unique identifier for serializable class. Which is used at the time of deserialization to verify the sender (who serializes the object) and the receiver (who deserializes the object) have loaded the same compatible serializable class versions at their side? This unique identifier is called  serialVersionUID . How JVM calculates default serialVersionUID? JVM uses various aspects of the class to calculate the  serialVersionUID   like class name, implemented interface, all members of that class, etc. The calculation of default  serialVersionUID

Why we can not throw exception from Thread’s run method?

Image
Yes, you heard it right.   We cannot throw checked exceptions from our implemented threads run() method. Because we override Thread class’s or Runnable interface’s run() method and that method does not throw any checked exception and that’s why even we cannot throw checked exception in our overriding run() method (“Rules for method overriding” is a different topic to discuss, that I will cover separately). Now a big question comes to our mind!! Why Thread class’s or Runnable interface’s run() method declared not to throw checked exception??                                                             Before answering the above question, we need to deep dive to understand: how our implemented run() method gets invoked?? I have explained the answer in a separate post (Just to keep this post as short as possible as this is a big topic to discuss). You can check the answer in my below post. https://deepdivejava91.blogspot.com/2020/09/how-run-method-get-invoked-from-our.html