Summary of Java Fundamentals (II.)

Source: Internet
Author: User

This article see: http://www.cnblogs.com/dolphin0520/category/361055.html

1. Byte stream and character stream

1). When a character stream operation uses a buffer, the contents of the buffer are forced to be output when the character stream is closed, but the contents of the buffer cannot be exported if the program is not closed.

2). The character stream uses a buffer, and the byte throttle does not use a buffer.

3). The buffer can be simply understood as a region of memory.

2. Typical garbage collection algorithms:

1). Mark-sweep (Mark-Clear) algorithm

2). Copying (copy) algorithm

3). Mark-compact (marker-collation) algorithm

4). Generational Collection (generational collection) algorithm

5). In general, large objects will be directly allocated to the old age, the so-called large object refers to the need for a large number of contiguous storage space objects, the most common large object is a large array, such as: byte[] data = new byte[4*1024*1024]? This general will

Allocate storage space directly in the old age.

6). Of course, the rules for allocation are not completely fixed, depending on which garbage collector combination is currently being used and the relevant parameters of the JVM.

7). The determination of rubbish:

A. Reference counting: This approach is characterized by simplicity and high efficiency, but it does not solve the problem of circular references, so this is not the case in Java (Python uses the reference notation).

B. Accessibility analysis: The basic idea of this method is to search through a series of "GC Roots" objects as a starting point, and if there is no unreachable path between "GC Roots" and an object, the object is said to be unreachable, but it is important to note that it is determined

Objects that are unreachable do not necessarily become recyclable objects. An object that is judged unreachable must undergo at least two marking processes to become a recoverable object, and if there is still no possibility of escaping from being a recyclable object during these two marks, the basic

is really a recyclable object.

Reference: http://www.cnblogs.com/dolphin0520/p/3783345.html

3. Static:

1). Makes it easy to invoke (method/variable) without creating an object.

2). Static can be used to modify member methods of a class, member variables of a class, and you can write static code blocks to optimize program performance.

3). The static keyword in Java does not affect the scope of a variable or method. The only private, public, protected (including package access rights) keywords that can affect access in Java.

4). Static modified methods and variables can be preceded by a permission modifier.

5). Static member variables, while independent of the object, do not mean that they cannot be accessed through the object, and all static and static variables can be accessed through the object (as long as access rights are sufficient).

6). Static member variables and static statement blocks are executed in the same order as in the code.


4. Classes and Inheritance:

1). In the process of generating an object, the member variables of the object are initialized before the constructor is executed. This means that the variables in the class are initialized before any methods (including constructors) are called, even if the variables are strolling between the method definitions.

2). Subclasses are constructors that cannot inherit the parent class, but note that if the constructor of the parent class is parameterized, the constructor of the parent class must be called with the Super keyword in the constructor of the child class and be accompanied by the appropriate argument list.

If the parent class has a parameterless constructor, it is not necessary to call the parent class constructor with the Super keyword in the subclass's constructor, and if the Super keyword is not used, the system automatically calls the parent class's parameterless constructor.

3). The constructor invocation of the parent class and the initialization process must precede the subclass.

4). Hide and overwrite are different. Shadowing is for member variables and static methods, and overrides are for common methods. if: parent p = new Child (), the p.name result is the value of the member variable name in the parent class.

5). Overrides are only for non-static methods (the end-state method cannot be inherited, so there is a overwrite), and the shadowing is for member variables and static methods. The difference between the 2 is: Overwrite by rtti (Runtime type identification)

Constrained, but hidden from the constraint. This means that only the overlay method will be dynamically bound, and the shadowing will not occur dynamically. In Java, all other methods, except the static method and the final method, are dynamically bound.

5. Deep understanding of Java interfaces and abstract classes

1). The abstract method must be public or protected (because if you are private, you cannot inherit from the quilt class, the subclass cannot implement the method), and by default it is public.

2). The variables in the interface are implicitly specified as public static final variables (and can only be public static final variables), and methods are implicitly specified as public abstract methods and can only be public abstract methods ,

And all the methods in the interface cannot have a concrete implementation, that is, the methods in the interface must all be abstract methods.

3). Abstract class is an abstraction of a thing, that is, an abstraction of a class, and an interface is an abstraction of a behavior.

4). If you need to add a new method, you can directly add a specific implementation in the abstract class, the subclass can not be changed, but for the interface is not, if the interface has been changed, all implementations of this interface must be modified by the corresponding class.

6. Final:

1). When a class is decorated with final, it indicates that the class cannot be inherited. All member methods in the final class are implicitly specified as the final method.

2). Set the method to final only if you want to explicitly prohibit the method from being overwritten in subclasses.

3). For a final variable, if it is a variable of the base data type, its value cannot be changed once initialized, and if it is a variable of a reference type, it cannot be pointed to another object after it has been initialized.

4). When the final variable is the base data type and the string type, if you know its exact value during compilation, the compiler uses it as a compile-time constant. In other words, where the final variable is used, it is equivalent to

This constant, which is accessed directly, does not need to be determined at run time. The compiler does this optimization only if the final variable value is known exactly during compilation

Summary of Java Fundamentals (II.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.