- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the differences between an Integer and an int in Java?
Integer (Wrapper class) and int (primitive data type)
- The major difference between an Integer and an int is that Integer is a wrapper class whereas int is a primitive data type.
- An int is a data type that stores 32-bit signed two’s complement integer whereas an Integer is a class that wraps a primitive type int in an object.
- An Integer can be used as an argument to a method that requires an object, whereas int can be used as an argument to a method that requires an integer value, that can be used for arithmetic expression.
- An int datatype helps to store integer values in memory whereas Integer helps to convert int into an object and to convert an object into an int.
- The variable of int type is mutable unless it is marked as final and the Integer class contains one int value and is immutable.
Example1
public class PrimitiveDataTypeTest { public static void main(String []args) { // Declaration of int int a = 20; int b = 40; int result = a+b; System.out.println("Result is: " + result); } }
Output
Result is: 60
Example2
public class WrapperClassTest { public static void main(String []args) { int a = 20; Integer b = Integer.valueOf(a); System.out.println("Converted Value of b is: " + b); Integer c = new Integer(30); int d = c.intValue(); System.out.println("Converted Value of d is: " + d); } }
Output
Converted Value of b is: 20 Converted Value of d is: 30
- Related Articles
- Difference between an Integer and int in Java
- What are the differences between an application and an applet in Java?
- What are the differences between an Exception class and an Error class in Java?
- What are the differences between a class and an interface in Java?
- What are the differences between an event listener interface and an event adapter class in Java?
- What is the difference between int and integer in MySQL?
- What are the differences between a dictionary and an array in C#?
- What are differences between a gated community and an apartment?
- What are the differences between C++ and Java?
- What are the differences between C and Java?
- What are the differences between a list collection and an array in C#?
- What is the difference between an int and a long in C++?
- What are the differences between Java classes and Java objects?
- What are the differences between ClassNotFoundException and NoClassDefFoundError in Java?
- What are the differences between recursion and iteration in Java?

Advertisements