In C, the language itself does not determine the representation of certain datatypes. It can vary from machine to machine, on embedded systems the int can be 16 bit wide, though usually it is 32 bit.

The only requirement is that short int <= int <= long int by size. Also, there is a recommendation that int should represent the native capacity of the processor.

All types are signed. The unsigned modifier allows you to use the highest bit as part of the value (otherwise it is reserved for the sign bit).

Here's a short table of the possible values for the possible data types:

          width                     minimum                         maximum
signed    8 bit                        -128                            +127
signed   16 bit                     -32 768                         +32 767
signed   32 bit              -2 147 483 648                  +2 147 483 647
signed   64 bit  -9 223 372 036 854 775 808      +9 223 372 036 854 775 807
unsigned  8 bit                           0                            +255
unsigned 16 bit                           0                         +65 535
unsigned 32 bit                           0                  +4 294 967 295
unsigned 64 bit                           0     +18 446 744 073 709 551 615

In Java, the Java Language Specification determines the representation of the data types.

The order is: byte 8 bits, short 16 bits, int 32 bits, long 64 bits. All of these types are signed, there are no unsigned versions. However, bit manipulations treat the numbers as they were unsigned (that is, handling all bits correctly).

The character data type char is 16 bits wide, unsigned, and holds characters using UTF-16 encoding (however, it is possible to assign a char an arbitrary unsigned 16 bit integer that represents an invalid character codepoint)

          width                     minimum                         maximum

SIGNED
byte:     8 bit                        -128                            +127
short:   16 bit                     -32 768                         +32 767
int:     32 bit              -2 147 483 648                  +2 147 483 647
long:    64 bit  -9 223 372 036 854 775 808      +9 223 372 036 854 775 807

UNSIGNED
char     16 bit                           0                         +65 535
Answer from gaborsch on Stack Overflow
Top answer
1 of 11
450

In C, the language itself does not determine the representation of certain datatypes. It can vary from machine to machine, on embedded systems the int can be 16 bit wide, though usually it is 32 bit.

The only requirement is that short int <= int <= long int by size. Also, there is a recommendation that int should represent the native capacity of the processor.

All types are signed. The unsigned modifier allows you to use the highest bit as part of the value (otherwise it is reserved for the sign bit).

Here's a short table of the possible values for the possible data types:

          width                     minimum                         maximum
signed    8 bit                        -128                            +127
signed   16 bit                     -32 768                         +32 767
signed   32 bit              -2 147 483 648                  +2 147 483 647
signed   64 bit  -9 223 372 036 854 775 808      +9 223 372 036 854 775 807
unsigned  8 bit                           0                            +255
unsigned 16 bit                           0                         +65 535
unsigned 32 bit                           0                  +4 294 967 295
unsigned 64 bit                           0     +18 446 744 073 709 551 615

In Java, the Java Language Specification determines the representation of the data types.

The order is: byte 8 bits, short 16 bits, int 32 bits, long 64 bits. All of these types are signed, there are no unsigned versions. However, bit manipulations treat the numbers as they were unsigned (that is, handling all bits correctly).

The character data type char is 16 bits wide, unsigned, and holds characters using UTF-16 encoding (however, it is possible to assign a char an arbitrary unsigned 16 bit integer that represents an invalid character codepoint)

          width                     minimum                         maximum

SIGNED
byte:     8 bit                        -128                            +127
short:   16 bit                     -32 768                         +32 767
int:     32 bit              -2 147 483 648                  +2 147 483 647
long:    64 bit  -9 223 372 036 854 775 808      +9 223 372 036 854 775 807

UNSIGNED
char     16 bit                           0                         +65 535
2 of 11
84

In C, the integer(for 32 bit machine) is 32 bit and it ranges from -32768 to +32767.

Wrong. 32-bit signed integer in 2's complement representation has the range -231 to 231-1 which is equal to -2,147,483,648 to 2,147,483,647.

🌐
CodeGym
codegym.cc › java blog › java numbers › integer max_value in java with examples
Integer MAX_VALUE in Java with Examples
December 10, 2024 - Integer.MAX_VALUE is a number in the Java Integer сlass of java.lang package. It is the maximum possible Integer number that can be represented in 32 bits. Its exact value is 2147483647 i.e.
Discussions

Beginner here; please help with explaining why Integer.MAX_VALUE and Integer.MIN_VALUE is assigned as values in this code.
Think of only one, you are looking for the lowest number in an array, you take the first number and compare it to your minValue, if it is smaller you choose that as new minValue and try the next. If you start minValue as the absolute MIN_VALUE, it will never find a smaller number in your array. SO you should start minValue as higher as possible and maxValue as lover. (Or you can just initiate them as the first number in your array) More on reddit.com
🌐 r/learnjava
3
0
July 4, 2022
How to get the value of Integer.MAX_VALUE in Java without using the Integer class - Stack Overflow
I have this question that has completely stumped me. I have to create a variable that equals Integer.MAX_VALUE... (in Java) // The answer must contain balanced parentesis public class Exercise{ More on stackoverflow.com
🌐 stackoverflow.com
Why Integer.MAX_VALUE + Integer.MAX_VALUE result in -2?
First off Integer.MIN_VALUE is -(231) and not 231 Integer.MAX_VALUE = 231 -1 = 2147483647. If we do the addition in binary we get: 1111111111111111111111111111111 +1111111111111111111111111111111 11111111111111111111111111111110 Which is -2 in decimal. As far as I remember the 32nd bit being 1 indicates that the number is negative. The binary representation of 231 - 1 takes 31 bits, the 32nd bit being 0. The operation of MAX_VALUE + MAX_VALUE overflows and makes the 32nd bit 1. To look at it another way.... Integer.MAX_VALUE + 1 = Integer.MIN_VALUE so Integer.MAX_VALUE + Integer.MAX_VALUE + 1 = Integer.MIN_VALUE + Integer.MAX_VALUE which implies Integer.MAX_VALUE + Integer.MAX_VALUE = Integer.MIN_VALUE + Integer.MAX_VALUE - 1 = -(231) + (231 -1) -1 = -(231) + (231) -1 -1 = -2 More on reddit.com
🌐 r/java
8
0
May 16, 2013
[JAVA]check if a value is higher than max or min int value
You want to test if the expression A * B > max is true, but you can't directly evaluate the term A * B because it might overflow, so adjust the inequality, perhaps A > max / B. (There could be rounding errors to account for.) Alternatively, you could compute A * B using a long. More on reddit.com
🌐 r/learnprogramming
3
7
July 8, 2012
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java math.max() method
Java Math.max() Method
September 1, 2008 - The Java Math max(long a, long b) returns the greater of two long values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value.
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › VariableBasics › minAndMax.html
3.7. Integer Min and Max — AP CSA Java Review - Obsolete
In 32 bits of space with one bit used to represent the sign you can represent that many values. Why is there one more negative number than positive number? It is because 0 is considered a positive number. What do the last two lines print out? Did this surprise you? Java will actually return the maximum integer value if you try to subtract one from the minimum value.
🌐
iO Flood
ioflood.com › blog › integer-max-value-java
Java's Integer.MAX_VALUE Explained: A Complete Guide
March 11, 2024 - Continue reading for a more detailed ... in the Integer class that holds the maximum possible value for an integer, which is 2,147,483,647....
🌐
W3Schools
w3schools.com › java › ref_math_max.asp
Java Math max() Method
System.out.println(Math.max(2.0, ... 22)); System.out.println(Math.max(96L, 2048L)); ... The max() method returns the number with the highest value from a pair of numbers....
Find elsewhere
🌐
Reddit
reddit.com › r/learnjava › beginner here; please help with explaining why integer.max_value and integer.min_value is assigned as values in this code.
r/learnjava on Reddit: Beginner here; please help with explaining why Integer.MAX_VALUE and Integer.MIN_VALUE is assigned as values in this code.
July 4, 2022 -

I was searching for a way to find the min and max value within a number of integers and I came across this code:

Scanner in = new Scanner(System.in);

int maxNum = Integer.MIN_VALUE;
int minNum = Integer.MAX_VALUE;
while (scanner.hasNextInt()) {
  int num = scanner.nextInt();
  maxNum = Math.max(maxNum, num);
  minNum = Math.min(minNum, num);
}

System.out.println("The maximum number: " + maxNum);
System.out.println("The minimum number: " + minNum);

I am struggling to wrap my mind around Integer.MAX_VALUE and Integer.MIN_VALUE. Why are they assigned as values and how does it work with the Math. min & max methods. Why is the variable maxNum assigned the value Integer.MIN_VALUE and minNum assigned the value Integer.MAX_VALUE?

Thanks.

Top answer
1 of 3
3
Think of only one, you are looking for the lowest number in an array, you take the first number and compare it to your minValue, if it is smaller you choose that as new minValue and try the next. If you start minValue as the absolute MIN_VALUE, it will never find a smaller number in your array. SO you should start minValue as higher as possible and maxValue as lover. (Or you can just initiate them as the first number in your array)
2 of 3
1
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 - best also formatted as code block 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. 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/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) 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.
🌐
Baeldung
baeldung.com › home › core concepts › programming › maximum value of an integer: java vs c vs python
Maximum Value of an Integer: Java vs C vs Python | Baeldung on Computer Science
March 18, 2024 - Here’s some real code to directly check what we’ve discussed so far. The code will demonstrate the maximum and minimum values of integers in each language.
🌐
Baeldung
baeldung.com › home › java › java collections › finding max/min of a list or collection
Finding Max/Min of a List or Collection | Baeldung
April 4, 2025 - To determine the minimum or maximum value in an ArrayList, we can either use the method we saw earlier or the min() and max() methods of the Java Collections class.
🌐
Programiz
programiz.com › java-programming › library › math › max
Java Math max()
Become a certified Java programmer. Try Programiz PRO! ... The max() method returns the maximum value among the specified arguments.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › max
Java Math max() - Find Maximum Value | Vultr Docs
December 3, 2024 - The Math.max() function in Java offers a straightforward way to find the maximum value between two numbers. Ideal for applications across a broad spectrum of domains, this method enhances code efficiency and readability by abstracting away the need for manual comparisons.
🌐
GeeksforGeeks
geeksforgeeks.org › java › integer-max_value-and-integer-min_value-in-java-with-examples
Integer.MAX_VALUE and Integer.MIN_VALUE in Java with Examples - GeeksforGeeks
July 12, 2025 - Integer.MAX_VALUE Integer.MAX_VALUE is a constant in the Integer class of java.lang package that specifies that stores the maximum possible value for any integer variable in Java.
🌐
Educative
educative.io › answers › what-is-integermaxvalue
What is Integer.MAX_VALUE?
Integer.MAX_VALUE represents the maximum positive integer value that can be represented in 32 bits (i.e., 2147483647). This means that no number of type Integer that is greater than 2147483647 can exist in Java.
🌐
Code Like A Girl
code.likeagirl.io › what-happens-when-you-add-1-to-integer-max-value-in-java-09020d0906a7
What Happens When You Add 1 to Integer.MAX_VALUE in Java | by Nouhaila El Ouadi | Code Like A Girl
October 23, 2024 - When you add 1 to Integer.MAX_VALUE (2,147,483,647), there's no more room to store the result within the 32 bits available for an int. Join Medium for free to get updates from this writer. ... This binary number represents -2,147,483,648 in two’s ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-get-size-minimum-and-maximum-value-of-data-types-in-java
How to Get Size, Minimum, and Maximum Value of Data Types in Java? - GeeksforGeeks
Value 1 Byte 8 -128 127 2 Short 16 -32768 32767 3 Integer 32 -2147483648 2147483647 4 Float 32 1.4E-45 3.4028235E38 5 Long 64 -9223372036854775808 9223372036854775807 6 Double 64 4.9E-324 1.7976931348623157E308 7 Character 16 · Comment · Article ...
Published   March 28, 2021
🌐
CodeGym
codegym.cc › java blog › java math › java math max() method
Java Math.max() method with Examples
December 5, 2024 - public class Main { public static void main(String args[]) { int x = 40; int y = 60; int z = 75; //Find the maximum among three values using max() function System.out.println(Math.max(z, Math.max(x,y))); } } The output will be 75. The function max() is a simple method in Java that’s very easy to use.
🌐
W3Schools
w3schools.com › java › java_data_types_numbers.asp
Java Numbers
Integer types stores whole numbers, positive or negative (such as 123 or -456), without decimals. Valid types are byte, short, int and long. Which type you should use, depends on the numeric value.
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 389945 › how-to-find-max-value-for-10-integers
java - How to find max value for 10 integers | DaniWeb
October 30, 2011 - The symptom that @subone saw (only the last number printing) comes from consuming all input with repeated calls to nextInt() without storing each value. A later nextInt() does not "replay" earlier tokens; it reads the next token (or blocks). The simplest, robust pattern is: read each integer once, store it (an array is ideal), and update sum, max and min inside the same while loop.
🌐
Oreate AI
oreateai.com › blog › understanding-longmaxvalue-in-java-the-power-of-64bit-integers › 5574addd966c01426e4e7110a32b17c7
Understanding Long.MAX_VALUE in Java: The Power of 64-Bit Integers - Oreate AI Blog
December 24, 2025 - This predefined value represents the upper limit that a long variable can hold—specifically 9 quintillion plus change (or simply put: 2^63-1). Why does this matter? Because remembering such a colossal number isn’t practical for most programmers.