reference type vs primitive type

int a = 11; // Primitive Type 

Integer b = new Integer(11); // Reference Type 

5
1
Ak2817 90 points

                                    // The value of primitive data types are directly stored in the memory.
// For example if int a is initilized to 11, then 11 is directly stored
// in the memory.
int a = 11; // Primitive Type 

// Reference types on the other hand are a reference to values in the
// memory. For example Integer(11) creates a reference in the memory
// whever the value 11 is stored and passes that memory reference/
// (address) to the variable.
Integer b = new Integer(11); // Reference Type 

5 (1 Votes)
0
4.5
2

                                    +================+=========+===================================================================================+
| Primitive type | Size    | Description                                                                       |
+================+=========+===================================================================================+
| byte           | 1 byte  | Stores whole numbers from -128 to 127                                             |
+----------------+---------+-----------------------------------------------------------------------------------+
| short          | 2 bytes | Stores whole numbers from -32,768 to 32,767                                       |
+----------------+---------+-----------------------------------------------------------------------------------+
| int            | 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647                         |
+----------------+---------+-----------------------------------------------------------------------------------+
| long           | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
+----------------+---------+-----------------------------------------------------------------------------------+
| float          | 4 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits           |
+----------------+---------+-----------------------------------------------------------------------------------+
| double         | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits               |
+----------------+---------+-----------------------------------------------------------------------------------+
| char           | 2 bytes | Stores a single character/letter or ASCII values                                  |
+----------------+---------+-----------------------------------------------------------------------------------+
| boolean        | 1 bit   | Stores true or false values                                                       |
+----------------+---------+-----------------------------------------------------------------------------------+

4.5 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Explain the difference between a primitive and a reference type. Reference vs Primitive data type what is primitive and reference types java primitive type vs reference type what is the difference between primitive type and reference type in java primitive vs reference data types What is the difference between primitive and reference types? java What is the difference between primitive and reference types? reference types vs primitive types primitive vs reference types is a primitive type a reference type Primitive vs Reference types? Difference between primitive type and reference type? Primitive data types vs primitive types vs reference type vs primitive type java primitive type vs reference type primitive type vs reference type java reference data type vs primitive data type primitive data types vs reference data types reference type primitive primitive vs reference type class type vs primitive When analyzing the relationship between primitive and reference data types, are created from the other. primitive types vs reference types java primitive types vs reference types difference between primitive types and referance types Primitve types vs reference types java java primitive types and reference types java reference type vs primitive Primitive types and reference types primitive type reference type reference type vs primitive type do primitive data types have a reference in java two types in java primitive and ref primitive vs reference primitive vs types primitive variable vs reference variable difference between reference data types and primitive data types? java primitive types vs reference types java data types primitive and reference what is the difference between primitive data type and reference data types differences between primitive and reference variables primitive vs reference types java primitives and references in java char not reference type java reference type of char in java string reference vs primitive What is the difference between primitive variables and reference variables? Primitive Type vs. Reference Type
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source