0 50 knowledge points necessary for basic Java

1. Writing: The written Java code is saved in the source file ending with ".java".

2. Compile: Use the javac.exe command to compile the java source file and generate a bytecode file.

Format: javac source file name.java

3. Run: Use the java.exe command to interpret and run the bytecode file. Format: java class name

4. Multiple classes can be declared in a java source file, but only one class can be declared as public at most, and the class name of the class declared as public must be the same as the source file name.

5. All letters in the java keyword are lowercase

6. Naming conventions in Java:

Package name: When composed of multiple words, all letters are lowercase: xxxyyyzzz Class name, interface name: When composed of multiple words, the first letter of all words is capitalized: XxxYyyZzz

Variable name, method name: When composed of multiple words, the first letter of the first word is lowercase, and the first letter of each word is capitalized at the beginning of the second word: xxxYyyZzz

Constant names: All letters are uppercase. When there are multiple words, each word is connected with an underscore: XXX_YYY_ZZZ

7. The string belongs to a class and belongs to the reference data type

8. In the class body, the variables declared outside the method body are called member variables.

9. Variables declared inside the method body are called local variables. In addition to formal parameters, local variables need to be explicitly initialized before they can be used. (Formal parameters are also local variables)

10. Java integer constants default to int type, and 'l' or 'L' must be added after declaring long type constants.

11. Java's floating-point constants are double by default. To declare a float constant, add 'f' or 'F' after it.

12. All characters in Java use Unicode encoding. One character can store one letter and one Chinese character, so the char type in java is two bytes.

13. Boolean type data only allows values ​​of true and false, no null. It is not possible to use 0 or non-zero integers instead of false and true. The Java virtual machine does not have any bytecode instructions dedicated to boolean values. The boolean values ​​​​operated by Java language expressions are replaced by the int data type in the java virtual machine after compilation: true is represented by 1, and false is represented by 0 .

14. Although the long type is 8 bytes, the float is 4 bytes, but the float type is stored in scientific notation, so the storage range of the float type is larger than that of the long type.

15. Automatic type conversion: A type with a small capacity is automatically converted to a data type with a large capacity. byte, short, and char are not converted to each other, and the three of them are first converted to int type during calculation.

16. Mandatory type conversion: convert a large-capacity data type to a small-capacity data type, but it may cause precision reduction or overflow.

17. A string cannot be directly converted to a basic type, but the conversion of a string to a basic type can be realized through the wrapper class corresponding to the basic type.

18. The bottom layer of the computer stores data in the form of two's complement.

19. The original code, inverse code and complement code of a positive number (the highest bit is 0) are the same, and the complement code of a negative number (the highest bit is 1) is its inverse code + 1.

20. Assignment operator: = += -= *= /= %=, the result of the operation will not change the data type of the variable itself. short i = i + 1; since the constant "1" is of int type by default, an error will be reported when compiling. Using short i += 1 will achieve the effect of +1 without changing the data type.

21. The difference between & and &&, | and | |: && and | | have a short-circuit function, the condition on the left is true or not, and the condition on the right does not need to be judged. No matter what the situation is, & and | must judge all the conditions.

22. Bit operations: Bit operators operate on integer data.

(Left shift operator) <<: Within a certain range, every 1 bit shifted to the left is equivalent to * 2

(Right shift operator) >> : Within a certain range, every 1 bit to the right is equivalent to / 2

23. Process control:

Sequential structure: The program is executed from top to bottom.

Branch structure: if - else, switch-case

Loop structure: for, while, do-while

24. Arrays are reference data type variables, but the elements of the array can be either basic data types or reference data types.

25. Once the length of the array is determined, it cannot be modified. After the initialization is completed, the length is fixed.

26. Static array initialization: The initialization of array elements and the assignment of array elements are performed simultaneously.

For example: int a[ ] = new int [ ] { 1,2,3 };

27. Array dynamic initialization: The initialization of array elements and the assignment of array elements are performed separately.

For example: int b[ ] = new int [5]; b[0] = 1 ;

28. The default initialization value of array elements:

Integer: 0

Float: 0.0

Character type: 0 or '\u0000', not '0'

Boolean type: false

Reference data type: null

29. The keywords break and continue can be used with labels (similar to the goto statement in C language)

break label;//End the one-level loop structure of the specified label.

continue label;//End the current cycle of a layer of loop structure with the specified label.

30. Object-oriented vs process-oriented

Process-oriented: The emphasis is on functional behavior, taking functions as the smallest unit, and considering how to do it.

Object-oriented: Emphasize objects with functions, take class/object as the smallest unit, and consider who will do it.

31. Two important concepts in object-oriented:

Class: A description of a class of things, an abstract, conceptual definition

Object: It is each individual of this type of thing that actually exists, so it is also called an instance (instance)

32. The virtual machine stack is the stack structure usually mentioned. Local variables are stored in the stack structure; new structures (such as: arrays, objects) are loaded in the heap space.

Supplement: The properties of the object (non-static member variables) are also loaded in the heap space. int arr [ ] = new arr [ ], bounded by the equal sign "=", the left side is the local variable stored in the stack, and the right side is the mechanism of new, stored in the heap.

Method area: class loading information, constant pool, static domain

33. The difference between "attribute" and "variable":

① The position of declaration in the class is different

Attributes: Defined directly within a pair of {} in the class.

Local variables: Variables declared within methods, method parameters, code blocks, constructor parameters, and constructors.

② Differences about permission modifiers

Attributes: When declaring attributes, you can specify their permissions and use permission modifiers. Common permission modifiers: private, public, default, protected —> reflected in encapsulation.

Local variables: permission modifiers are not allowed.

③ In case of default initialization value

Attribute: The attribute of the class, according to its type, has a default initialization value.

Integer (byte, short, int, long: 0), floating point (float, double: 0.0), character (char: 0 (or '\u0000')), Boolean (boolean: false), reference data type(class, array, interface: null)

Local variables: no default initialization value. It means that we must explicitly assign a value before calling a local variable. In particular: when the formal parameter is called, we can assign it.

④Location loaded in memory

Attribute: loaded into the heap space (non-static).

Local variables: loaded into stack space.

34. If the method does not return a value, "return;" means to end the method.

35. The specific code embodiment of the encapsulation idea:

36. The scope of permission modifiers:

37. All four permissions can be used to modify the internal structure of a class: attributes, methods, constructors, and inner classes. If you modify the class, you can only use: default, public.

38. If the constructor of the class is not explicitly defined, the system will provide a constructor with empty parameters by default.

39. Multiple constructors defined in a class constitute overloading with each other.

40. Once we explicitly define the constructor of the class, the system no longer provides a default empty parameter constructor.

41. In a class, there will be at least one constructor.

42. This can be understood as: the current object or the object currently being created.

43. You can explicitly use the "this (parameter list)" method to call other constructors specified in this class, but the constructor cannot call itself through the "this (parameter list)" method (infinite loop).

44. It is stipulated that "this (parameter list)" must be declared in the first line of the current constructor, and it can be pushed out of the constructor. At most, only one "this (parameter list)" can be declared to call other constructors.

45. If the class or interface used is defined under the java.lang package, the import structure can be omitted.

Using "xxx.*" means that all structures under the xxx package can be called. But if you are using the structure under the xxx subpackage, you still need to import it explicitly.

46. ​​A class can be inherited by multiple subclasses (a father can have multiple sons), but a class can only have one parent class (a son can only have one biological father)

47. What are the differences after the subclass inherits the parent class?

Once the subclass A inherits the parent class B, the subclass A obtains all the properties and methods declared in the parent class B. In particular, for the properties or methods declared as private in the parent class, after the subclass inherits the parent class, it still obtains the private structure in the parent class. Only because of the impact of encapsulation (private permission modifier), the subclass cannot directly Just call the structure of the parent class.

After the subclass inherits the parent class, it can also declare its own unique properties or methods: to achieve the expansion of functions.

48. The parent class directly inherited by the subclass is called: the direct parent class. The parent class that inherits indirectly is called: the indirect parent class. After the subclass inherits the parent class, it obtains the properties and methods declared in the direct parent class and all indirect parent classes.

49. If the parent class of a class is not explicitly declared, this class inherits from the java.lang.Object class.

50. Method rewriting (override or overwrite). After the subclass inherits the parent class, it can override the method with the same name and the same parameters in the parent class.

Guess you like

Origin blog.csdn.net/JACK_SUJAVA/article/details/130508853