What are integer overflows and underflows and how to handle
them?

Answers were Sorted based on User's Feedback



What are integer overflows and underflows and how to handle them?..

Answer / nirmala

If the specified value exceeds the range that will result
overflow.
similarly,
if the specified value below the range that will result in
underflow
ie
byte b=259;(butits rangeis(-127 to 128) totally 256
in this u will get overflow error.

Is This Answer Correct ?    26 Yes 11 No

What are integer overflows and underflows and how to handle them?..

Answer / ramprakash

It uses those low order bytes of the result that can fit
into the size of the type allowed by
the operation.

Is This Answer Correct ?    11 Yes 4 No

What are integer overflows and underflows and how to handle them?..

Answer / ramesh kumar

byte b = (byte)250;

Here I assinged the value to b more than the positive range
of byte. So, It leads to overflow and we won't get any
error in compile time or run time.

But some unexpected value will be stored into b. i.e b = -
6. This will affect your logic.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

I want to control database connections in my program and want that only one thread should be able to make database connection at a time. How can I implement this logic?

0 Answers  


Will the compiler creates a default constructor if I have a parameterized constructor in the class?

0 Answers  


Why transient variables wont participate in serialization?

2 Answers  


class A { public void disp(int a,int b) { System.out.println("hai"); } } class B { public void disp(int a,int b,int c) { System.out.println("hai"); } } above program is overloading or overriding?

9 Answers   Infosys, Wipro,


Explain java coding standards for methods?

0 Answers  


Explain about data types?

0 Answers  


What are the Object and Class that classes used for?

3 Answers   Mphasis,


What are the advantages of assembly language?

0 Answers  


What is a class object?

0 Answers  


Can we nested try statements in java?

0 Answers  


How the elements are organized in GridLayout?

2 Answers  


Why are functions called methods in java?

0 Answers  


Categories