02_Java basic data types and operators _

Identifier

v      identifier is assigned to the class name, methods, or variables. An identifier can be letters, numbers in any order, underscore, dollar sign combinations, but can not start with a digit.
Note: Java is case-sensitive;

java character sets

v      java using the Unicode standard character set, can recognize up to 65,536 characters, the first 128 characters of the Unicode character set is the ASCII character set table .Unicode cover most of the country's "alphabet" letters; that is java class name variable names, etc. can be Chinese; because the Chinese character is a Unicode character set; it is not recommended development with Chinese identifier.

§         naming convention

-     Camel name: userName userSex

-     class name capitalized

-     variables, method names begin with lowercase letters

-     Constant all capital letters

-     the package name all lower case

-     Project name capitalized

Constants and Variables

v      Constant is a value remains unchanged

v      variables a basic memory cell is a Java program. It consists of a variable identifier, optionally type and an initial value of a defined composition.
The variable values during program execution often

Variable memory space allocation

v      program to allocate memory for each piece of data, is generally used to store variable data. Use variables can reference data stored in memory, and whenever the need to display data or perform data manipulation.

§ How much memory is required

§ where the data is stored in

v      operating system is responsible Annotations variable address in memory

v      To reference value memory space, simply specify the variable name

Note

v      the Java annotations in three ways:

§ // single-line comment, a simple explanation of the meaning of the statement.

§ / * multi-line comments, to illustrate more content, including the algorithm.

    ……

   */

    •  / ** Java documentation comments by javadoc Health

    * Help documents into HTML format and type of interface.

    * This comment has its own special format (see related documents)

    */

type of data

v      the Java language is strongly typed language

§ each variable for each expression has type

§ type of parameters passed compatibility checks should be carried out

 

v      Category

§ basic data types (Primary Data Types)

§ complex data type (Composite Data Types)

Eight basic data types

v      Logical (or Boolean)

§ share memory: 1 byte

§ constants: true, false

§ variables: definitions using boolean

v      Integer

§ integer is an integer type, integral type: byte; short; int; long

V      byte (byte)

§ share memory: 1 byte

§ constants: 12, 32 (decimal); 033 (octal); 0x7F (hexadecimal)

§ Variable: Use byte definitions

v      For byte variables, memory is allocated to one byte, one byte consists of 8 bits (bit) composition; bit has two states are represented by 0, 1, so that the computer can store information by a binary number.

§ example: byte x = 7; the memory state: 0000111
most significant bit (the first bit on the left) is the sign bit, 0 for positive, 1 for negative; positive number represented by the original code; complement negative number (i.e., plus 1 negated) FIG.

§ example: byte x = the storage state of -8: 11111000
give complement -8, to obtain the original code 7 first, and then the original code. 7 0 to 1, 1 to a 0 is the complement -8 code.

Thus § byte variable in the range of -27 ~ 27-1 (-128 to 127)

v      Short integer

§ share memory: 2 bytes

§ constants: 12, 32 (decimal); 01133 (octal); 0x117F (hex)

§ Variable: Use short definition:

    • In the range: -2 ^ 15 to 2 ^ 15-1

v      int int

§ share memory: 4 bytes

§ constants: 12, 32 (decimal); 01133 (octal); 0x117F (hex)

§ variables: int using the definition:

    • In the range: -231 ~ 231-1

v      Long integer

§ share memory: 8 bytes

§ constants: 12, 32 (decimal); 01133 (octal); 0x117F (hex)

§ variables: use long definition:

    • In the range: -263 ~ 263-1
    • Note: When long-type variable assignment, after the number to uppercase or lowercase L

v      float (i.e. a decimal type) are two: float; double

v      float

§ share memory: 4 bytes

§ constants: 3.14F, 2.23f;

§ Variable: Use float definition:

    • In the range: 10-38 ~ 1038 ~ -10-38
    • Note: When a float variable assignment, the numbers must be uppercase or lowercase f

v      Float (double)

§ share memory: 8 bytes

§ constants: 3.14D, 2.23d, 23.23;

§ Variable: Use double definition:

    • In the range: 10-308 ~ 10308 ~ -10-308
    • Note: When you want to upper or lower double-type variable assignment (optional) d after digital

v      character; Java Unicode character set;

§ share memory: 2 bytes

§ constants: '?' 'A', 'A', '\ t', 'you', 'basic guarantee'

§ Variable: Use char Definition:

    • NOTE: character enclosed in single quotes

v      in the range: for char types of memory assigned 2 bytes, accounting for 16, the highest level is not used to represent the symbol. char type variable value of
0 to 216-1 (0 to 65535)

Data type conversion (implicit conversion)

v      integer, real, character data may be mixed operation. In operation, to different types of data into the same type, and then calculates, from lower to higher conversion:

       ---------------------------- Low> High

byte, short,char  >  int > long >  float > double

Cast

v      can be cast by the use of an expression is converted into a certain type, a unary operator.

v      The generic syntax conversion are:

(type) cast   

type any valid data type java

v      Data type conversion must satisfy the following rules:

§ boolean type can not be cast.

§ object types can not be converted into unrelated objects classes.

§ must be cast upon the type of conversion capacity of a small capacity type.

§ conversion process may result in overflow or loss of accuracy

§ floating-point to integer conversion is obtained by dropping the decimal, not round (int) 23.7 == 23, (int) -45.89f == -45

Char and int integer conversion

v        Character binary information is stored in the computer; value is stored in the character unicode character set sorting position.

v      character is 2 bytes of storage, but it is unsigned; it is larger than the range of short range character. Int char generally into each other;

expression

v      operators, and parentheses operand connecting line with equation java language syntax rules, referred to as expression

v      effective combination of operators and operands

v      operand can be a variable, constant or function

v      during program execution, and the actual values of the constants used in conjunction expression variables appearing in

v      expressions can be divided into:

§ arithmetic expression

§ relational expression

§ logical expression

§ function expression

v      operator precedence and associativity direction

§ executed in low priority order operator. For example, after the first addition and subtraction multiplication and division.

§ If the operand (or operands) of the same priority on both sides of the operator, the predetermined direction press java language binding (binding) performed.

v      Good writing habits source: in the expression, the left and right sides of each binary operators with a space, can enhance readability.

Assignment Operators

v      assignment symbol "=" is the assignment operator, its role is assigned the value of a variable of an expression.

v      general form: variable name = expression

v      is assigned to multiple variables with the value of the operation is called a multiple assignment

Operators

description

Bitwise AND 

( x & y )

If corresponding bits of two operands are 1, the bit value of 1 results

Bitwise or  

(X | y) 

If corresponding bits of two operands is a 1, then the result of the bit is 1

Bitwise
 (~ x) 

The bitwise operand
(0-1 and 1-0) 

Bitwise XOR

(X ^ y)

If the number of arithmetic operations to participate in the same number of two corresponding bits, the result is 0, compared with No. 1 iso

The left

( x<<2 )

Left (upper) portion was removed discarded, right (low) complement 0

Right

( x>>2 )

Right (lower) partially removed discarded, left (high) according to the sign bit is 0 or 1, unsigned 0 or a positive number up, make a negative

 

v      -bit binary numbers as the operator values, according to the corresponding bit operation, and then reconverted to a digital operation completes

In general, arithmetic operators higher priority than the logical operators than comparison operators assignment operators

 

Points added:

Other operators

              Static variables and constants call the class. Properties of the object   

              instantiate a new object. Heap memory allocated to the object region.

              () Call static class method object. Changing the operator priority      

              [] Array, the array elements to obtain by the reference numeral

              instanceof determines whether an object instance of a class.

Reproduced in: https: //my.oschina.net/u/2552902/blog/543914

Guess you like

Origin blog.csdn.net/weixin_34409703/article/details/92326413