Question

How are primitive types treated differently than reference types in Java?

How are primitive types treated differently than reference types in Java?

Homework Answers

Answer #1

There are two types of variables in java

primitive (int,float, etc)
reference (class,interface etc)

the main difference between primitive and reference types is primitive type has always a value
and can never be null but reference type can be null.

if you dont assign a value to primitive type it will 0 but reference variable by default has null
if you try to access it it will throw a null pointer exception

assignment operator working on primitive and reference type

primitve values are created in the stack while reference values are created in heap.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java passes arguments by value. Which of the following correctly describes how variables are passed to...
Java passes arguments by value. Which of the following correctly describes how variables are passed to a method? Select one: Both primitive and object types are passed by the value that they refer to in memory. Primitive types are passed by reference while object types are passed by values stored at the object location in the memory. A variable is passed to a method and its value will no longer exist within the scope of where the method was originally...
accounting items are treated differently under tax legislation than under accounting standards
accounting items are treated differently under tax legislation than under accounting standards
Thinking about Culture Diversty When and how did you become aware of people being treated differently...
Thinking about Culture Diversty When and how did you become aware of people being treated differently because of race, culture, or religion? Explain.
Consider a one-dimensional Bravais lattice with two ions per primitive cell, with N primitive cells in...
Consider a one-dimensional Bravais lattice with two ions per primitive cell, with N primitive cells in total. How many phonon types are there in the lattice
Write Java code that creates an array of primitive integers named odds and stores all odd...
Write Java code that creates an array of primitive integers named odds and stores all odd numbers between -6 and 38 using a for loop. (Your code will populate the array.) Your code should also enable the array’s size to be exactly large enough to store the numbers. (You will not put a number for the size, your code will determine the number.) (5 pt)
why is the volume of the primitive unit cell smaller than the conventional unit cell? What...
why is the volume of the primitive unit cell smaller than the conventional unit cell? What are the primitive vectors of the fcc (face centered cubic)
What causes cells to look and act differently from other types of cells?
What causes cells to look and act differently from other types of cells?
How do accountants treat the timing of cash flow transactions differently than finance people do?
How do accountants treat the timing of cash flow transactions differently than finance people do?
Explain how cash dividends affect individual shareholders differently than an equal amount of funds spent on...
Explain how cash dividends affect individual shareholders differently than an equal amount of funds spent on a repurchase.
Why is freight-in accounted for differently than freight-out? Identify the difference in accounting and explain how...
Why is freight-in accounted for differently than freight-out? Identify the difference in accounting and explain how principles or definitions from the Conceptual Framework for Financial Reporting are involved
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT