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.
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”. …
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. …
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…
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:
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. …
Computers are all I want to know about.