Java's Primitive Data Types

boolean: 1-bit. May take on the values true and false only.

byte: 1 signed byte (two's complement). Covers values from -128 to 127.

short: 2 bytes, signed (two's complement), -32,768 to 32,767

int: 4 bytes, signed (two's complement). -2,147,483,648 to 2,147,483,647.

long: 8 bytes signed (two's complement). Ranges from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807.

float: 4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative).

double: 8 bytes IEEE 754. Covers a range from 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative).

char: 2 bytes, unsigned, Unicode, 0 to 65,535

🌐
DataCamp
datacamp.com › doc › java › double
double Keyword in Java: Usage & Examples
The double keyword in Java is a primitive data type that represents a double-precision 64-bit IEEE 754 floating point. It is used to store decimal numbers with a higher degree of precision compared to the float data type. The double data type is commonly used in situations that require a large ...
🌐
Quora
quora.com › What-is-the-range-of-the-double-data-type-in-Java
What is the range of the double data type in Java? - Quora
Answer (1 of 4): The range of double in Java is 1.7976931348623157 x 10^308 to 4.9406564584124654 x 10^-324. The java documentation mentions all such details of different data types and all the classes, interfaces and function that are shipped ...
Discussions

Which is larger? Long vs Double
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
10
3
January 19, 2023
When should I use double and when should I use float for Java?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
65
59
January 6, 2024
floating point - What explains the range of a double in java? - Stack Overflow
I'm taking an introductory course in programming (in java) and I'm interested in understanding why the ranges of the primitive data types in java are as they are. When it comes to integer-like data... More on stackoverflow.com
🌐 stackoverflow.com
Java Double Precision
I found this useful the first time I encountered the strangeness of floating-point values: https://floating-point-gui.de/ Basically, it boils down to you can't represent an infinite continuum of real numbers using a finite number of bits. More on reddit.com
🌐 r/java
25
14
August 24, 2020
🌐
Scaler
scaler.com › home › topics › float vs double in java - difference you should know
Float Vs Double in Java - Difference You Should Know - Scaler Topics
March 27, 2024 - Hence, adding the suffix 'd' or 'D' in the number is optional in the case of Double data type values. ... The main difference between Java Float and Double is their precision and range.
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.4 › org › apache › commons › lang › math › DoubleRange.html
DoubleRange (Commons Lang 2.4 API)
$Id: DoubleRange.java 437554 2006-08-28 06:21:41Z bayard $ Author: Stephen Colebourne · See Also: Serialized Form · public DoubleRange(double number) Constructs a new DoubleRange using the specified number as both the minimum and maximum in this range. Parameters: number - the number to use ...
🌐
Oracle
docs.oracle.com › javadb › 10.10.1.2 › ref › rrefsqljdoubleprecision.html
DOUBLE PRECISION data type
These limits are the same as the java.lang.Double Java type limits. An exception is thrown when any double value is calculated or entered that is outside of these value ranges. Arithmetic operations do not round their resulting values to zero. If the values are too small, you will receive an exception. Derby normalizes -0.0 to positive 0.0. Derby throws an exception if an operation calculates or tries to store a value of NaN, positive infinity, or negative infinity, as defined by the IEEE 754 Standard for Binary Floating-Point Arithmetic and as represented with named constants in the Java programming language (for example, Double.NaN).
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-double-precision-2-decimal-places-example-float-range-math-jvm
Java double decimal precision
The precision of a double in Java is 324 decimal places. But the Java double isn't always as precise as you think it should be. Sometimes even simple, two decimal Java double calculations yield ...
Find elsewhere
🌐
CodeGym
codegym.cc › java blog › java numbers › java double keyword
Java double keyword
February 19, 2025 - Float is 32 bits, of which 1 bit is signed bit, 8 bit for exponent and 23 bit for significand. It's range is ±3.40282347E + 38F i.e. 6-7 significant digits. The name double comes from double float.
🌐
Baeldung
baeldung.com › home › java › java numbers › float vs. double in java
Float vs. Double in Java | Baeldung
January 4, 2025 - This test demonstrates that values exceeding the precision limit of float are truncated, while double maintains accuracy up to 15 digits and rounds beyond that. The delta of 1e-15 accounts for minor rounding differences in double precision. The range of a floating-point data type defines the smallest and largest values it can represent, and the ranges of float and double differ significantly.
🌐
IBM
ibm.com › docs › en › i › 7.4.0
COBOL and Java Data Types
We cannot provide a description for this page right now
🌐
Quora
quora.com › What-is-double-in-Java
What is (double) in Java? - Quora
Answer (1 of 4): Double precision, as denoted by the double keyword, uses 64 bits to store a value. Double precision is actually faster than single precision on some modern processors that have been optimized for high-speed mathematical calculations.
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
Note: This rule makes Java safer, because the compiler will stop you if you try to mix up types by mistake. If you really need to change between types, you must use type casting or conversion methods (for example, turning an int into a double).
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Float-vs-Double-Whats-the-difference
Java double vs float: What's the difference?
From the output of the program above, we see the size difference between float and double Java types is: The upper range of a double in Java is 1.7976931348623157E308.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
October 20, 2025 - The argument is considered to be ... "double format" bit layout. If the argument is 0x7ff0000000000000L, the result is positive infinity. If the argument is 0xfff0000000000000L, the result is negative infinity. If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish ...
🌐
Wikipedia
en.wikipedia.org › wiki › Double-precision_floating-point_format
Double-precision floating-point format - Wikipedia
January 9, 2026 - Most implementations provide SINGLE-FLOATs and DOUBLE-FLOATs with the other types appropriate synonyms. Common Lisp provides exceptions for catching floating-point underflows and overflows, and the inexact floating-point exception, as per IEEE 754. No infinities and NaNs are described in the ANSI standard, however, several implementations do provide these as extensions. On Java before version 1.2, every implementation had to be IEEE 754 compliant.
🌐
Mount Allison University
mta.ca › ~rrosebru › oldcourse › comp1711 › 171102 › comp1711A › numbers.html
CS 1711
A primitive data type is only a value. It has no methods. This is because primitive data types are provided as part of the java language - not through a java class definition · The java language provides many different primitive data types to represent and store numeric values.
🌐
Codefinity
codefinity.com › blog › Float-vs-Double
Float vs Double
On the other hand, double offers double the precision with about 15 decimal digits and a range from approximately 4.9E-324 to 1.8E+308, making it more suitable for accurate calculations.
Top answer
1 of 2
1

Java uses the IEEE-754 binary64 format. In this format, one bit represents a sign (+ or − according to whether the bit is 0 or 1), eight bits are used for an exponent, and 52 bits are used for the primary encoding of the significant. One bit of the 53-bit significand is encoded via the exponent.

The values of the exponent field range from 0 to 2047. 2047 is reserved for use with infinities and NaNs. 0 is used for subnormal numbers. The values 1 to 2046 are used for normal numbers. In this range, an exponent field value of E represents an exponent e = E−1023. So the lowest value of e is 1−1023 = −1022, and the highest value is 2046−1023 = 1023. An exponent field value of 0 also represents the lowest value of E, −1022.

The 53-bit significand represents a binary numeral d.dddddd2, where the first d is 0 if the exponent field is 0 and 1 if the exponent field is 1 to 2046. There are 52 bits after the “.”, and they are given by the primary significand field.

Let S be the sign bit field, E be the value of the exponent field, and F be the value of the primary significand field as an integer. Then the value represented is:

  • if E is 1 to 2046, (−1)S • 2E−1023 • (1 + F•2−52),
  • if E is 0, (−1)S • 2−1022 • (0 + F•2−52).

Now we can see the smallest positive number is represented when S is 1, E is 0, and F is 1 (00000000000000000000000000000000000000000000000000012). Then the value represented is (−1)0 • 2−1022 • (0 + 1•2−52) = +1 • 2−1022 • 2−52 = 2−1074.

The greatest finite number is represented when S is 1, E is 2046, and F is 252−1 (11111111111111111111111111111111111111111111111111112). Then the value represented is (−1)0 • 22046−1023 • (1 + (252−1)•2−52 = +1 • 21023 • (1 + 1 − 2−52) = 21023 • (21 − 2−52) = 21024 − 2971.

2 of 2
0

It's the same thing for floating-point values as for integer values - the number of bits available.

An IEEE double-length floating point value has 64 bits, used as follows:

Sign bit: 1 bit
Exponent: 11 bits
Significand precision: 52 bits

The significand is a binary fraction, the maximum value (all bits set) is therefore somewhat less than one.

The exponent has value 0 to 2047, or -1024 to +1023. That gives you the approximate range of 2 to the -1024 to 2 to the +1023 (it's actually less since a couple of values are reserved for specific use).

Wikiipedia for more exact details