The integer class is a wrapper for integer value. Integers are not objects. The Java utility classes require the use of objects. If you want to store an integer in a hash table, you have to "wrap" an Integer instance in it.
Understand with Example
The Tutorial illustrate a code that helps you in understanding a Integer exception in java. The program given below describes the way of handling integer exception .In the program given below we have created -
1) Buffer Reader - This is used to read text from the character input stream. The program will ask the user to enter the number , if the user enter the number other than integer it will gives an exception error. if the user enters integer it will display the number which the user have entered.
2) Read line( ) - This is used to read a line from the character
3)Integer.toString( ) - This return you the string representation irrespective of any data type passed as argument in it.
In case the user enter a value other than integer, exception will caught in the catch block and println print the "Please enter the value as integer".
Output of the program
|Enter the integer value:
Please enter the value as integer
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial
Discuss: Integer exception in java
Post your Comment