Java Datatypes
Java Datatypes
Long
byte short int
Float double
The compiler won’t let you put a value from a large cup into
a small one. But what about the other way—pouring a
small cup into a big one? No problem.
NO!
Don’t do that
Be sure the value can fit into the variable.
what about non-primitive variables?
■ An object reference variable holds bits that represent a way to access an object.
■ It doesn’t hold the object itself, but it holds something like a pointer. Or an address. Except, in Java we don’t
really know what is inside a reference variable. We do know that whatever it is, it represents one and only one
object. And the JVM knows how to use the reference to get to the object.
For eg
byte x = 7; Scenario 1:
The bits representing 7 go
into the variable. (00000111). Book A =new Book();
Book B =new Book();
Reference Variable Book C =B;
Dog myDog = new Dog();
The bits representing a way to get to
the Dog object go into the variable. Scenario 2:
The Dog object itself does not go into
the variable Book A =new Book();
Book B =new Book();
A=B;