I. Java naming conventions
Class name: For all classes, the first letter of the class name should be capitalized. If the class name consists of several words, the first letter of each word should be capitalized, such as Myfirstjavaclass.
Method Name: All method names should start with a lowercase letter. If the method name contains several words, the first letter of each subsequent word is capitalized.
Ii. Java data types
Basic data type (built-in data type)
| Byte |
8-bit, signed,-128-127, default value 0
|
| Short |
16-bit, signed,-32768-32767, default value 0
|
| Int |
32-bit, signed, -2,147,483,648-2,147,483,647, default value 0
|
| Long |
64-bit, signed, -9,223,372,036,854,775,808-+, default value 0L
|
| Float |
32-bit, signed, IEEE 754-compliant floating-point number, default 0.0F
|
| Double |
64-bit, signed, IEEE 754-compliant floating-point number, default 0.0
|
| Boolean |
1-bit, true/false, all lowercase
|
| char |
16-bit Unicode characters, constant with ' |
-
java for Unicode support with is the UTF-16 encoding implementation; Under UTF-16, a Unicode character in Java is represented by a 1 or 2 char (code unit).
utf-32 and Unicode code table basic One A corresponding, fixed four bytes. |
unicode the scope of the definition is too large, in fact 99% of people use no more than 2 bytes of character encoding, so if you unify 4 bytes, data redundancy is too large and 16 bits are the best. Characters that are more than 16 digits long can be represented by proxy technology, with 32-bit identification. So now most machines implement Unicode with UTF-16 scheme |
-
-
-
-
Objects, arrays are reference data types. The default value for all reference types for
-
is null.
-
A reference variable can be used to reference any type that is compatible with it.
Type conversions
(1) Automatic type conversion
Integer, Real (constant), character-type data can be mixed. Operations, different types of data are converted to the same type first, and then the operation is performed. Conversions from low to advanced.
Low------------------------------------------------------------> High
Byte, short, char-> int-> long-> float-> Double
(2) Forced type conversion
Forced type conversions must be used when converting large-capacity types to small-capacity types.
Format: (type) value
Note: The data type of the conversion must be compatible, and the Boolean type cannot be cast.
Three, constant
Variable scope
(1) Local variables
A local variable is declared in a method, a construction method, or a block of statements;
Local variables are created when methods, construction methods, or block of statements are executed, and when they are executed, the variables are destroyed;
Access modifiers cannot be used for local variables;
A local variable is only visible in the method, construction method, or block of statements that declares it;
Local variables are allocated on the stack.
The local variable has no default value, so the local variable is declared and must be initialized before it can be used.
(2) member variable (instance variable)
-
Instance variables are declared in a class, but outside of methods, construction methods, and statement blocks;
Instance variables are created when the object is created and destroyed when the object is destroyed;
Instance variables can be declared before use or after use;
An access modifier can decorate an instance variable, and an instance variable has a default value;
The default value for a numeric variable is 0, the default value for a Boolean variable is false, and the default value for the reference type variable is null.
Instance variables can be accessed directly from the variable name.
(3) class variable (static variable)
-
Declared with the static keyword in a class, but must be outside of the constructor and statement blocks.
No matter how many objects a class creates, the class has only one copy of the class variable.
Static variables are seldom used except when declared as constants. Static variables are stored in a static storage area.
Static variables are created at the beginning of the program and are destroyed at the end of the program.
has similar visibility to instance variables. However, in order to be visible to the consumer of a class, most static variables are declared as public types.
The default value is similar to the instance variable. The default value for numeric variables is 0, the Boolean default is False, and the reference type default value is null. The value of a variable can be specified at the time of declaration, or it can be specified in a constructor method. In addition, static variables can be initialized in static statement blocks.
Static variables can be accessed by: Classname.variablename.
Class variable names are generally recommended to use uppercase when the class variable is declared as public static final type. If the static variable is not public and final, it is named in the same way as the instance variable and the local variable.
Iv. variables
Five, modifier
Access modifiers
Modifiers are used to define a class (interface), method, or variable, which is usually placed at the very front of the statement.
| Modifier |
Current class |
In the same package |
Descendant class
|
Other Package Classes |
Public
|
Y |
Y |
Y |
Y |
Protected
|
Y |
Y |
Y |
|
| Default |
Y |
Y |
|
|
| Private |
Y |
|
|
|
Note: An empty cell row on the previous table represents N.
(1) Access control inheritance relationship
Methods declared as public in the parent class must also be public in the subclass.
A method declared as protected in a parent class is either declared as protected in a subclass, or declared as public, and cannot be declared as private.
The method declared as private in the parent class cannot be inherited.
Non-access modifiers
-
static: Used to create class methods and class variables
|
declares a static variable independent of an object, no matter how many objects a class instantiates, its static variable has only one copy. A static variable is also a class variable. A local variable cannot be declared as a static variable. |
static method |
|
access to class variables and methods can be used directly classname.variablename and classname.methodname way access. |
-
final:final decorated class cannot be inherited, the decorated method cannot be redefined by the inheriting class, the modified variable is constant, is not modifiable.
| final variable |
final variables can be explicitly initialized and initialized only once. A reference to an object declared final cannot point to a different object, but the data in the final object can be changed, meaning that the final object's reference cannot be changed, but the value inside can be changed. The final modifier is typically used with the static modifier to create a class constant. |
final method |
|
final class |
final class cannot be inherited, and no class can inherit any of the properties of the final class. |
Abstract: Used to create abstraction classes and abstract methods.
Abstract method
|
An abstract method is a method that does not have any implementation, and the specific implementation of the method is provided by the subclass. Abstract methods cannot be declared final and static. Any child class that inherits an abstract class must implement all the abstract methods of the parent class, unless the subclass is also an abstract class. If a class contains several abstract methods, the class must be declared as an abstract class. Abstract classes can contain no abstract methods. The declaration of an abstract method ends with a semicolon, for example: Public abstract sample ();.
|
Abstract class
|
An abstract class cannot be used to instantiate an object, and the sole purpose of declaring an abstract class is to augment the class in the future. A class cannot be both abstract and final decorated. If a class contains an abstract method, the class must be declared as an abstract class. Abstract classes can contain both abstract and non-abstract methods.
|
Synchronized
Transient
Java Knowledge Point Finishing--(2) Programming Basics