eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Spring Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Spring Sale. All Courses are 30% off until 31st March, 2026

>> EXPLORE ACCESS NOW

Partner – Diagrid – NPI EA (cat= Testing)
announcement - icon

In distributed systems, managing multi-step processes (e.g., validating a driver, calculating fares, notifying users) can be difficult. We need to manage state, scattered retry logic, and maintain context when services fail.

Dapr Workflows solves this via Durable Execution which includes automatic state persistence, replaying workflows after failures and built-in resilience through retries, timeouts and error handling.

In this tutorial, we'll see how to orchestrate a multi-step flow for a ride-hailing application by integrating Dapr Workflows and Spring Boot:

>> Dapr Workflows With PubSub

Course – Spring Sale 2026 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our Spring Sale. All Courses are 30% off until 31st March, 2026

>> EXPLORE ACCESS NOW

1. Introduction

There are instances when we need to work with primitive types and their corresponding wrapper classes in Java. When dealing with the int type and its wrapper class Integer, we may come across three different representations. These representations are Integer.class, Integer.TYPE, and int.class. Although they might seem similar at first glance, there are subtle differences between them.

In this tutorial, we’ll explore the differences between these terms and understand their significance in Java programming.

2. Integer.class

Integer.class represents the class object associated with the Integer wrapper class.

We can use it when we need to obtain information about the class itself, such as its name, superclass, interfaces, methods, and fields.

Furthermore, we can use it for reflection-related operations, like creating new instances dynamically or invoking methods at runtime.

Here’s an example demonstrating the usage of Integer.class:

@Test
public void givenIntegerClass_whenGetName_thenVerifyClassName() {
    Class<Integer> integerClass = Integer.class;
    Assertions.assertEquals("java.lang.Integer", integerClass.getName());
    Assertions.assertEquals(Number.class, integerClass.getSuperclass());
    Assertions.assertFalse(integerClass.isPrimitive());
}

Here, we obtain the class object for Integer using Integer.class, allowing us to perform various operations on it.

For example, calling getName() on the class returns “java.lang.Integer”. Another useful method is getSuperclass(), which allows us to obtain the superclass of a class. This helps to identify the inheritance relationship with the Number class.

3. Integer.TYPE

Integer.TYPE is a special constant in Java that represents the primitive type int. We can use Integer.TYPE to distinguish between primitive types and their corresponding wrapper classes. This distinction becomes particularly important in scenarios involving method overloading.

Let’s illustrate the usage of Integer.TYPE with an example:

int sum(int a, int b) {
    return a + b;
}

int sum(Integer a, Integer b) {
    return a + b;
}

int sum(int a, Integer b) {
    return a + b;
}

In the above code, we created three overloaded sum() methods. The first sum() method takes two int primitive values and returns their sum. The second sum() method takes two Integer wrapper objects and returns their sum. The third sum method takes an int primitive value and an Integer wrapper object and returns their sum.

Let’s verify the sum of values when dealing with int and Integer types.

@Test
public void givenIntAndInteger_whenAddingValues_thenVerifySum() {
    int primitiveValue = 10;
    Integer wrapperValue = Integer.valueOf(primitiveValue);
    Assertions.assertEquals(20, sum(primitiveValue, primitiveValue));
    Assertions.assertEquals(20, sum(wrapperValue, wrapperValue));
    Assertions.assertEquals(20, sum(primitiveValue, wrapperValue));
    Assertions.assertEquals(Integer.TYPE.getName(), int.class.getName());
}

The main usage of the given test case is to distinguish between int primitive types and their corresponding Integer wrapper classes, which is crucial in scenarios involving method overloading.

The provided code snippet contains three assertions that verify the correct functioning of different sum() methods. The first assertion checks if the sum() method correctly adds two int primitive values, ensuring that the expected sum of 20 is returned. Similarly, the second assertion tests the sum() method with two Integer wrapper objects, expecting a sum of 20. Lastly, the third assertion validates the sum() method that takes both an int primitive value and an Integer wrapper object, confirming that it correctly computes the sum and returns the expected result of 20.

These assertions collectively ensure the proper distinction between the int primitive type and the Integer wrapper class in the overloaded sum() methods.

The code also compares the class name of int.class (which represents the int primitive type) with the class name of Integer.TYPE. The assertEquals() method asserts that both class names are equal.

4. int.class

int.class represents the class object associated with the int primitive type. To be specific, it can be used when we need to refer to the primitive type itself explicitly.

This is particularly useful in scenarios where we want to check the type of a variable or parameter. Furthermore, it allows us to perform type-specific operations directly on the primitive type.

Let’s see the usage of int.class with an example:

@Test
public void givenIntClass_whenUsingIntClass_thenVerifyIntClassProperties() {
    Class<?> intClass = int.class;
    Assertions.assertEquals("int", intClass.getName());
    Assertions.assertTrue(intClass.isPrimitive());
    Assertions.assertEquals(int.class, intClass);
}

In this example, we retrieve the class object for intValue using the getClass() method. Although intValue is a primitive int, the getClass() method returns the corresponding wrapper class java.lang.Integer. To compare it with the primitive type int, we use int.class and verify that they match.

5. Differences Between Each Type

The following table summarizes the key distinctions between Integer.class, Integer.TYPE, and int.class:

Integer.class Integer.TYPE int.class
Represents The class object associated with the Integer wrapper class int primitive type associated with the Integer wrapper class The class object associated with the int primitive type
Usage Reflection-related operations, obtaining class information, creating instances dynamically Distinguishing between method overloading with Integer and int parameters Type-specific operations directly on the int primitive
Example Usage Integer.class.getName() returns java.lang.Integer Integer.TYPE.getName() returns int int.class.getSimpleName() returns int
Reflection Used to access information about the class, such as name, superclass, methods, and fields Not applicable, as it represents the primitive type, not a class Can be used to access information about the class through several methods such as getName(), getModifiers(), getSuperclass(), and so on
Type Checking Integer.class.isPrimitive() returns false Not applicable, as it represents the primitive type, not a class int.class.isInstance() can be used to perform type checks to determine if an object is of the int type.
Method Overloading Not directly related to method overloading Used to distinguish between Integer and int parameters in overloaded methods Not directly related to method overloading
Performance Involves the overhead of working with wrapper objects No overhead, as it represents the primitive type directly No overhead, as it represents the primitive type directly

6. Conclusion

In this article, we’ve explored the concepts of Integer.class, Integer.TYPE, and int.class in Java. Understanding these concepts empowers us to work efficiently with primitive types and their wrapper classes.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Spring Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Spring Sale. All Courses are 30% off until 31st March, 2026

>> EXPLORE ACCESS NOW

Course – Spring Sale 2026 – NPI (All)
announcement - icon

Yes, we're now running our Spring Sale. All Courses are 30% off until 31st March, 2026

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments