The third-day variant of JAVA's faltering self-study

Source: Internet
Author: User
Tags float double

Data type

Byte 8-bit signed integer-any integer between 128 and 127

Any integer between short 16-bit unsigned integer -32768~32767

An int 32-bit signed integer -2^31 to 2^31-1 any integer

Long 64-bit signed integer -2^63 to 2^63-1 any integer

Float 32-bit single-precision floating-point number according to ieee754-1985 standard

Double 64-bit dual-precision floating-point number according to ieee754-1985 standard

A variable is an address space in memory that stores an invariant value. Because Java is a strongly typed computer programming language, there are mandatory partitioning of data types.

Define the variable's format data type variable name = Assignment

Personal understanding is that we want to create different sizes of paper boxes to put different sizes of things.

For example, the four-sided paper box size has 1th number 2nd number 3rd number 4th is different to store a byte short int long four different size values; floating-point type is the triangle paper box size 1th number 2nd size does not Same as for storing float double two different values other types are so good to understand, huh?

The default integer is that floating-point decimals with int type default to the default of double type, which is also possible with the largest box, but in order to effectively utilize the memory space, it is necessary to define the type of the variable according to the specific situation.

Type conversion Btye x = 8; Define a variable X of type Btye and assign a value of 8, (8 Although the default is int type, but Java automatic judgment is not in the range of Btye if 8 is automatically converted to byte type of data. If the error is not within the range)

The result is an error.

x = x+4; 4 The default is the int type of data Oh, the x in the expression is automatically promoted to the int type data, so the result of the x=4 operation is the int type data now. We cannot assign a value to a variable x of type Btye. What if the output would be an error now?

System.out.println (x);

Output error

Because the 4 default is the int type x is the Btye operation, the result is an int type, so it cannot be assigned to a byte type X if the required cast (Btye) (x+4) type to be assigned to the byte type is enclosed in parentheses.

System.out.println (x);

In addition the char type can also be converted to the int type because the data of type char is 16 bits of data. Oh, int is a 32-bit representation of the relationship between them with that asscii table, so you can type the conversion.

char x = ' a '; Define a variable X of type char and assign a value of ' a ', remember that it is a character value oh be sure to use single quotes.

x+1;   1 is a numeric value of type int x is a numeric value of type char that is automatically promoted to type int because the corresponding relationship of the ASSCII Code table corresponds to a value of 97, so the result of the operation is an int of type 98 now if you want to put in a char type variable x, you need to cast it. x = (char) (x+1);

I am a farmer of farming, oh, idle time to learn the next java. The most afraid of impatient, practice heart than practice what is important, patience, careful, perseverance, calm heart, the heart of the mind. Only let our calm down, work can persist. Encourage yourself. Although I am not young, although to now still nothing, but from now on, I want to insist on doing one thing, I want to do a thing, I want 5 years to sharpen a sword.

The third-day variant of JAVA's faltering self-study

Related Article

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.