Look at "Java Programming Thoughts" notes

xiaoxiao2021-03-06  104

These days, because of the work needs to read "Java Programming Thought" again, the process of seeing some no attention will be done in the middle of the process, and many of them written in my own summary, if There is wrong, please refer to it. Now use it as my first article, I will publish it later, thank you for your participation.

Chapter two

1. Java is a reference (Reference), create an object via the New keyword

2. Primitive Boolean (False), Char ('/ U

0000 '

), Byte (0), Short (0), Int (0), long (0), LONG

0L

), float

0.0F

), Double (0.0D), Void

3. The scope of the Java intermediate parameter is between {}. Can't have variables {INT X; {INT X;}} illegally in Java, and variables can be defined anywhere in the Java language.

4. When the original type of variable is a member of the class, there is a default value. However, non-class member variables do not have default, otherwise compile errors

5. In Java, the method is part of the class, so you need to call the method through an object. If the object is wrong, you will have a compilation error. When you call the method, it is actually a pass reference. .

6. Method If there is no return value, you must void type

7. Note in Java. / * Multi-line comment * / / / single note, comment documentation / ** * /, Javadoc only handles members and comment documents for public and protect.

third chapter

1. Focus on the primitive variable in Java is relatively simple. But to assign a value here is a copy of Reference, and is also the transferring Reference when the method calls call.

2. == and! = Comparison is the reference to the object, not the value of the object, to compare the value of the two objects. Need to use Equals

3. In Java, logical operators can only be applied to logic values ​​and cannot be used on non-logical values.

4. Bit operator: &, ^, |, ~. A few can be used in combination with = operator, <<, >>, java >>> (no sign right), this is C and C No, if you displaced with char, byte, short, they first turn into int types, and the result is the int type, the long type does not change. Shift symbols can be used in conjunction with =, such as << =, >> =, >>> =

5. If the expression starts with String, then the back variable is String, "A B C" 10 20 30

6. You can convert the original type. But for Boolean can't be converted

7. In the middle of Java, hexadecimal numbers use 0x to start, backward numbers or cases of A-F letters. Octa use 0 starts, with LONG type data, plus F or F represents the data of the float type after digital rear. Plus D or D represents Double type data (integer, for example, 12 default is an int type, with decimal point (12.34) default Double type)

8. If the data type is more than the intimate data (Byte, Char, Short) is performed in arithmetic operations and bit operations. It will be upgraded to the int type, so when a result is small, it is necessary to convert 9. There is no sizeof () in java, because in Java, the data size fixed of each type is fixed.

10. The number of Double generated by the Random () method in Math is less than 1, greater than or equal to 0

11. Goto is the reserved word in Java. But it is not used, we can use Break and Continue to complete a GOTO function. This is not a jump, but a way to jump out of the loop. The same thing is that they all use labels (label)

12. When you turn the Float and Double type data to an int type, it is removed to remove their fractional parts, such as int (36.7) = 36

Chapter Four

1. Constructor is a special method. It has no return value. This and Void's approach has essentially different from the void method. This is determined by you, you can return the value there. But the constructor does not return anything, you have no choice (the New expression does return this new creative object reference, but the constructor itself does not return value)

2. Each overloaded method must have a list of unique parameter types.

3. If the parameter is the original type, the type of improvement is performed when it can't find the corresponding type. But you can't automatically become a type smaller than it.

4. If we don't define constructor (no matter whether there is any parameters), the compiler will create a default non-parametric constructor for us. But as long as we define a constructor (whether there is any parameters), the compiler will not provide the default constructor.

5. This can only be used inside the method, you can regard the Reference of the THIS object as the Reference of any object, but in the constructor, this means that the constructor of the matching parameter is called.

6. In Java, the object is not necessarily recycled by the garbage collector, and garbage recovery is not a descent. The reason for the Finalize method is because Java can call local methods. The memory may be allocated in the local method.

7. Initialization of variables: The initialization of class variables is better than any method, even in front of the construction method. For Static variables, the same, if the variable is the original type, then it gets a standard original type of initial value, if it is an object reference, unless you create a new object to this reference, otherwise Null. The Static variable will only be initialized when needed, and the constructor is called before the constructor of this class and all other normal variables, and the static will no longer be initialized. That is to initialize Static variables, then initialize non-Static variables

8. When the array is defined in Java, the size of the array is not allowed, INT [INT [INT A [] = {1, 2, 3, 4, 5}, the array can be directly assigned, INT A [], int b [], A = B; is correct. For arrays, we can use a function of calculating length. Length. If you don't know how many elements are written while writing, you can create an element in an array, int a []; A = new int [10]; of course, array definition and array initialization can be Merge together: int a [] = new int [10]; if the array you created is not an original type, but an array of objects, you must use New. Integer B [] = {New Integer (1), new integer (2), new integer (3)}; second way: integer b [] = new integer {new integer (1), new integer (2), NEW INTEGER (3)}; 9. Treatment of multidimensional arrays. You can first determine one dimension and then determine other. Integer a [] [] = new integer [3] []; and each vector can be any length, such as the array of the above can be a [0] = new integer [4], a [1] = new integer [5], etc.

转载请注明原文地址:https://www.9cbs.com/read-97241.html

New Post(0)