[02] java data type and knowledge of operators

The 00 Java annotations

To facilitate the reading program, Java language allows the programmer to write a program in some descriptive text, to improve the readability, which is called the caption of a comment. Comments do not appear in the byte code file, that statement will skip comments Java compiler compile time. In Java, according to the functional annotation of different, mainly divided into single-line comments, multi-line comments and documentation comments.

1. Single-line comments: using the "//" at the beginning, "//" single-line comments are behind the content.

2. Multi-line comments: The "/ " beginning with " end /" in the "/ " and " content between / 'for comment, we can also use multi-line comments as inline comments. But pay attention when using multi-line comments can not be nested.

3. Documentation Comments: The "/ *** beginning" to " end /" and the comment contains some descriptive text and a number of JavaDoc tags (when the latter written project, you can generate API project) **
/ **

 * Welcome class (I'm documentation comments)
 * @Author ultra-brother
 * @version 1.0
 */
public class Welcome {
    // I am a single line comment
    public static void main (String [] args / * My comment is inline * /) {
        System.out.println("Hello World!");
    }
    /*
       I am a multi-line comment!
       I am a multi-line comment!
     */
}

  

01 Java identifiers in the nomenclature hump &

Identifier is used to variables, classes, methods, and naming package, such as Welcome, main, System, age, name, gender and the like. Identifiers need to comply with certain rules:

  1. The identifier must be a letter, underscore _, the dollar sign ($) at the beginning.
  2. Identifier may be other portions of letters, any combination underscore "_" dollar sign "$" and numbers.
  3. Java identifiers are case sensitive, and unlimited length.
  4. Java identifier can not be a keyword.
  5. Use identifier

Represent the class name identifiers: the first letter of each word, such as Man, GoodMan
identifier representing methods and variables: the first word lowercase, beginning from the second word capitalized, which we call "hump principle "such as eat (), eatFood ()
[Note]: Java does not use the ASCII character set languages commonly used, instead of using such standard Unicode international character set. Therefore, the meaning here is not just the English alphabet, also includes Chinese characters and so on. But we do not recommend the use of Chinese characters is defined identifier!

Valid identifier

int  a = 3;
int  _123 = 3;
int  $12aa = 3;
int variable 1 = 55; // illegal, but we do not recommend the use of Chinese name identifiers

  

Not valid identifier

int 1a = 3; // not start with a number
int a # = 3; // not include special characters #
int int = 3; // can not use the keyword

  

The basic data types 02 Java

Java is a strongly typed language, each variable must declare its data type. Java data types can be divided into two categories: basic data types (primitive data type) and the type of reference data (reference data type) (reference data type of uniform size is 4 bytes, which is the address of record of the reference object, behind the proposed terms of reference types will specifically)

Java class 3 defined eight kinds of basic data types

Numeric - byte, short, int, long , float, double
char - char
Boolean -boolean
Here Insert Picture Description

The 03 Java operator

Here Insert Picture Description
In the arithmetic operators +, -, *, /,% are binary operators, binary operators refers to the need to complete the two-operand arithmetic operators. Wherein% is the modulo operator, we often say that the remainder operands.

Binary operator operation rule:
integer arithmetic:

1. If both operands have one of Long, the result is also a long.

2. When there is no long, the result is int. Even operands are all short, byte, the result is int.

Floating-point operations:

3. If both operands have a double, the result is double.

4. Only two operands are float, the result was a float.

A modulo operation:

1 which may be a floating-point operands, integer generally used, the result is the "remainder", "remainder" left operand and the same reference numerals, such as: 3 = 1 7%, 7% 1,7% 3 = -3 = 1.

The arithmetic operators +, - is a unary operator, such operators require only one operand.

Unary + and -

int a = 3;
int b = a ++; // after the implementation, b = 3. B give an assignment, and then increment.
System.out.println("a="+a+"\nb="+b);
a = 3;
b = ++ a; // implementation of the latter, c = 5. a first increment, to give the assignment c
System.out.println("a="+a+"\nb="+b);

  

result:

a=4

b=3

a=4

b=4

The 04 Java assignment and the assignment operator extension

Here Insert Picture Description

int a=3;
int b=4;
a + = b; // equivalent to a = a + b;
System.out.println("a="+a+"\nb="+b);
a=3;
a * = b + 3; // equivalent to a = a * (b + 3)
System.out.println("a="+a+"\nb="+b);

  

operation result:

a=7

b=4

a=21

b=4

The 05 Java relational operators

The result of a relational operation is a Boolean value: true / false;
Here Insert Picture Description
Note points:

1 = is the assignment operator, and determines whether or not the real two operands is equal == operator.

2. ==,! = All (basic and reference) data types can be used

3>,> =, <, <= only for numeric type (byte / short / int / long, float / double.

06 Java logical operators

Operands and the result is a boolean logic operations.
Here Insert Picture Description
Or the short-circuit and short circuit by way of a short circuit. Left to right, it can be determined if only by the left operand of the value of the logical expression, it will not continue to calculate the right operand the operator, to improve efficiency.

The 07 Java Bitwise Operators

Bitwise refers binary bit operations
Here Insert Picture Description

int a = 3*2*2;
int b = 3 << 2; // equals: 2 * 3 * 2;
int c = 12/2/2;
int d = 12 >> 2; // corresponds 12/2/2;

  

important point:

  1. & And | is both logical operators, also a bit operator. If the number of sides of a boolean operation is, as it is logical operators. If the operands are both integer type, it is bitwise operators.

  2. Do not put "^" as math, "power" and "bit XOR" operation.

The conditional operator 08 Java

Syntax

x ? y : z

Wherein x is a boolean type expression, to calculate the value of x, if it is true, the result of the whole operation of the y value of the expression, or the whole calculation result of the expression values ​​of z.

Guess you like

Origin www.cnblogs.com/Linc93/p/12152652.html