Summary of Java Review

Source: Internet
Author: User

Java Review Summary naming method

The name of the created file should match the name of the class, or it will be an error.

Class is named in uppercase letters, and if it is the class name of multiple words, the first letter of each word is capitalized, for example: HelloWorld.

The method uses the Hump naming method, that is, the second letter begins with uppercase.

Typically, a company uses its Internet domain name in reverse form as its package name.

Abstract class Summary provisions
    • Abstract classes can not be instantiated (beginners are prone to make mistakes), if instantiated, will error, compile cannot pass. Only non-abstract subclasses of abstract classes can create objects.
    • Abstract classes do not necessarily contain abstract methods, but classes with abstract methods must be abstract classes.
    • Abstract methods in abstract classes are only declarations, do not contain method bodies, that is, the concrete implementation of the method is the specific function of the method.
    • A constructor method, a class method (a method that is decorated with static), cannot be declared as an abstract method.
    • Subclasses of an abstract class must give a concrete implementation of an abstract method in an abstract class, unless the subclass is also an abstract class.

The This keyword is used to resolve a conflict with the same name that occurs between the instance variable (private String name) and the local variable (the name variable in setName (String name).

Any class that accesses private member variables in a class is passed through these getter and setter methods.

The interface cannot be instantiated, but it can be implemented. A class that implements an interface must implement all the methods described in the interface, otherwise it must be declared as an abstract class.

interface has the following characteristics
    • Interfaces are implicitly abstract, and it is not necessary to use the abstract keyword when declaring an interface.
    • Each method in the interface is implicitly abstract, and the declaration does not require the abstract keyword.
    • The methods in the interface are public.
The difference between an interface and a class
    • An interface cannot be used to instantiate an object.
    • Interface has no constructor method.
    • All methods in an interface must be abstract methods.
    • An interface cannot contain member variables, except static and final variables.
    • Interfaces are not inherited by classes, but are implemented by classes.
    • The interface supports multiple inheritance.
Implementation of the interface
    • When a class implements an interface, the class implements all the methods in the interface. Otherwise, the class must be declared as an abstract class.
    • class implements the interface using the Implements keyword. In a class declaration, the Implements keyword is placed after the class declaration.
The difference between set and list
    • The Set interface instance stores unordered, non-repeating data. The List interface instance stores elements that are ordered and can be duplicated.
    • Set retrieval efficiency is low, delete and insert efficiency is high, insert and delete do not cause element position change < implement class has hashset,treeset>.
    • Lists and arrays are similar and can grow dynamically, automatically increasing the length of the list based on the length of the actual data stored. Finding elements is efficient, and insertion and deletion is inefficient because it causes other elements to change position < The implementation class has arraylist,linkedlist,vector>.
Generic Methods

All generic method declarations have a part of a type parameter declaration (delimited by angle brackets) that is part of the type parameter declaration before the method return type.

Each type parameter declaration section contains one or more type parameters, separated by commas between the parameters. A generic parameter, also known as a type variable, is the identifier used to specify a generic type name.

The declaration of a generic method body is the same as other methods. Note that the type parameter can only represent a reference type, not the original type (like Int,double,char, and so on).

Type wildcard character

Type wildcard characters are generally used instead of specific type parameters. For example List<?> List<String> , the parent class is logically, List<Integer> such as all list< concrete type arguments >.

The upper bound of a type wildcard is defined by a shape such as list, which is defined as a wildcard generic value that accepts number and its underlying subclass type.

The lower bound of a type is defined by a shape such that a List<? super Number> type can accept only number and its three-level parent class type, such as an instance of the Objec type.

Java serialization

Classes ObjectInputStream and ObjectOutputStream are high-level data streams that contain methods for deserializing and serializing objects.

Summary of Java Review

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.