Basic syntax:
Keywords: words that are given a specific meaning by the Java language
Class,public,static,void,package ....
Goto and const are used as reserved words, not currently used!
Identifier: is the name of the class/interface/method/variable! (See the name of the idea)
Write code that must conform to this rule!
Package: Whether it is a multilevel package or a single-level package, the letters are all lowercase and can be separated in the middle.
Class/interface:
Single word: Capitalize first letter
Multiple words: Capitalize the first letter of each word
Method/Variable
Single word: All lowercase letters
Multiple words: First word letter all lowercase, starting with the second word each word capitalized
Constant:
Single word: Uppercase letters
Multiple words: Each word is capitalized and the words are separated by _
Constant:
The amount of change in the value of the program during execution
Classification:
A: Literal constants
B: Custom Constants (Object-oriented section)
Literal constants:
A: String constants: Content enclosed in double quotes
"HelloWorld", "High-round ..."
B: Character constants: Single content enclosed in quotation marks
' A ', ' a ', ' 0 ' ab ' (wrong)
C: Integer Constants
100,1000 ...
D: Decimal Constants
3.14 ...
C: Boolean constant: True/false
D: empty constant: null
Conversion of the binary
Decimal----> Other binary
Other binary---> Decimal
Variable (emphasis): The amount of its value changes during the execution of the program;
Variable classification:
Basic data types
Reference data type (object-oriented section)
Basic data type: 4 classes of 8
Integer type (default int) range
Byte byte type accounted for 1 bytes -128~127
Short shorter integer 2 bytes
int integer default type is 4 bytes
A long integer is 8 bytes
Floating-point type: Default is double
Float Single Precision 4 bytes
Double doubles as 8 bytes
Character type:
Char character 2 bytes
Boolean type Boolean is 1 bytes
Defining three elements of a variable
1) must be qualified to qualify this variable, so the principle of data type must be observed
2) must have variable name
3) must have an initialization value, can not have the initialization value, but before the use of the variable (output), you must assign a value to the variable, otherwise
Considerations for Defining variables:
1) cannot start with a number
2) define the variable as known as the name, not the Java keyword
3) define variables (local variables: In the method definition), before use, be sure to have initialization values
4) to conform to a certain coding style, as far as possible in a row to define lattice variables, do not define multiple;
Extended arithmetic operators: ++/--
1) when used alone
Conclusion: either + + or--at the front of the data or behind the data, are self-increment 1 or minus 1
2) When participating in the operation
A) If participating in the operation, ++/--in front of the data, increment by 1 or decrement by 1, and then the operation (Assignment)!
b) If the participating operation is used, the ++/--is followed by the data, the first operation (Assignment), and then the increment of 1 or minus 1!
Assignment operators
Basic assignment Operator: =
Example:
In the course of a lecture, if there is no explicit data type, use INT
int x = 10;
Assign 10 to variable x of type int
Extended assignment Operator: +=,-=,/=,*=,%=
Add the value to the left of the = sign and the = number to the left of the = number.
Comparison operators
, <,>=,>=,== (compares two data for equality),! = (not equal to)
logical operator (Master)
Basic logical operator
logical operator, whether the concatenated expression is simple or complex, All are Boolen type
logic and: &
Feature: false, false
Logic order or: |
Feature: TRUE, True
Logical XOR: ^
Feature: Same or false, different true
Simple note: Male and female relationship between men and women male and female
logical non:!
Feature: Non-false true, False
the extended assignment operator used in development
logical double and &&
Logical Double or | | The
bitwise operator (mastering bit xor ^)
is connected with two specific data
bit XOR ^ a feature:
One data is different from another data bit or two times, its value is his own
ternary operator (master)----> three-mesh operator
Format
(expression )? True result: false result;
Execution Process:
If the expression is true
otherwise, false results
Keyboard entry Development steps:
Class: Scanner:java.util.Scanner;
1) Create keyboard entry object, fixed format
Scanner sc = new Scanner (system.in);
2) As long as it is not a class under the Java.lang package, you need the Guide package
Location: The top of the class class under the Packages
Import Java.util.Scanner;
3) Accept data
int variable = sc.nextint ();
4) Output
Definition method: The definition of a method with a specific return value type
public static return value type (base data type) method name (formal parameter list) {
return result;
}
Formal parameter list: Data type 1 variable 1, data type 2 variable Name 2 ....
Method Overloading: Overload
Method name is the same, the parameter list is different, and the return value type is not related!! The
parameter list differs in two cases:
1) with different number of parameters
2) different parameter types
Basic Java syntax, variables, operators, keyboard entry