Conditional statements
& | Can be used as a conditional statement, but it is a long connection, and both left and right expressions must be executed! This and && | | Different,&& and | | is a short connection, as long as the expression on the left has been able to calculate the result of the entire expression, the right expression will not be executed!
Inherited, overloaded, polymorphic
Overloading and polymorphism are not a concept:
Overloading: in-class, horizontal relations; Two method names are the same, but different parameters, the return type can be different (but not only the return type), access permissions can be different (because there is no more relationship between overloaded two methods, inheritance and polymorphism independent).
Polymorphic: A longitudinal relationship between classes (parent and subclass) , inherited from a method of a parent class, overriding overrides, having the same method name, having the same argument, returning the same type, or being a subclass of that return type (and the subclass guarantees that all the behavior of the parent class can be performed), access permissions are the same or more open.
With regard to the difference in the return type and access permissions, it can be seen from the perspective that the declaration of a subclass cannot affect how the declaration in the parent class is used, because the purpose of polymorphism is to use the parent class as a reference without caring about the implementation of the subclass, so the declaration of the subclass cannot be used in a way that the declaration in the parent class Thus, the return type subclass cannot exceed the declaration of the parent class, and the access permission subclass cannot restrict the declaration of the parent class.
Call Method:
The compiler depends on the reference type to determine which method can be called, not the actual type of the object. However, when you call the version, the most recent version is found based on the object's true type.
Why is it allowed to create object objects?
Super, this
Each constructor can choose to call Super () or this (), but it cannot be called at the same time, and they must be the first statement of the constructor (the parent class constructor is the first step of the subclass constructor, and the parent class must be constructed before the child class).
Output formatting
Normal formatting
Formatting instructions:
Example of formatting:%1$,06.1f
1$: Using the 1th parameter (the count is 1 base, that is, the first parameter after the formatted string) is formatted as a floating-point number;
Use "," to separate the integer part;
06: The integer part is at least 6 characters, the insufficient part is padded with 0;
.1: A decimal number is retained after the decimal point;
F: floating point number;
date Formatting (String.Format (...) )
Formatting "" "means reusing previously used parameters
Date class
Java.util.Calendar:set (...) The month in is zero-based, so 0 represents January, and set is delayed.
Abnormal
Try/catch is used to deal with real exceptions, which programmers cannot predict or prevent, rather than logic errors of the program, while RuntimeException is mostly a logic problem for the program and is a non-check exception (unchecked, the compiler does not check).
Input/OutputStreaming (Inputstream/outputstream)
Design principles:
Object-oriented design: Each class can do just one thing.
So Java's input/output API has a connection-type stream that represents the link between the source and the destination, and the connection stream connects the stream to the other streams.
In general, it makes sense for a stream to be 22 connected-one representing the connection (the source of the input or the destination of the output) and the other representing the method to be called (the high-level API, which reads out the true high-level data type or outputs the true high-level data).
For example, FileOutputStream is used to write bytes to a file, but usually we do not write directly, but we write at the object level, so high-level connection streams are required to handle high-level object data to the byte stream.
This makes it possible to achieve maximum adaptability through different combinations without having to consider all possible situations in a stream class (which is not possible).
Serialization of
Generic type
Class ChildClass extends Superclass {...} public void f (list<? extends superclass> List) {list.get (0);//OK List.add (new ChildClass ());//Wrong} This is To: public <t extends superclass> void f (list<t> List) {list.get (0);//OK List.add ((T) New ChildClass ()) ;}
Head First Java