One thousand Feng JAVA day 21 after-school review

Shiqianfeng class against the war,
the war against Shiqianfeng classes to learn the first 21 days
"to learn the benefits of java, that is not the object may be a new"
China refueling, refueling Wuhan, Qian Feng refueling, I cheer myself
today learned about packaging and contents of the string
class Object:

  1. The concept:
    I. superclass, base class for all classes of direct or indirect parent class, located inheritance tree top level.
    II. Any kind, such as not writing extends to inherit a class display, by default the direct successor to the Object class, or inherit indirect.
    Method III. Object class, as defined, includes all method objects.
    . IV Object can store any type of objects:
    1) as a parameter, a pharmaceutically any object.
    2) as a return value, to return any object.

  2. Common methods:
    I. Final public Class getClass () {} <?>
    Returns the actual object type stored in the reference.
    Application: Typically two references for determining the type of the object is actually stored are the same.

II. Public int hashCode () { }
a target integer expressions (integer name).
Returns the hash code value for this object decimal.
The calculated hash algorithm address of the object or character string or a numerical value type int.
Hash code is not unique, the same subject may be guaranteed to return the same hash code, return to try to ensure that different objects of different hash codes.

III. Public String toString () { }
Returns a string representation of the object (manifestation).
The program can override this method needs, such as: the attribute values of the respective display objects.

IV. Public boolean equals (Object obj ) {}
default implementations for (this == obj), the address compare two objects are the same.
Can be covered, compare the contents of two objects are the same.

V. covered equals the order:
1) comparing two references point to the same object.
2) whether obj is null.
3) determining two reference points of the actual object are the same type.
4) cast.
5) sequentially comparing each attribute value are the same.

VI. Protected void finalize () throws Throwable // understood (in the interview questions may have pits)
when the object is determined to be garbage objects, this method is called automatically by the JVM for marking garbage objects, into a recovery queue.
Garbage Object: No valid reference point to the object, the object is garbage.
Garbage Collection: garbage objects destroyed by the GC, the release of data storage space.
Automatic recovery mechanisms: JVM memory is exhausted, a one-time recovery of all garbage objects.
Manual collection mechanism: using System.gc (); informing the JVM garbage collection.
Packaging:

  1. Concept:
    I. basic types corresponding reference type
    II Object can unify all the data, package the default value is null.
    III packaging in fact holds a primitive type, as storage data (Byte. byte has a property), also it provides a common method of transformation, and constants,
    may be stored values, also have a number of common methods and transformation constants, more powerful than using basic types of functions.
    IV. Packaging type provides several methods of transformation, allowing mutual conversion between themselves and other types of packaging types, basic types, string.

  2. Transformation method:
    I. 8 Zhong packaging types, there are six kinds of digital type (Byte, Short, Integer, Long , Float, Double), java.lang.Number inherited from the parent class.
    II. Java.lang.Number parent of all subclasses are provided six transformation method to convert themselves into other types of digital type.
    o byteValue ();
    shortValue ();
    intValue ();
    longValue in ();
    o floatValue ();
    doubleValue in ();

. III parseXXX (String s) transformation static method, there are eight kinds of package types
parseByte ( "123");
parseShort ( "123");
the parseInt ( "123");
parseDouble ( "123.45");
...

. IV valueOf (basic type), valueOf (string type), static transformation method, the type of packaging has eight kinds
Byte B1 = Byte.valueOf ((byte) 10);
Byte B2 = Byte.valueOf ( "20 is");

V. Note: When using a string to build the package type of the object, to ensure compatible types, otherwise generate NumberFormatException.

. VI After JDK5, provides automatic packing, unpacking, simplify the programming process using the wrapper class
Byte b4 = 40; // autoboxing, assign primitive types directly to packaging type
byte b5 = b4; // automatic unpacking, the value of the package type, directly assigned to the basic types

VII. When auto-boxing, calls the valueOf method, Byte, Short, Integer, Long, four kinds of integer type of packaging provides the corresponding cache buffer, the commonly used 256 numbers to create an object in advance and stored in the array to achieve multiplexing. That is, in the interval of reusing existing objects and create new objects outside the range.

Released three original articles · won praise 0 · Views 145

Guess you like

Origin blog.csdn.net/qq_40091389/article/details/104621207