Head First Java chapter3 (primitives and variables)
首先是每一章里面书中自带总结。
-
Variables come in two flavors: primitive and
reference. -
Variables must always be declared with a name
and a type. -
A primitive variable value is the bits representing
the value (5, ‘a’, true, 3.1416, etc.). -
A reference variable value is the bits
representing a way to get to an object on the
heap. -
A reference variable is like a remote control.
Using the dot operator (.) on a reference
variable is like pressing a button on the remote
control to access a method or instance variable. -
A reference variable has a value of null when
it is not referencing any object. -
An array is always an object, even if the array is declared
to hold primitives. There is no such thing as a primitive array,
only an array that holds primitives.
下面是一些 我认为有必要的摘抄:
rules of name(class, method or variable):
-
It must start with a letter, underscore (_), or dollar sign ($).
You can’t start a name with a number. -
After the fi rst character, you can use numbers as
well. Just don’t start it with a number. -
It can be anything you like, subject to those two
rules, just so long as it isn’t one of Java’s reserved words.
3 steps of object declaration, creation, and assignment:
Dog myDog = new Dog();
- declare a reference variable(等号左边)
- create an object(等号右边)
- link the object and the reference(等号的作用)
一张图理解Java的数组: