Getting Started with Java Learning (2)-Basic data types

Source: Internet
Author: User
Tags array length bitwise

1, variables: define variables: "Data type" variable name = Assignment ( so the defined variables are usually local variables, placed in the stack memory );

2, Identifiers : can have letters (can make any text), numbers, underscores, $ and so on, but can not start with a number, can not be reserved keywords, required to see the name of understanding.

3, data type : Byte,int,short,long,double,float,boolean.

A, where the Byte,short,int type Three will not occur to each other , but the three in the time of operation will be converted to int type .

b, at the time of the calculation of small capacity will automatically (ˇ?ˇ) to large capacity conversion. If you need to convert large capacity to small capacity, you need to force the type to reload, in some cases, the loss of precision. Cast: Long n = 100l;int i = (int) n;

C, Boolean only true and false two kinds of values, as a condition for judging.

4, Operator:+,-,*,/,% (modulo),--,++. (Note--, + +, either in front of the variable or behind the variable).

5, assignment operation : =; Be careful not to use the relational operator "= =";

6, the relational operator :>,<,>=,<=,!=,==; special attention, do not use "= =" as "=";

7. Logical operator:&,|,! ,^,&& (short circuit and), | | (short circuit or).

A, "^", xor, the same is false, do not need to be true.

b, the difference between & and &&:

&: Calculates the left, calculates the right, and then makes and computes the result.

&&: First calculate the left, determine whether it is true, the right expression is calculated, False, False, if the left expression is false return false, do not calculate the right expression.

8, bit operation: It is bitwise operation, ~ (bitwise negation),|,&;

9, shift operation:a<<b:a to the left B-position, removed from the low-fill 0;

A>>b shift the B-bit to the right, and the shifted-out bits complement the original sign bit; (Signed shift)

A>>>b b bit to the right, shifted out of the bit 0;(non-symbolic shift)

10, trinocular operator:x? The y:z;x is true to output the Y condition, and X is false to output the x condition.

Note: For the priority of the operation, do not rote, please use parentheses to distinguish.

11, array: as a tool to store big data, as a data type, but itself is a reference data type, that is, the class pointer.

Static initialization: int [] ARR; Define array names

ARR = new int [] {data}//Initialize, create a new array memory space, and allocate 3 memory space to assign the initialization value. Initialization can also be simply written as: ARR = {data}.

Dynamic initialization: Type ARR =new type [length]-when defined, the array length is specified, allocating memory space, but the system assigns the initial value.

Attention:

1, the storage of the array is divided into two parts, the array name exists in the stack memory , can be directly referenced; the initialized data exists in the heap memory , can not be directly referenced, only by the array name can be referenced to use the data defined in heap memory.

2, when the subscript of the referenced array exceeds the definition, compile without error, but the runtime throws an exception, Array index out of Bounds Exception; (Array out-of-bounds exception).

3, the reference to a non-initialized array, the same compile time will not error, but the runtime will report null pointer exception .

Getting Started with Java Learning (2)-Basic data types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.