HashMap in Java

HashMap is one of the most used collections in Java. It is used to store key value pair. The size of HashMap increases as more key value pairs are added. Let us look at sample declaration of HashMap: HashMap<Integer,String> dummy = new HashMap<Integer,String>(); In above sample the key stored will be of type Integer and … Read more

NumberFormatException in Java and how to prevent it

NumberFormatException occurs in Java when we are trying to convert string into some numeric type but string is not in the correct format. It usually occurs when we parse string to integer, double, long etc datatypes but string is not present in correct format. Let us see an example code : Output Since ‘123a’ cannot … Read more

Local vs Instance vs Class vs Reference variable in Java

In Java we have 4 type of variables :- Local Variable Instance Variable Class variable Reference variable Java developers often get confused while using these terms, let us understand the difference between them in detail : Local Variable Local variables are those which are defined inside a block, method or constructor. These variables get destroyed … Read more