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

public class BatchTest { public static void main(String[] args) { Runtime run = Runtime.getRuntime(); try { Process p = run.exec("cmd start /c D:/test.bat"); System.out.println(p.exitValue()); } catch (Exception e) { e.printStackTrace(); } System.out.println("FINISHED"); } }

0 Answers  


What is difference between word and integer?

0 Answers  


Diff between Comparator and Comparable?

2 Answers   Aditya Birla,


What is the use of bufferedreader?

0 Answers  


How do you join strings in java?

0 Answers  






Is it compulsory for a try block to be followed by a catch block in java for exception handling?

0 Answers  


Explain about object oriented programming and its features?

0 Answers  


what do you mean by stream pipelining in java 8? Explain

0 Answers  


What is a boolean used for?

0 Answers  


What is overloading and overriding in java?

0 Answers  


How many bits are allocated to represent character of character sets - Unicode, ASCII, UTF-16, UTF-8?

1 Answers  


Which package has light weight components?

0 Answers  


Categories