Skip to content

Java int | Range & Size | Primitive Data Type | Examples

  • by

Java int is Primitive Data Type, and Integer is a wrapper class. In Java, all data types variables must first be declared before they can be used.

If you think about Java int is the same as a number, you might be right or wrong because in programming it about memory allocation of particular variables. So Number further has divided into data types like int, long, double float, etc.

Java int Range & Size Primitive Data Type Examples

Where Java int default values are “0“. and the size is 16 bits.

Java int range

It has a minimum value of –2,147,483,648 and a maximum value of 2,147,483,647 (inclusive).

Java int example

Here is a simple example of how to create an int variable in Java and print the value.

class Hello {
    public static void main(String args[]) {

        int a = 546;
        System.out.println(a);
    }
}

Output: 546

How to do check number is equal or not?

Here is code to check whether 2 numbers (int) are equal or not. If equal then the output will be true else false.

class Hello {
    public static void main(String args[]) {

        int a = 546;
        int b =78;
        System.out.println( a == b);

    }
}

Output: false

QA: Is it possible to assign the value in int beyond its maxed values? And What if integer beyond its max value?

It’s not possible, will throw an error: Error:(4, 17) java: integer number too large

Error output Screenshot:

Java int, What if integer beyond its max value error

This tutorial is short and simple for beginners, if you have any doubts and suggestions then do comment.

Note: This example (Project) is developed in IntelliJ IDEA 2018.2.6 (Community Edition)
JRE: 11.0.1
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.1

Java version 11

All Java Data Types Examples are in Java 11, so it may change its different from Java 9 or 10 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading