Home » Java » Thinking in Java- notes

Thinking in Java- notes

1.P27 you have a reference, is not necessarily associated with an object and the like. Relationship between references and objects, remote controller and television (the book), with a bridle (- Reference) and MA (-new out) (thinks).

--------------- self play ---------------

String s = null; / / equivalent to find a bridle, the bridle is used for horses (defined type), named s, in my pocket (stack), do not use.

new String ("I am instance 1"); / / equivalent in grassland (heap) found a horse, that is found in , you can't control it (anonymous object).

s=new String ("I am instance 2"); / / equivalent to find a horse, and with s > ( S.contains ("a");

s=new, String ("I am instance 3"); //, the bridle s can trap any horse, not the horse, and a.


2.P28 Java are stored in the heap, even if there are objects of type static, are not stored in static storage space. (this guy horse cannot be placed in the house, should let it run, in the grasslands of special and horse, and Ma Ya.

The basic type of

3.P29 is relatively small, and simple to put objects in a heap with new is not efficient, so it's better to store it in the stack than.

basic type + reference on the stack, equivalent to cats, dogs, small animals, in the house with.

objects used in the heap, equivalent to cattle and sheep, large animals, on the grassland to raise.

4.P30 BigInteger supports arbitrary precision integer.BigDecimal, supports any precision floating-point number.



String, s = new, String ("a string"),



reference s disappears at the end of the scope, but the String object referred to by s continues to occupy memory space.

6. P33, when a variable is used as a member of a class, Java ensures that its default value is given to ensure that the variable is initialized.


7.P35 package name is lowercase. There has been a problem in history,.

An important use of the

8. static method is to invoke it without creating any object. (for example, the method of the tool class, Math.random ()).


9. P39 java.lang is automatically imported into each of the java files,.

System.out is a static object of type PrintStream,.