- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Overflow of DataTypes in Java
Overflow occurs when the given value is more than the maximum prescribed size of a data type. The overflow condition can result to an error or now the implementation of the programming language handles it on its own.
To display overflow of datatypes, I have taken an example of float datatype. Float data type is a single-precision 32-bit IEEE 754 floating point.
The range of a float datatype is −
approximately ±3.40282347E+38F
The following program display overflow of datatypes in Java.
Example
public class Demo { public static void main(String[] args) { System.out.println("Displaying Overflow... "); float val1 = 3.3976835E38f; System.out.println(val1 * 25f); } }
Output
Displaying Overflow... Infinity
In the above program, the float variable is initialized to.
float val1 = 3.3976835E38f;
After that, multiplication operation is performed on it to check for overflow.
val1 * 25f;
Since it extends the maximum range, “Infinity” is returned as the output.
- Related Articles
- Underflow of DataTypes in Java
- Display the limits of DataTypes in Java
- Display default initial values of DataTypes in Java
- Java overflow and underflow
- Heap overflow and Stack overflow in C
- Java Program to check for Integer overflow
- Heap overflow and Stack overflow
- Python Container Datatypes
- Assigning long values carefully in java to avoid overflow\n
- Python – Get the datatypes of columns
- Java Program to multiply integers and check for overflow
- Java Program to add integers and check for overflow
- Java Program to subtract integers and check for overflow
- Values of CSS overflow property
- What is the difference between overflow: auto and overflow: scroll in CSS?

Advertisements