Java data types are divided into primitive data types and reference data types.
The primitive data types in Java are divided into four classes and eight kinds. Primitive also do not know how to translate more appropriate, call him the basic data type bar, in fact, directly from the literal meaning of English understanding easier.
Primitive data types include: boolean, char , Integer, float. The integral type also includes: Short, Byte, int, long . Float type also includes:float, double .
All primitive are eight species in total. Size: Boolean (determined by JVM) char (BITS) short (BITS) byte (8 bits) int (64bits) float (zero bits)
In addition to the basic data types, all that is left in Java is references (reference).
In general, there are three steps to declaring, assigning, and creating objects: In a simple small example:
Dog Mydog = new Dog (); In this sentence we can create a dog object (Mydog), and later see this new statement must have three steps in mind to put it together:
- Step1: dog Mydog = new Dog (); Executes the red part of the statement, declares a reference Mydog(requires the Java Virtual machine to allocate space on the stack to the reference variable, and named Mydog, this reference variable will always be fixed to the dog type)
- Setp2:dog Mydog = new Dog (); Executes the red part of the statement, creating an object (requires the Java Virtual machine to allocate space on the heap to the dog object)
- Setp3:dog Mydog = new Dog (); Executes the "=" symbol in the statement, connecting the object and the reference (assigning the Dog object to the Mydog reference)
Here is a special object that needs to be specifically explained, that is, arrays, yes, arrays are also objects ! The creation of the array object is as follows: (Picture truncated from headfirst Java)
Data types and references in Java