My name is fish soup, not only a Java side of the dish chicken, but also the first contact with the blog Dish Chicken, yesterday after the first blog to find the post to the "article", and write their own general is the "essay", although I have no impact but still a little bit uncomfortable ...
Here is my second note, the basic syntax of Java.
First, identifiers
In the last note written in the "HelloWorld" inside, the real can be manipulated by me, only the quotation marks inside the HelloWorld, other places can not do any change. If I think of the sentences in the quotation marks I entered myself as a string of data, then the rest of the program is an identifier. It can be said that the entire Java language is written by the program is composed of identifiers and data.
Identifiers are divided into: System predefined identifiers, user custom identifiers.
1. System pre-defined identifiers are also called keywords, not more than dozens of:
abstract boolean Briea byte case catch char class const continue default Do double else extends assert final finally &NB Sp Float for goto If Implemen TS import instanceof int interface &nbs P STRICTFP package Private protected &NBS P;public return short static super Switch synchronized This throw  THR OWS transient sry void  VOLATILRE while
My English is very vegetable, if someone browses, found to write wrong must tell me
2. User-defined identifiers
This is a lot of, Java is now available in the API document is very much more than the user-defined, so many things can be categorized: classes, constants, variables, methods and so on. These things are used when coding, so there must be a specification when writing a name, and here are two categories:
A. Rigid specification
Java is strictly case-sensitive, that is, a and a are completely different; numbers cannot start with a name; You cannot name a custom identifier by using a keyword because the keyword already has a fixed meaning. Otherwise, you will not be able to compile.
B. Industry norms
That is, the rules that all Java programmers obey, so that they can propagate. Class name, each word capitalized; variable name, the first word is all lowercase, if it is composed of more than one word to be capitalized, the constant name, to all uppercase, if it is composed of multiple words in all uppercase and each word is separated by an underscore, the method name is the same as the variable name naming convention, the last verb of the word.
The above A, b two naming rules must be observed at the same time.
II. Basic data types
The data type has two functions:
1. Tell the computer how much memory space is allocated to the appropriate data type.
2. Tell the computer how to express the corresponding data type in the form.
Data types are divided into basic data types and complex data types. The former is the first definition of Java, and the latter is a combination of the basic data types, which is very complex and powerful. So as a cornerstone, the basic data types are still very important.
The basic data types are divided into four types of eight classes:
1. Integral type
A.byte
Byte is the smallest integral type and can only hold 1 bytes, also known as Byte type. Speaking of bytes, by the way, a supplement to it here, the computer's smallest storage unit should be "bit" in English called bit, it can only store a binary number (0 or 1), a byte is 8 bits, that is, the maximum number of 11111111 converted to decimal is 255. Byte cannot be a positive number, so although there are 8 bits, the upper limit of the range is not 255, which is 2 7 to 2 7.
B. Short
Short can hold an integer of 2 bytes, also known as shorter shaping. Its value range is 2 of 15 square to 2 of 15 square-1.
C.int
int can hold an integer of 4 bytes, also called shaping. Its value range is 2 of 31 square to 2 of 31 square-1. int is the most commonly used shape, and when you use an integer constant, the computer defaults to its type int if you do not declare it.
D. Long
Long is the largest integer that can hold 8-byte integers, also known as the Long Integer. Its value range is 2 of 63 square to 2 of 63 square-1. Constants for long integers must end with L.
2. Floating-point type
A. Float
The so-called floating-point type is used to store decimals, involving decimals on the existence of precision problems, the size of float is 4 bytes, also called single-precision type, can be accurate to 5 to 6 digits after the decimal point. Its value range is
3.4e-45~1.4e38 (can not understand, copy). Computer default all decimals are double type, so when you use float to declare a constant or variable, when you assign a value, you need to add F or F after the number.
B.double
The size of a double is 8 bytes, also known as a double type. It can be accurate to 12 to 13 digits after the decimal point. Its value range is 4.9e-324~1.8e308 (also copied).
3. Character type
Char
The character type has only one data type, char, whose size is 2 bytes and is used to hold a single character. Example: ' A ', ' medium ', these characters are called Unicode codes. The computer can only hold binary numbers, so the characters are stored in the form of conversion to digital encoding (ASCII code). It is worth mentioning that the ASCII code of ' A ' is 65, other uppercase letters and so on, ' a ' ASCII code is 97 other lowercase letters, and so on, uppercase and lowercase between 32; Escape character: Some keys on the keyboard are not directly represented by the character, this need to escape, such as: Enter the escape character is ' \ n ' or ' \ r '; tab ' \ t '; \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ In Computer eyes, char is actually a number, so it can be mathematically computed.
4. Boolean type
Boolean
The Boolean type also has only one data type, Boolean, whose size is indeterminate and determined by the JVM. Boolean differs from other primitive types by storing only two constants, true and false, for logical judgments.
Third, operator
If the data type is Java's representation of the data, then the operator operates on the data.
1. Assigning values
=, the equals sign does not have the same meaning in Java, but instead assigns the result to the right of the equal sign to the left of the equals sign. such as: a = 1; the value of 1 is assigned to a.
2. Arithmetic operators
+ 、-、 *,/,% (for redundancy). When the arithmetic operator and = meet, it becomes the + =,-=, *=,/=,%=, such as: A + = 1, meaning a = a +1; the more special is the + + 、--, which represents the self +1 or the self-1, when the increment/decrement is in front of the variable, if the variable is in the expression then the variable will do the self-increment/decrement Conversely, when the increment/decrement is behind a variable, if the variable is in the expression then the variable will participate in the expression first and then do self-increment/decrement.
3. Comparison operators
= = (equals),! =, >, <, >=, <=, their comparison results only two kinds: true/false.
4. Logical operators
A. Logic and
&, &&. such as A&b, a&&b, meaning a and B at the same time the result is true. The difference between & and && is that when a is judged to be false if the use is && then this code executes, B does not execute the opportunity, so && is called short-circuit and, conversely, using & regardless of A is really fake B will be executed.
B. Logical OR
|, | | |. such as a|b, a| | B, meaning A and b where one is true then the result is true. | | The difference is that when a is judged to be true, if it is used at this time is | | So this sentence is executed, B has no chance to execute, so | | Also known as short-circuit or, in contrast to the use of | When a is TRUE or false B will be executed.
C. Logical non-
! ,! A single-mesh operator only needs to be put! In front of a single expression that needs to be judged, the effect is to change true to False and false to true.
D. Xor or
^, such as: A^b, if A and B are the same, then the result is false; If a is different from B, the result is true. Any number XOR or its own result is 0; any number XOR 0 The result is it itself.
4. Bitwise operators
As the name implies, the bit here is bit, the bitwise operation is the binary operation. Bit operators are almost unused in Java, but this is something that needs to be understood.
<< is the left-shift symbol, meaning that the binary number to the left to move the number of bits, the number of moves after the automatic 0 to fill, in fact, how many bits to move the original number multiplied by 2 of how many times Square.
>> is the right-shift symbol, referring to the left-shift symbol, that is, how many bits to move the original number divided by 2 how many times Square. Of course, the move out of the range is lost.
&, | These two symbols can also do bit operations, called bits and bits or. ~ Call a bit counter.
5. Three mesh operator
? :, such as: a? B:c, meaning a must be a Boolean expression, A is determined, if a is true then execute the B statement, if A is false then execute the C statement.
Here is a little bit of a supplement to the data type operation, in Java, when the data type performs mathematical expression operations, there are the following elevation rules:
1. All byte, short, and Char will be promoted to int type once they participate in the operation;
2. If one of the operands in the expression is long, the result is a long type;
3. If one of the operands in the expression is float, the result of the calculation is also float type;
4. If one of the operands in the expression is double, the result of the calculation is also of type double;
Here the 1 to 4 does not violate, is judged in turn: Byte < short, char < int < Lang < float < Double this is called upward transformation, is automatically executed by the computer
We can also perform a downward transformation, but since it is large space to go to small spatial data accuracy there is a risk of being destroyed or lost, the computer does not automatically execute, so a downward transition must be enforced, called a cast: simply precede the data that needs to be transformed (the type you want to convert).
Type conversions are usually conversions of variables, and here's a quick look at variables and constants:
1. Variables
Before a variable is used, it needs to declare the type, then name the variable and initialize it. The reason to initialize is because the memory space you declared is stored in the case where you are not using the data of the last program that used this space (is this space empty?). The answer is not sure.)
2. Constants
Constants are divided into: literal constants and symbolic constants.
A. Literal constants, such as: number, true.
B. Symbolic constants, which need to be declared, the keyword final as the modifier of the constant, the FINLA data type constant name = XXX; The symbolic constants must be assigned immediately at the time of declaration and cannot be changed. Symbolic constants have two benefits: first, when using constants in many places, it is convenient to use symbols instead. Second, bring the business meaning into the constant value. The focus is on the second benefit.
Iv. notes
Comments are meant to make it easier for us to read into the code, and the computer will not react to it. Comments are divided into single-line comments, multiline comments, and text annotations. Where text annotations can generate DOS documents.
Single-line Comment://
Multiline Comment:/*
Comment Content
*/
Text Comment:/**
Comment Content
*/
Java Basic syntax