Sun Xin's Java video learning notes (1)

Source: Internet
Author: User

Byte is a single-byte integer, which is an 8-bit signed integer between-127-127.
Byte B;
B = 3;
B = B * 3// Here, Java automatically performs an upward type conversion, converts the result of phase X to the int type, and assigns an int to the byte, causing loss of precision.
Here is a knowledge point (automatic type conversion) B = B * 3 here, Java will automatically convert byte to int to ensure accuracy during compilation, to ensure the accuracy of the result, therefore, the result after B * 3 is actually an int type, and assigning an int type to a byte will lead to loss of precision. Therefore, compilation fails here. Therefore, B = byte (B * 3) is required)

Short 2-byte integer 16-32768-32767 signed two-byte integer

Int 4-byte signed integer
Long 8-byte signed integer

Char two-byte, unsigned 0-65535 stored with assc II Code

Float 4-byte unsigned floating point number
Generally, decimal constants are of the double type, for example, 1.3. Therefore, the exact representation is 1.3f, which indicates that it is a float type. The four bytes have the same length as the int, and the first digit represents the symbol, 2-9 indicates the index, and the last 23 digits indicate the decimal part.

Double and float are the same, only eight bits, corresponding to long

Boolean has only two values: true and false.

When defining an array, it cannot allocate space. Therefore, it cannot be written in a way similar to C such as int num [3.
This is wrong
Int num [] = new int [3];// This is incorrect. The correct method is provided below.
The recommended method is
Int [] num;
Initialize the array during definition
Int [] num = {1, 2, 3 };//Initialization defined in this way can only be used during definition
The following method is incorrect for initialization.
Int [] num;
Num = {1, 2, 3}; // It is incorrect if you define it first and initialize it according to the above method.

There is another way to define arrays.
Int [] num = new int [] {1, 2, 3}; // new

Frequently used definition methods
Int [] num;
Num = new int [3] // allocate three spaces
Num [0] = 1;
Num [1] = 2;
Num [3] = 3; // assign values using Indexes

Two-dimensional array
Int [] [] num;
Num = new int [3] [4]; // The access method is the same as that of C.

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.