1, a java program
class HelloWorld{ public static void main(String[] args){ System.out.println("Hello World!"); } }
2 comments
1. In the code, the explanation for the program part.
2. Notes Features
1. The compiler does not check the syntax of this part.
2. The running time is negligible content of this section.
3. Classification
single line comment //
multi-line comment / * * / not nest
documentation comments / * * /
4. Notes effect
1. program explanation: code requirements, there are used 30% of the number of rows write comments.
2. Description of the thinking process.
3. debugging a program: quickly navigate to the wrong location by way of comment.
4, Keyword
1 is given a specific meaning of the word.
2. Features
1. All lowercase
2. myself a name, do not duplicate names and keywords
3. There are two reserved words: goto const, is not used in the current version, but later whether to use unknown.
5, the identifier (a name)
1. For to classes, interfaces, methods, variables, constants, etc. from the name.
2. components:
1. English case AZ AZ
2. 0-9
3. Special symbols $ _
3. Cautions
1. Do the same name and keyword
2. The numbers do not begin with, abc123 legal 123abc unlawful
4. industry specifications
1. See name known Italian
int i = 20;
int personCount = 20;
int renShu = 20;
2. the use of hump-like
class and interface naming:
first letter of each word capitalized, the rest lowercase.
Named variables and methods:
lowercase first letter of the first word, the other word capitalized
constant naming
all uppercase letters, use _ to connect
6, constants
1. During program execution, the value of which does not change the amount of occurrence, is constant.
2. The constant in the forms of classification:
literals: Write constants can know the value of the constant. 122015
symbolic constant: to constants has a name, to see to know the name meaning constant, do not know the value of the constant.
3. Constant The data type:
integer constants: all integers, for example 5, 10, -15, -16
decimal constant: All decimals, e.g. 3.1415926
character constants: single quotes single symbols, such as' a '' 1 '' abc 'illegal
Boolean constants: used to represent the content of right and wrong. true false
reference data types: basic data types as the type of assembled.
String constants: double quotation marks symbol sequence. E.g. "HelloWorld!"
Empty constants: indicates empty, not point to any data, null.
. 7, variable
1. Variable: the program is running, the value of the amount of change occurs.
2. Definition Format:
data type variable name = variable value;
reasons 3. Use variables:
in the program, there are some data represent the same meaning, constantly changing, such as age.
Define a constant variable name, those numbers represent changing.
In memory, in fact, a section of memory space and data space may be constantly changing.
4. The basic data types of variables (four eight kinds)
Integer types:
byte. 1 byte. 7 ~ -2 ^ 2 -128-127 ^ 7-1
Short 2 bytes 2 ~ 15 ^ -2 ^ 15-1
int. 4 bytes -2 ^ 31 to 2 ^ 31 -1
long 8 bytes -2 ^ 63 to 2 ^ 63-1
decimals (floating point) type
float 4 bytes> 8 bytes long type
Double 8 bytes
boolean
boolean unknown
character type
char word 2 section
5. the default type constant
default type 1. integer constants as int, write random integer constant must be enclosed in a pan of type int.
-214 783 648 2147483647
2 decimal constant is the default type double
If float type, a behind the decimal add F.
6. The conversion of the implicit conversion of data types
1, when a small range of data types and large range of operation when, it will first range smaller data type
for lifting, carrying, or to a large range of data types, then operation.
byte <Short char = <int <Long <float <Double
2. Notes
byte short char int at each calculation, all directly promoted to int type, not larger type.
int int type above and, at each operation, is promoted to a larger type
converter 7. The data casts
1. wide range of data types to be converted to a small range of data types, it is necessary to use a cast.
2. The conversion format:
(to be converted into data types) need to convert data
3. Notes
data before the transfer may be strong and inconsistent data after the strong turn.
8. face questions
constant optimization mechanisms: For integer, some calculation is very simple, such as operational constants and constants,
We can put these simple value calculation is completed at compile time.
9. Note variables defined
1. Variable is scoped
scope: the scope of work.
Scope: Which of the variables in curly brackets declaration defines the scope of which is to braces.
2. In the same scope, the same name can not be defined variables.
3. Define the variables in the method must be the real beginning of the assignment before you can use.
4. Define separation variables can be assigned to variables and variables declared.
The data type may be the same variable in the same row of a plurality of statements.
10. The character variable
1.char variable name = variable value;
2. in the computer, all data are represented using numbers, characters are no exception.
3. The character seen, and a digital computer, a conversion correspondence.
From the process of digital characters, called the encoding
process to the digital characters, called decoding
4. Table coding table ascii code
'0' --- 48
'A' 65 ---
'A' --- 97
11. The string type
1 using a series combination of characters enclosed in double quotation marks, a reference data type.
String type variable space, the address data is recorded.
2. The key statement is a string type String.
3. string and other types of stitching, +
It represents splicing: first other types of data, string type rotor surface, and then the current string stitching
result is a longer string.
8, the operator
1. Operator: symbol for arithmetic operations and data
2. Classification:
arithmetic operators
assignment operators
Comparison Operators
Logical Operators
shift operators
ternary operator
9, the arithmetic operators
+, -, * , /,% (modulo, modulo)
1. If two integers and the result is an integer, rounding is not rounded 17/2 = 8
2. If one division when there is a fraction, the result was obtained decimals.
3. modulo operation time and the results are consistent sign modulus.
Increment decrement: ++ -
1. role: on the basis of a variable, increment or decrement
2. Note:
1. the increment operator can be put in front of the variable variable.
2.a ++ behalf of other operators do first, and then incremented by one
3. Representative ++ a first increment 1, do other operations
10, the assignment operator
1. The operator for assignment to the variable
2. Classification
Basic assignment operator: =
extended assignment operator: + = - = = * / =% =
11, comparison
!>> = <<= = ==
arithmetic result is a Boolean type
12, logical operators
& |! && (short-circuiting) || (or short circuit)
! = To false to true
to false to true =!
true&true=true
true&false=false
false&true=false
false&false=false
true|true=true
true|false=true
false|true=true
false|false=false
Involved in computing parameter is a Boolean type, the result is a Boolean type
13-bit operator
>> <<
<<: left, each move one, will expand twice the original figures
>>: right, each move one, will be reduced twice the original digital
<<<: unsigned operation directed to
face questions: 2 Know the most efficient operation will expand 8 times
2 8 = 16 *
2 << 3 is moved to the left 3
14 , ternary operator
expression 1 expression 2: expression 3;?
expression is a Boolean expression 1, the result is true false Boolean
expression 1 is true, execute 2 expression;
expression 1 is false, execution expression 3;