Basic summary of the Java section

Source: Internet
Author: User
Tags modifier modifiers

a summary of some knowledge in the novice period
Object-oriented: First, the object-oriented and process-oriented division: The process is mainly through the process, to achieve a purpose, the goal is the object, two object-oriented focus is no longer consider the process, direct object-oriented! Object concept: All the objective existence of a single object can be separated. (All things are objects.) Composition: attribute, behavior class concept: Several abstract components of an object with the same characteristics or commonalities: attribute, behavior syntax: [modifier]classThe class name {} (when the modifier is public, the class name must be consistent with the source file name (only public or default)) structure:1. Member Variable----property----field [modifier] Data type variable name [=Initial value]2. Constructor----Construction Method----Constructor (is a special member method) [Modifier] class name ([data type parameter name]) {} The constructor name must be consistent with the class name, no return type (including void), and any class contains a constructor. If there is no explicit constructor, then the system will provide a default parameterless constructor for the class, if explicit then the system is no longer available. constructor function:1. Instantiate the Class object 2. Initialize the member variable. 3. Member Methods----behavior----function [modifier] return value type method name ([data type parameter name]) {}4. code block {} or static{} (two differences: The former must use an object (Newconstructor Name ()), which does not need to be used:1Declaration of the. Class variable: The name of the class name object;2. Creation of Class objects: Object name =Newconstructor name ();3. Assignment of Class Properties: Object name. property name =data (also called attribute value) (data type is consistent with object name type)4the invocation of the. Class properties and Methods: System.out.println (object name, property name), object name. Method name ([data type parameter]); NOTE:1. The custom class can declare variables as reference data Types! (use of reference Class) 2. Parameter: A special local variable that passes data to a parameter through an argument. Overloaded (overloading) concept: In the same class, multiple methods with the same name and different parameters are defined. (Different parameters: the type, number, order of parameters) used: Overloading of methods, overloading of constructors this keyword concept: Each class implicitly has an object of the current class using:1. This. Members (member variables and member methods) 2. The first line of statements within the constructor can invoke other overloaded constructors within the class to complete its own initialization: This([Data, data, ...]); Class members and instance member concepts and differences:1The static modifier is a class member, and no static adornment is an instance member. 2A . Class member is common to all objects within a class, and instance members are unique to an object within a class.3. Class members can access all members directly (whether or not they are members of a class), and instance members only have direct access to instance members, and if you want to access a class member, you must first create an object. 4a call to a class member can either create an object first, or directly with the class name. The member must first create an object. 5. Class members are not allowed to use the This keyword. (because no instance of this can be used) the declaration of the package:1. The first line of statements in the source file PackagePackage name. Package Name 2the name of the package is usually inverted. Import of packages:ImportPackage name. The name of the package. The class name is under the declared package, above the declared class. Modifier access modifier:1. Public: Can be accessed under the same package and under the same package. 2.protected: Can be accessed under the same package, and sub-classes under the same package can be accessed. 3. Default: Under the same package can be accessed, not under the same package can not be accessed. 4.Private: can only be accessed within the class. Non-access modifiers:1.StaticStatic2.FinalModifier class: The class cannot be inherited by a decorated member variable: The modifier is not modifiable: cannot be overridden by a modifier parameter: cannot be assigned in the method body. 3.Abstractabstract return value type: Void There are also eight big data types:byte Short int Long float Double Char Booleanreturn: In the method body with the return value, the last row returns a data, ends the method body, and ends the method body in the void method body. Four characteristics of objects encapsulation, inheritance, polymorphism, abstract encapsulation concept: the privatization of members (attributes and methods) (Private) to provide access only to trusted classes. () Use: Provides access to the public's get and set methods. Inheritance concept: A new class is derived from an existing class. Extract the same code that the class has, become the parent class, inherit from the other classes, and reduce the redundancy of the code. Use: [modifier]classSub-class nameextendsparent class Name {} Note: When a subclass inherits the parent class, it will have a method of the non-private property of the parent class. When a subclass creates an object, it essentially creates two objects, a subclass object (the sub-constructor), an implicit parent object (the parent constructorSuper(subclass cannot inherit the constructor of the parent class) overriding concept: In the context of inheritance, the parent class method cannot satisfy the requirements of the subclass method, and the class method is rewritten (rewritten or overwritten) using:1. Inheritance 2. The method of the subclass must be the same as the return value type, method name, and parameter of the parent method, but the method body must be different. 3the. Modifier can be different, but the subclass modifier accesses a scope greater than or equal to the parent class Super keyword concept: A subclass implicitly has an object of the parent class. Use:1.Super. member 2. In the subclass constructor, the first line of the sentence (Super([parameter list]); default constructor that calls the parent class without a parameter. Polymorphic concept: A variety of forms of things. Use:1. Inheritance 2. Rewrite 3. Transition upward (parent class Name Parent class object name =Newsub-class constructor name ();) Effect:1. Improve the reusability of code 2reduce the degree of coupling between programs. Abstract class Keywords:AbstractAbstract method (Incomplete method): [Modifier]Abstractreturns a value type method name ([data type parameter name]); abstract class Concept: A class with abstract methods is an abstract class (incomplete method). Content: An abstract class has a constructor, or it can declare a variable, but it cannot be instantiated because it has an incomplete method, which is an incomplete class. Abstract classes can have complete methods, but classes with abstract methods must be abstract classes. Use: Abstract classes can be inherited, through subclasses to complete the method, and thus achieve the instantiation of the abstract class. Declaration of the interface class (with polymorphic up-up): [modifier]InterfaceInterface Name (consistent with source file name) {} concept: More abstract abstract class (more incomplete incomplete class, Nature is class, but it has no constructor) structure:1. Constants [modifiers] [Final] data type variable; 2. Abstract method [modifier]AbstractReturn value type method name ([data type parameter name]); (1There are changes to the. 8 version, such as adding different modifiers to a complete method. Currently ignored) use:1. Class implementation interface: [modifier]classSub-class nameextendsParent class NameImplementsinterface Name, interface name,...... {} (class implements interface when extends and implemnts order is not changed)2. Interface inheritance interface [modifier]InterfaceInterface Nameextendsinterface Name, interface name,...... {} effect:1. Improved reusability of code 2. Reduced coupling between programs 3. Multiple Inheritance 4 implemented. Improved program extensibility instanceof Operator Concept: Determines whether an object is an instance of a class. Use:if(Object nameinstanceofclass name) {} And so on inner class member inner class: In a class, the method defines a class outside the body. 1the external class accesses the inner class: you need to first create an object and then the object name. Inner class member. 2. Internal class access to external classes: external class members can be accessed directly: external class names. This. External class Members3. External class Access Inner class: External class. Inner class inner class object name =NewExternal class constructor ().Newthe Inner class constructor (); The inner class object name. Inner class member; local inner class: Defines a class in the method body of a class. 1The external class accesses the inner class: After the inner class is declared in the Outer class method body, an object is created and then the member is called. 2. Internal class access to external classes: external class members can be accessed directly, including private classes. You cannot access variables in the outer class method body. The external class name. This. External class Members3external other classes access internal classes: they cannot be accessed directly, and their contents can be obtained through an external class. Static inner class: In a class, the method defines a class outside the body, and this class is decorated with static. 1the external class accesses the inner class: an inner class member with a static decoration: the inner class name. Inner class member No static adornment: Creates an inner class object and then accesses it. 2the inner class accesses the outer class: if the external class member does not have a static adornment, then it is necessary to create an outer class object, which can be directly outside the class name if there is a static adornment. External Class Members3. External class access Inner class: no static modifier inner class member: 1. Outer class. Inner class inner class object name =NewExternal class. The Inner class constructor name (); Inner class object name. internal classes member; Internal class member with static decoration: 2. External class. Inner class member; anonymous inner class: essentially an abbreviation for an inner class. 1. External classes Access Internal classes:Newparent class or interface () {overriding method body}. method name;2Internal classes Access External classes: External class members can be accessed directly, including private classes. Cannot access variables in the Outer class method body3. External other class access internal classes: cannot be accessed directly.

Basic summary of the Java section

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.