Three, operation

Parameter passing

Java is value passing. To summarize the use of method parameters:

A method cannot modify the parameters of a primitive data type (that is, numeric and Boolean)

A method can change the state of an object parameter (object. Properties can be modified because the address of the object is passed, making it possible to change properties through object methods.)

A method cannot have an object parameter reference to a new object (two objects cannot be exchanged)

Implicit type conversion

Java cannot implicitly perform a downward transformation because it would reduce accuracy.

// the literal 1.1 is a double and 1 is an int
/ / float f = 1.1;
//short s1 = 1;

But using the += or ++ operators will perform implicit type conversions
s1 += 1;// this is equivalent to the following equation
s1 = (short) (s1 + 1);
Copy the code

switch

Starting with Java 7, you can use strings in switch conditional statements.

Four, keywords

1, the final

data

For basic types, final leaves the value unchanged;

For reference types, final leaves the reference unchanged and therefore cannot refer to other objects, but the referenced object itself can be modified.

methods

Declaration methods cannot be overridden by subclasses.

Private methods are implicitly specified as final. If a method defined ina subclass has the same signature as a private method in the base class, the subclass’s method does not override the base class method, but defines a new method in the subclass.

class

Declare that classes are not allowed to be inherited.

2, the static

A static variable

Also called a class variable, that is, the variable belongs to the class. All instances of the class share a static variable, which can be accessed directly by the class name. Only one copy of a static variable exists in memory.

A static method

Static methods exist when the class is loaded and do not depend on any instance. So a static method must have an implementation, that is, it cannot be an abstract method.

Only the static fields and methods of the owning class can be accessed. The methods cannot have the this and super keywords because they are associated with specific objects.

Static statement block

A static statement block is run once during class initialization.

Static inner class

A non-static inner class depends on an instance of an external class, which means that an instance of an external class must be created before it can be used to create a non-static inner class. Static inner classes do not.

A static inner class cannot access the non-static variables and methods of an external class.

Static guide package

When using static variables and methods, you no longer have to specify a ClassName, simplifying the code but greatly reducing readability.

Initialization sequence

In the case of inheritance, the initialization sequence is:

Parent class (static variables, static statement blocks)

Subclasses (static variables, static statement blocks)

Parent classes (instance variables, plain statement blocks)

Parent class (constructor)

Subclasses (instance variables, plain statement blocks)

Subclass (constructor)

The order in which static variables and static statement blocks are initialized depends on their order in the code.