1, the difference of the recognition class declaration
When declaring a class with the public class name, the class name must match the file name or the program cannot compile;
When declaring a class with the class name, the class name can be inconsistent with the file name, but you must execute the generated *.class when executing.
For example: Testclass.java file declaration class for demo, execute as Demo.class;
There can be more than one class definition in a Java file, but only one class declared by the public class;
Java naming conventions, class definitions, the first letter of each word in the class name must be capitalized.
2. Java annotations
Single-line comment, "//";
Multi-line Comment, "/*" and "* *";
Document comment, "/**" begins with "*/" ending.
Eclipse in the previous row of the function using/** (here carriage return) */auto-generated function description
3. Java identifier rules
The names of packages, classes, methods, parameters, and variables in Java can be in any order of uppercase and lowercase letters, numbers, underscores, and dollars
Symbol ($), but the identifier cannot start with a number, nor can it be a reserved keyword in java.
Class, 67.9, and Hello Linxinghua are illegal identifiers.
4. Array declaration and object Instantiation Memory allocation
int sarray[]; Stack memory open space Save array name Sarry;
Sarray = new Int[3]; Heap memory opens up Sarray array memory space.
Person Person1; Stack memory open Space Save object name Person1;
Person1 = new Person (); Heap memory opens up Person1 object memory space.
5. Common Memory Area of Java
(1) Stack memory space: Saves all object names (addresses where the referenced heap memory space is saved).
(2) Heap memory space: Saves the specific property content of each object.
(3) Global Data area: Saves properties of the static type.
(4) Global Code area: Save all method definitions.
6. Static keyword in Java
The static property is shared by all objects.
A method of a non-static declaration can invoke the properties and methods of a static declaration, but the method of static declaration cannot invoke properties and methods of a non-static declaration.
Because the properties and methods of a non-static declaration must be called after the object has opened up the heap memory space, the method of the static declaration is not instantiated by the object
Can be called by the class name.
Singleton mode: A class will always have only one instanced object present. The constructor method is privatized (private), and the class's Static method GetInstance () Gets the inner self-instantiated object of the class.
7. Code block
Code block: A piece of code enclosed in {}, classified according to location: Ordinary code block, building block, static code block, synchronous code block.
Ordinary code block: refers to a block of code defined directly in a method or statement;
Building blocks: Blocks of code that are written directly in the class, and construction blocks take precedence over the construction method execution, each time the object is instantiated.
Static code block: a block of code that uses static declarations; a static block of code defined by a class takes precedence over a construction block execution, and is performed only once with object-Independent
8. Inner class
1. Define inner classes in class
Inner class Benefits: You can easily access the private properties of an external class.
External Access Internal classes:
(1) Non-static inner class: Outer class. Inner class Inner Class object = External class instance. New inner class ();
(2) Static inner class: Outer class. Inner class Inner Class object = new External class. Inner class ();
2. Define the inner class in the method
The inner class defined in the method cannot directly access the parameters in the method, and the parameter must be preceded by the final keyword to be accessed by the inner class.
9. Final keyword
(1) The class of the final declaration cannot have sub-categories;
(2) The method of Final declaration cannot be covered by the quilt;
(3) The variable of final declaration becomes a constant, and the constant cannot be modified.
Final variable naming rule: The variable letter in final declaration is all uppercase.
10. Abstract classes and interfaces
1. Abstract class
(1) The class containing the abstract method must be an abstract class;
(2) Abstract classes and abstract methods are declared by the abstract keyword;
(3) Abstract methods only need to declare and do not need to implement;
(4) Abstract classes must inherit from the quilt class, and subclasses (if not abstract classes) must overwrite all abstract methods.
2. Interface: Special abstract class, which is composed of global constants and common (public) abstract methods.
Interfaces can inherit multiple interfaces interface A extends B,c;
11. Packing and Unpacking
Boxing: The process of turning a basic data type into a wrapper class;
Unpacking: Changing a wrapper class to
12. Static Import
Import static Package. class. *;
Methods in a class all use static methods of the static declaration to import statically.
These methods can be called directly without the following: class. static method (); Method call, call directly: Static method ();
13, multi-threaded runnable
A multithreaded application is implemented through the Runnable interface, meaning that properties in a class are shared by multiple threads.
Java Knowledge Collection