It's been 5 months since I started working as an engineer, and I'm about to get a qualification. .. .. So! As a countermeasure for "Oracle Certified Java SE Silver", I picked up and summarized the important points for each chapter based on the black book.
Entry point: The place to start execution when executing the program (it is OK to recognize where the main method is).
How to call Java command is ↓
java class name command argument 1 command argument 2...
java file name.java
java sample x "y y"z ¥" c¥" // x , y yz , " , c"
Base number | prefix | Description method | display |
---|---|---|---|
Binary number | 0b | 0b01001000 | 80 |
8 base | 0 | 077 | 63 |
Decimal number | None | 63 | 63 |
Hexadecimal | 0x | 0x3F | 63 |
Data type | value |
---|---|
boolean | true, false |
char | 16-bit (Unicode \ u0000 ~ \ uFFFF) |
byte | 8-bit integer-128~127 |
short | 16-bit integer −32,768〜32,767 |
int | 32-bit integer |
long | 64-bit integer |
float | 32-bit single institutional floating point number |
double | 64-bit precision floating point number |
(Caution) The only symbol that can be used in the notation of integer literals is "_". (Not available before / after the beginning / end / symbol)
char type = null; will result in a compilation error. For character code, 0 to 65535
How to generate a String type Object.
String str1 = "Sample1"; //Enclose the character string with ""
String str2 = new String("Sample2"); //Create an instance of String type with new
About ver type (inference type)
Can only be declared with a local variable. Note that it cannot be used in class field declarations and method argument types!
Infer the literal type from the corresponding value at compile time. Therefore, it cannot be initialized because it is null or cannot be judged.
ver = null; //Compile error because the data type cannot be inferred
ver = {1,2,3} //Compile error because the type cannot be assumed
ver list = new ArrayList<Object>(); // OK
charAt (a) method: Returns the character of the specified number. Note) The character number starts from 0.
indexOf ("xxx") method: Returns where the specified character is in the string. If it does not exist, -1 is returned. Note) The character number starts from 0.
substring (a, b): Returns the character within the specified position.
replace ("x", "y") → Replace with the specified character and any character. Note) It is necessary to unify the argument types.
contat ("xx") → Concatenate any character string and argument character string.
Srting str = "hello";
System.out.printout(str.charAt(1)); // e
System.out.printout(str.charAt(5)); //Throw an exception
System.out.printout(str.indexOf("o")); // 4
System.out.printout(str.indexOf("hello!")); // -1
System.out.printout(str.substring(1, 3)); // el
System.out.printout(str.replace("l", "r")); // herro
System.out.printout(str.substring("l", 'r')); //Error due to different argument types
str2 = srt.concat(", world!"
System.out.printout(str2); // hello, world!
Object a = null → No problem
intern (): The character string of new String () is also referred to as the constant pool.
If the same string exists in the pool, return that reference.
The types that cannot be returned by the conditional expression of switch (conditional expression) are as follows.
Numbers with a decimal point double, float
Case x cannot be defined
Variables (constants qualified with final are OK)
Signature: Includes method name and arguments, argument type, number, and order. → Note that the return type is not included!
The equals method returns false whenever null is passed.
Null can be included in the elements of the array!
The default value for Object type is null
[] of int [] is a declaration, so do not put a number in [].
int[5] array //Of the declaration[]Error because there is a numerical value in
int[5][] array //Of the declaration[]Error because there is a numerical value in
Object a = null is possible.
A reference type can only hold a reference or not (null).
Variable length must be the last argument.
Definition method ◯: Type ... Variable name, ×: Type variable name ...
void sample(int ...a){...} // OK
void sample(int ...a, int...b){...} //error
void sample(int a...){...} //error
There are no restrictions on the access modifiers that qualify the constructor.
The constructor initializer "{}" is processed before the constructor is executed.
The condition of overload is that the signature is different. Access modifiers are irrelevant.
When calling another overloaded constructor from the constructor, it must be listed first in the constructor.
If the code is written below return, a compile error will occur on the line of that code.
Unreachable code will result in an error.
While editing