Java naming conventions:

Package name: lowercase letters for multiple words

Class name, interface name: If there are multiple words, all the words must start with an uppercase letter

Variable name, method name: If there are multiple words, the first word must start with lowercase letters and the second word must start with uppercase letters

Constant name: all letters are capitalized, separated by an underscore

An expression in a Switch structure in Java can only be one of the following six data types:

Byte, short, char, int, enumeration, string.

Arrays in Java are reference types

If the array contains a reference data type, the default value is null

The initial values of the outer elements of the two-digit array are address values, and the initial values of the inner elements are type dependent (same as in one dimension).

Memory partitioning: stack, heap, method (including constant pool, static field)

The Arrays tools

JAVA object orientation has three main threads:1.JAVA classes and their members: properties, methods, constructors, code blocks, inner classes2.Three characteristics of Object-oriented: Encapsulation, Inheritance, polymorphism, (Abstract)3.Other KeywordsCopy the code

“Everything is an object.”

1. In the Java language category, we all encapsulate functions, structures, and so on into classes, and invoke specific functional structures through instantiation of classes.

> Scanner, String, etc

> File: File

> Network resource: URL

2. When it comes to the interaction between the Java language and front-end Html and back-end database, the front and back end structures are reflected as classes and objects in the interaction at the Java level.

Variables of reference type can only store NULL and address values.

Java provides four types of permissions (from small to large) :private, default, protected, and public

The modifier Inside the class The same package Subclasses of different packages Same project
private Square root
The default Square root Square root
protected Square root Square root Square root
public Square root Square root Square root Square root

Four permissions can be used to modify the inner structure of a class: properties (member variables), methods (member functions), constructors, and inner classes

You can only modify classes (non-inner classes) with: default and public

Order of assignment for attributes (member variables) : Default initialization-display initialization-constructor assignment – object. Method (attribute) assignment

Javabeans are reusable components written in the Java language and refer to Java classes that meet the following standards:

The class is public. It has a constructor with no arguments. It has attributes and corresponding get and set methods

The package keyword (similar to namespace in C++) :

1. Provide the concept of package in order to better realize the management of classes in the project

2. Use package to declare the package to which the class or interface belongs, in the first line of the source file

3. Packages belong to identifiers and follow the naming rules and specifications of identifiers.

4, each “.” At a time, it’s a layer of file directories

Note: Interfaces and classes with the same name cannot be defined in the same package

Import keyword (#include<>)

1. Use the import structure shown in the source file to import classes and interfaces under the specified package

The declaration is between the package declaration and the class declaration

3. If you need to import multiple structures, write them side by side

4. You can import all structures in the XXX package by using the XXX.* mode

5. If the class or interface used is the java.lang package or defined in this package, omit it

6. If you use classes with the same name in different packages in the source file, at least one of the classes must be displayed with the full class name.

7. Using “XXX.*” indicates that all structures under the XXX package can be used, but if structures under the XXX subpackage are used, the import still needs to be displayed

8. Import static: Import static structures: properties or methods from a specified class or interface

MVC: one of the common design patterns (model layer, view layer, control layer)

Model layer: data object encapsulation, database operation class, database

Control layer: application interface related, fragment storage, display list adapter, service related, extracted base class

View layer: related tool classes, custom view

Inheritance format: class A: extends B

Inheritance rules in Java:

1. A subclass can have only one parent

2. A class can have only one parent (single inheritance)

3. Children and parents are relative concepts

4. The parent class directly inherited by a subclass is called the direct parent class, and the parent class indirectly inherited is called the indirect parent class

When a subclass inherits from its parent class, it obtains the attributes (member variables) and methods (member functions) declared in the direct parent class and all indirect parent classes.

6. If we do not explicitly declare a class’s parent, the class inherits from java.lang.Object, which means that all classes have the functionality of Object

Method rewrite:

1. After a subclass inherits its parent class, it can override methods with the same name and parameters in the parent class

2, override, when the subclass object is created, the subclass object calls the method with the same name and parameter in the parent class, and actually executes the subclass overriding method

Rewritten provisions:

Method declaration: Permission modifier Return value Type Method name (parameter list) Throws the type of exception

{// method body}

The convention is that a method in a subclass is overridden, and a method in a superclass is overridden

The names and parameter lists of methods overridden by subclasses are the same as those of methods overridden by their parent classes

2. The permission modifier of a method overridden by a subclass is no less than the permission modifier of the method overridden by the parent class

Subclasses cannot override private methods in their parent classes

4, Return value type:

If the parent overrides a method, the return type of the parent overrides a method must be void

② The return type of the overridden method is class A, and the return type of the overridden method is class A or A subclass of class A

(3) The return type of the method overridden by the parent class must be the same as that of the primitive data type.

A method overridden by a subclass may throw no more than the type of exception thrown by the method overridden by its parent class

Methods with the same name and arguments in subclasses and superclasses are either declared non-static (overridden) or static

Instanceof keyword use:

A instanceof a: checks whether object a is an instanceof a. If so, return true

Usage scenario: In order to avoid ClassCastException during the downward transition, we make instanceof judgment before the downward transition. Once true is returned, the downward transition will take place, otherwise the downward transition will not take place

JDK5.0 automatic packing and unpacking

Static keyword use:

Static attributes VS non-static attributes (instance variables)

Instance variables: We create multiple objects of the class, each of which has an independent set of non-static properties of the class. Changing a non-static property in one object does not result in changing the value of the same property in other objects

Static variables (class variables) : We create multiple objects of the class that share a static variable. When a static variable is modified through one object, it causes other objects to call the static variable, which is modified

Static variables are loaded as the class is loaded, prior to the creation of the object, through the “class”. Static variable “.

Since classes are only loaded once, static variables also have only one copy in memory: the static domain of the method area

2. Use the static modifier

In static methods, only static methods or properties can be called; non-static methods can be called

You cannot use this and super in static methods

Distinguish between hungry and slacker

The hungry type:

Cons: Objects take too long to load

Benefits: Thread safety

LanHanShi:

Cons: Thread insecurity (for now)

Benefits: Delayed object creation

Block of code:

1, code block function: used to initialize classes, objects

2, Code blocks can only use static if they are decorated

Static code block (can define more than one) :

There can be output statements internally

Executes as the class is loaded, and only once

Function: Initializes information about a class

Static code blocks can only call static properties or methods, not non-static structures

4. Non-static code blocks:

There can be output statements internally

Executes as the object is created, executing a block of non-static code once each object is created

Function: Initializes the properties of an object when it is created

Father and son, static first

Places to which attributes can be assigned: default initialization, explicit initialization, after code block assignment, constructor initialization, after object creation. Attribute (method)”

Final: structures that can be modified: class, method, variable 1. Final: structures that can be modified: class, method, variable 1. Final: structures that can be modified: class, method, variable 1

4. Final modifier properties, which can be explicitly initialized, initialized ina code block, or initialized ina constructor

5. Final modifies local variables, especially when final modifies a parameter, to indicate that the parameter is a constant. When we call this method, we assign an argument to the constant parameter. Once assigned, the parameter can only be used within the method body and cannot be reassigned

Static final: global constants

Abstract keyword usage

Can be used to modify the structure of a class: class, method

2. Abstract modifier class: abstract class

This class cannot be instantiated

There must be constructors in the abstract class to facilitate the call of subclass instantiation (involving: subclass object instantiation process)

Development provides subclasses of abstract classes that can be instantiated

3, Abstract method

Abstract methods have only method declarations, no method body, and cannot be called

A class that contains abstract methods must be an abstract class. Conversely, an abstract class can have no abstract methods

A subclass can be instantiated only if it overrides all of its parent’s abstract methods. If it does not, it is still an abstract class

Abstract cannot be used to modify private, static, and final methods and classes

Interface usage:

We can only define global constants and abstract methods global constants before we define interface members in JDK7. Public abstract JDK8: In addition to defining global constants and abstract methods, we can also define static methods, default methods. Means that the interface cannot be instantiated. If an implementation class overwrites all abstract methods in an interface, the implementation class can be instantiated. Otherwise, the implementation class is still abstract. Java classes can implement multiple interfaces -----> make up for the limitations of Java single inheritance: Class AA extends BB Impliments CC,DD,EE 7. Interface CC extends AA,BB 8Copy the code