Common exceptions in java language

In java programming, daily coding, we have encountered different exceptions,so i am listing out the list of common exceptions, and the scenarios, how to solve those exceptions.

following are the exceptions in java programming language. NullPointerException:-

One of common exception occurred, This will be happened when you are calling the object's method with object is not created or not initialized properly.

String str=null; System.out.println(str.toString());

the solution in our code is if(str==null){ //initialize the string object here }else{ System.out.println(str.toString()); } ClassCastException:- This exception is occurred if we assign the incorrect object. NumberFormatException:- This exception is occurred if we convert the string data itmes to number items format object.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.