- 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
Why does Java strictly specify the range and behavior of its primitive types?
Java provides various datatypes to store various data values. It provides 7 primitive datatypes (stores single values) namely, boolean, byte, char, short, int, long, float, double.
Java strictly specifies range and behaviors of all the primitive datatypes. Making the users choose the required datatypes based on the application thus reducing the unused occupancy of memory.
For example, if you need to store an integer constant of single digit using integer would be a waste of memory instead, you can use byte type since 8 bits would be necessary to store it.
Example
Following Java example lists out the ranges of the primitive datatypes.
public class PrimitiveDatatypes { public static void main(String[] args) { System.out.println("Minimum value of the integer type: "+Integer.MIN_VALUE); System.out.println("Maximum value of the integer type: "+Integer.MAX_VALUE); System.out.println(" "); System.out.println("Minimum value of the float type: "+Float.MIN_VALUE); System.out.println("Maximum value of the float type: "+Float.MAX_VALUE); System.out.println(" "); System.out.println("Minimum value of the double type: "+Double.MIN_VALUE); System.out.println("Maximum value of the double type: "+Double.MAX_VALUE); System.out.println(" "); System.out.println("Minimum value of the byte type: "+Byte.MIN_VALUE); System.out.println("Maximum value of the byte type: "+ Byte.MAX_VALUE); System.out.println(" "); System.out.println("Minimum value of the short type: "+Short.MIN_VALUE); System.out.println("Maximum value of the short type: "+Short.MAX_VALUE); System.out.println(" "); System.out.println("Minimum value of the long type: "+Long.MIN_VALUE); System.out.println("Maximum value of the long type: "+Long.MAX_VALUE); } }
Output
Minimum value of the integer type: -2147483648 Maximum value of the integer type: 2147483647 Minimum value of the float type: 1.4E-45 Maximum value of the float type: 3.4028235E38 Minimum value of the double type: 4.9E-324 Maximum value of the double type: 1.7976931348623157E308 Minimum value of the byte type: -128 Maximum value of the byte type: 127 Minimum value of the short type: -32768 Maximum value of the short type: 32767 Minimum value of the long type: -9223372036854775808 Maximum value of the long type: 9223372036854775807
- Related Articles
- Java primitive data types
- Comparison of double and float primitive types in Java\n
- Display the minimum and maximum value of primitive data types in Java
- Default value of primitive data types in Java
- What are primitive data types in Java?
- Types and Goals of Organizational Behavior
- What are Primitive and Non-Primitive Data Types in JavaScript?
- List out the default values of numeric and non-numeric primitive data types in Java?
- Convert Long to numeric primitive data types in Java
- Convert Byte to numeric primitive data types in Java
- Convert Short to numeric primitive data types in Java
- Java Program to convert Java Float to Numeric Primitive Data Types
- How does default virtual behavior differ in C++ and Java?
- Comparison of double and float primitive types in C#
- Java Program to convert Double to numeric primitive data types

Advertisements