Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Integer exception in java 
 

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

                         

» View all related tutorials
Related Tags: java c exception com compiler class io compile pil handle if ie mpi ssi e il ce in as m

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.