CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Integers In Java

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor
  • Home

Integers In Java

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 ยท 3 min read ยท 0 Comments
Share: in X

Integers in Java is a primitive data type. It is used to represent whole numbers. It is denoted by the keyword int. The int type is a signed 32-bit value.

It can hold integers ranging from -2,147,483,648 to 2,147,483,647.

Hence,

The minimum value of Integer is -2,147,483,648 and the maximum value an integer can hold is 2,147,483,647.

Table of Contents

Declaration and Initialization
Arithmetic Operations
Integer Overflow and Underflow
Integer Literals
Integer Wrapper Class

Declaration and Initialization

We can declare an integer variable by specifying the int keyword, followed by the variable name. For example:

int rollNumber;

We can also initialize the variable at the time of declaration:

int rollNumber = 10;

Arithmetic Operations

  • Integer support basic arithmetic operations, such as addition (+), subtraction (-), multiplication (*), and division (/).
  • The result of arithmetic operations involving integers will be an integer, and any fractional part will be truncated (rounded down).
  • Integer division (/) between two integers will yield the quotient, discarding any remainder

Following is an example of using the int data type in a Java program that sums the two variables:

public class Main {
  public static void main(String[] args) {
    int x = 10;
    int y = 20;
    int sum = x + y;
    System.out.println("The sum of x and y is: " + sum);
  }
}

Output:

The sum of x and y is: 30

Integer Overflow and Underflow

  • Since int is a fixed-size data type, it has a range of representable values. If an arithmetic operation results in a value outside this range, it will cause an overflow or underflow.
  • Overflow occurs when a value exceeds the maximum representable value, while underflow occurs when a value goes below the minimum representable value. These operations are considered undefined behavior in Java.

Integer Literals

  • Integer literals can be specified in Java using decimal, octal, or hexadecimal notation.
  • Decimal literals are represented in base 10 (e.g., 10, 123).
  • Octal literals are represented with a leading 0 followed by octal digits (e.g., 012, 077).
  • Hexadecimal literals are represented with a leading 0x or 0X, followed by hexadecimal digits (e.g., 0xA, 0xFF).

Example:

  • The decimal equivalent of the hexadecimal value 0xA is: 10

You can test it by directly printing this value.

System.out.println(0xA); // 10
  • Similarly, the decimal equivalent of the hexadecimal value 0xFF is: 255. You can use lowercase values. Like: 0xff the output will be the same.

Integer Wrapper Class

  • Java also provides a corresponding wrapper class for the int primitive type called Integer.
  • The Integer class provides useful methods to perform operations on integers, convert strings to integers, and vice versa.
  • Integer wrapper class default value in Java is null.

If you need to represent larger numbers or require more precision, you can use other numeric types in Java, such as long (for larger integers) or double (for decimal numbers).

Frequently Asked Questions

What are integers in Java?

Integers are a fundamental data type in Java used to represent whole numbers, both positive and negative, without fractional parts.

How many types of integers are there in Java?

Java provides four integer types: byte, short, int, and long, which vary in size and can hold different ranges of values.

What is the default value of an uninitialized integer variable in Java?

The default value for uninitialized integer variables in Java is 0.

What is integer overflow in Java?

Integer overflow occurs when an operation on integers results in a value that exceeds the maximum range of the data type, causing unexpected behavior.

How can I convert other data types to integers in Java?

You can use type casting or the appropriate conversion methods, such as Integer.parseInt() for strings, to convert other data types to integers in Java.

Related Posts:

  • Primitive data types in Java
  • Arrays of Primitive Types in Java
  • Character data type in Java
  • java.lang.Long Class in Java
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • final Keyword in Java
Tags:javalanguage-fundamentals
Was this article helpful?
โ† Previous ArticleJDBC CachedRowSet Example
Next Article โ†’Floating point in Java

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
ยฉ 2026 CoderSathi. All rights reserved. Privacy Policy ยท Sitemap