Home Java Java-exception Integer exception in java



Integer exception in java
Posted on: June 13, 2009 at 12:00 AM
The integer class is a wrapper for integer value. Integers are not objects.

Integer exception in java

     

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".

 

IntegerException.java


import java.io.*;

public class IntegerException {

  public static void main(String[] argsthrows IOException {
  try {
  BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the integer value:");
  String s = buff.readLine();
  String doub = new Double(s).toString();
  System.out.println("Double:=" + doub);
 catch (Exception ex) {
  System.out.println("Please enter the value as integer");
 }
  }
}

 

Output of the program

Enter the integer value:
g
Please enter the value as integer


Download source code

Related Tags for Integer exception in java:
cclassobjectobjectsintegervalueintwrapperappforwrapintegersenotpeinnoasntjclobjppsisarvassthapaluctsjeo


More Tutorials from this section

Ask Questions?    Discuss: Integer exception in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.