惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
V
Visual Studio Blog
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
Vercel News
Vercel News
F
Fortinet All Blogs
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
小众软件
小众软件
月光博客
月光博客
A
About on SuperTechFans

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Wrapper Classes in Java – A Simple Guide
Jayashree · 2026-04-22 · via DEV Community

When we start learning Java, we mostly work with primitive data types like int, char, double, etc. These are fast and efficient. But at some point, we run into situations where primitives alone are not enough. That’s where wrapper classes come into the picture.

What is a Wrapper Class?

A wrapper class is used to convert a primitive data type into an object.

In simple terms, it “wraps” a primitive value inside an object.

For example:

  • int → Integer
  • char → Character
  • double → Double
  • boolean → Boolean

So instead of working with raw values, we can work with objects.

Why Do We Need Wrapper Classes?

You might wonder — why not just use primitives?

Good question. Here are the main reasons:

1. Collections work only with objects

Java collections like ArrayList cannot store primitive types.

ArrayList<int> list;   //  Not allowed
ArrayList<Integer> list; //  Allowed

Enter fullscreen mode Exit fullscreen mode

So we use wrapper classes to store values in collections.

2. Utility Methods

Wrapper classes provide useful methods like:

Integer.parseInt("123");   // converts String to int
Double.valueOf("10.5");    // converts String to Double

Enter fullscreen mode Exit fullscreen mode

These methods make data conversion easy.

3. Object-Oriented Features

Sometimes we need objects instead of primitives—for example, when working with APIs, frameworks, or generics.

Wrapper classes help us follow object-oriented programming concepts.

Autoboxing and Unboxing

Java automatically converts between primitives and wrapper classes.

Autoboxing (primitive → object)
Integer num = 10; // int → Integer

Unboxing (object → primitive)
Integer num = 10;
int value = num; // Integer → int

This makes coding easier and cleaner.

Where Are Wrapper Objects Stored?

Primitive values → stored in stack memory
Wrapper objects → stored in heap memory
Reference variables → stored in stack

Example:

Integer a = 10;

Here:

a is stored in stack
The actual object (10) is stored in heap
Special Case: Integer Caching

Java caches values between -128 to 127.

Integer x = 100;
Integer y = 100;

System.out.println(x == y); // true

Enter fullscreen mode Exit fullscreen mode

Because Java reuses the same object from memory.

But:

Integer x = 200;
Integer y = 200;

System.out.println(x == y); // false

Enter fullscreen mode Exit fullscreen mode

Here, new objects are created.

Final Thoughts

Wrapper classes play a very important role in Java. Even though primitives are faster, wrapper classes give flexibility, especially when working with collections, APIs, and object-based operations.

If you are preparing for interviews, understanding wrapper classes, autoboxing, and memory behavior is a must.