Photo by Ricardo Gomez Angel on Unsplash

In this article, we will be having a detailed look at exceptions and errors in Java. Let’s start with the most basic question What are exceptions??

Exceptions are in layman's terms are misbehavior in an application that can be predicted and thus, handled to stop the program from getting terminated abruptly. The next question must be so What are errors??

In general, an error is which nobody can control or guess when it occurs. Errors are abnormal conditions that should never occur.


Photo by Camille Orgel on Unsplash

Reserved words are words that cannot be used as an identifier such as variables, functions. Reserved are majorly used for syntactic definitions. Keywords are closely related and often interchangeably used notions for Reserved words. A keyword is a word with special meaning in a particular context. In most modern languages keywords are a subset of reserved words, and it gives advantages during parsing as keywords cannot be confused with identifiers.

In Java, all keywords are reserved words, but some reserved words are not keywords — these are “reserved for future use”. …


Photo by Annie Spratt on Unsplash

In part1 and part2 of this series, we looked upon Hashtable and hashcode() and equals() contract in Java. One might ask why just not use Hashtable instead of HashMap, it’s because as of Java1.2 this collection has been retrofitted to implement the Map interface and the Java docs suggest using HashMap if a thread-safe implementation is not needed and ConcurrentHashMap if a thread-safe implementation is needed.

Now coming to HashMap it implements Map interface and is part of the Java Collections framework. HashMap allows retrieval of values based on a given key, e.g: “key1”->value1, “key2”->value2. …


Hash Code
Hash Code
Photo by Mari Helin on Unsplash

In last article, we saw the implementation of Hashtable. Before moving on to HashMap and its implementation let’s get to know about two primary and most used methods by java developer: equals() and hashCode(). These methods are also underlying core for both Hashtable and HashMap.

public boolean equals(Object obj)
public int hashCode()

Both methods are part of Object class in java. This is the root of the class hierarchy. Every class has Object class as a superclass. All objects, including arrays, implement the methods of this class.

As per Javadoc equals()method indicates whether some other object is “equal to” given…


Photo by Luke Johnson on Unsplash

Let’s take an instance, you are asked to keep track of list of students in your school along with their phone number. What is the first approach that comes to your mind? Hmmm…

Let’s take a look at few approaches:

  1. We’ll go to each student and ask their phone number and keep writing them in our ledger as we come across them.

This was easy if we have 10 students, when we want to look it up we just check in the ledger for a said student and we get the number. …

Prashant Shubham

Computers are all I want to know about.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store