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
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
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
write a simple program that displays 4 python primitive data types sizes in bytes run the...
write a simple program that displays 4 python primitive data types sizes in bytes run the program on a command prompt CMD. attach a photo of the source file in the text editior and the excutable on CMD ex; the size of int in bytes is ... the size of floot in bytes is ... the size of string in bytes is ... the size of char in bytes is ....
Describe how someone who is mandated psychological services, may act differently than someone who receives voluntary...
Describe how someone who is mandated psychological services, may act differently than someone who receives voluntary psychological services. Discuss the role of extrinsic and intrinsic motivation.
Do you believe drug users are socialized differently? If so, indicate how they are socialized differently?...
Do you believe drug users are socialized differently? If so, indicate how they are socialized differently? If not, discuss what factors you believe have influenced the individual to use drugs.