Java Getting started important knowledge points here to summarize, in order to facilitate review later, this part of the main content is: variables and constants, common operators, flow control statements, arrays, methods of these contents
First, variables and constants
1.Java keywords
Put a picture first:
All keywords are case sensitive.
2. Identifiers
Identifiers are symbols that are used to name variables, classes, methods, and so on in a Java program.
Note Several rules:
Identifiers can consist of letters, numbers, underscores (_), dollar symbols ($), but cannot contain other special characters, such as @,%, space, and cannot begin with a number.
Identifiers cannot be Java keywords and reserved words , but can contain keywords and reserved words.
Identifiers are strictly case-sensitive .
The name of the identifier best reflects its role, to be known.
3. Variables
In Java, we describe variables by three elements: variable type, variable name , and variable value .
such as: String s= "Freeweb";
Variable naming strictly conforms to the specification of identifiers, the good habit of naming is to use the Camel name method: When the variable name is composed of multiple words, the first letter is lowercase and the first letter of the word is capitalized.
4.Java Data types
The Java language is a strongly typed language. The data stored in Java is typed and must be determined at compile time.
Where the underlying data type variable is the data itself, the reference type variable holds the space address where the data is stored.
In Java, the default declaration of the decimal is double type, such as double a=3.3, if declared: float x = 3.3 will be an error, you need to do the following: float x = 3.3f or float x = (float) 3.3, where 3.3f after the F just to distinguish Double does not represent any meaning in the numbers.
Char represents a character, defined with single quotes, and can only store one character, such as Char c= ' x '; String , which is defined with double quotation marks, can store one or more characters, such as String name= "Web"; Char is the base data type, and string is a class that has an object-oriented feature that can call a method, such as Name.length () to get the length of a string.
Variable name to ensure better compatibility does not recommend the use of Chinese names, although there is no error.
5. Conditions for automatic type conversion
There is often a need for mutual conversion between data of different basic data types. The conditions for conversion are:
The target type can be compatible with the source type, such as a double compatible int, but the char type is not compatible with the INT type
The target type is greater than the source type, such as a double type of 8 bytes and an int type of 4 bytes, so a variable of type double can directly hold data of type int, but not in the opposite way.
6. Forcing type conversions
A simple understanding is that a variable with large storage space transforms into a variable with small storage space, and the data precision is lost. Syntax is simple: (data type) values
such as: Double avt1=120.23;
int avt2= (int) avt1;
7.Java Constants
The value cannot be changed during program execution, such as: Final double pi=3.1416;
Constants can increase the maintainability of the program and prevent it from being mistakenly manipulated. Constant names generally use uppercase characters.
Second, operator
1 . Arithmetic Operators
2. Assignment operators
3. Comparison Operators
Note: >, <, >=, <= only support left and right operands are numeric types, = =,! = The operands on both sides can be numeric types, or they can be reference types
4. Logical operators
5. Conditional operators
Also called ternary operator, form: boolean expression? Expression 1: Expression 2, Operation procedure: Returns the value of expression 1 if the value of the Boolean expression is true, otherwise returns the value of expression 2
such as: (8>5)? "8 is greater than 5": "8 is not greater than 5", and the value of this expression is a string: 8 is greater than 5
2. Operator Precedence
Third, Java Process Control
1.if statements
2.if...else statements
3. Multiple if
Note: Condition 2 defaults to include the part where Condition 1 is no, for example: Condition 1 is x greater than 90, and condition 2 is 60-90 write only: x>=60.
4.switch statements
5.while Cycle
Features: first judgment, after execution
6.do...while Cycle
Features: First execution, after judgment, ensure that the loop is executed at least once.
7.for Cycle
The For loop is more concise and understandable
8.break Jump
1, used to terminate the current cycle, while,do...while,for are applicable 2, used in the switch statement, to avoid repeated selection
9.contiune Jump
Jumps out of the remaining statement in the loop body, executes the next loop, which jumps to the end of the loop without terminating the loop
Four, array
1. Declaring an array
Syntax: data type [] array name, or data type array name [];
such as: int[] SC; String names[];
2. Allocating space
Syntax: array name =new data type [array length];
such as: Sc=new int[8];
1.2 Two steps can be combined, int[] sc=new int[8];
3. Assigning values
Initialize and assign value: int[] sc={45,23,33,25}; or int[] sc=new int[]{45,23,33,25};
4. Operation
After the definition is the same as the variable operation: sc[0]=8; sc[1]=10;
5. Two-D array definition
Same as one-dimensional array, such as defining an array of 3 rows and 2 columns
Int[][] Num=new int[3][2];
V. Methods
1. Define a method
Access modifiers: Methods allow access to a range of permissions that can be public, protected, private, or even omitted, where public means that the method can be called by any other code
Return value type: The type of the method return value, if the method does not return any value, the return value type is specified as void, if the method has a return value, you need to specify the type of the return value, and return the value in the method body using the return statement
Method Name: The name of the method defined, must use a valid identifier
Parameter list: A parameter list passed to a method, with arguments that can have multiple arguments separated by commas, each parameter consists of a parameter type and parameter name, separated by a space
2. Method classification
The method can be divided into four classes depending on whether the method has parameters or not, and whether it has a return value:
No parameter no return value method
Non-parametric return value method
No return value method with parameter
Return value method with a parameter
3.Java Method Overloading
If the same class contains two or more than two methods with the same name, the number of method arguments, the order, or a different type of method, it is called an overload of the method, or it can be said that the method is overloaded.
Method overloads distinguish the calling method: When the overloaded method is called, Java determines which overloaded method should be called based on the number and type of arguments, and the method that exactly matches the parameters is executed.
4. Determining the basis of method overloading
Must be in the same class
Method name is the same
Different number, order, or type of method parameters
Not related to the modifier or return value of a method
Java Getting Started learning knowledge points summary-Part One