Java Fundamentals-Basic data types

Source: Internet
Author: User

Eight data types numeric: Integer type: Byte, shot, int, long

Byte: Length is 28 ( -27~27-1)

Shot: Length 216 ( -215~215-1)

int: Length 232 ( -231~231-1)

Long: Length 264 ( -263~263-1)

Float type: float, double

float: Length 232 (initialization required to add F after decimal, example: float num=3.14f)

Double: Length 264 (both forms of initialization can be, example 1:double num=3.1415926d; 2:double num=3.1415926)

Character type: Char

Char: Stores a single character, occupying 16 bits (two bytes) of memory space.

(The Java language can also treat characters as integers, because Unicode encoding uses unsigned encoding, and characters in Java correspond to integers between 0~65536, so char and int can show conversions to each other)

Boolean Type: Boolean

Boolean: The value is divided into: true and false;

Type conversion of numeric type

In expressions, such as:c=a+b;a>b?c:d;

Two number has a double type and the other is also converted to double type

Two numbers have one float type and the other is converted to float type

There is a long type in the two number and the other is also converted to a long type

Otherwise it will be converted to int type;

Converting a large range of numeric types to a small range of numeric types requires an explicit conversion and may be accompanied by a loss of precision.

Examples of interview questions

1. (false?) 10.9:9) What is the value?

Java is automatically type-converted based on the precision type of the operator, and 9 is automatically converted to 9.0 due to the presence of 10.9. So the result is 9.0.

2. Char x= "9"; (false?) X:10) The value of why?

When there is a constant expression in the expression (this is titled 10), the other type is T (this is the char type), and the constant expression can be represented by T, and the output is of type T.

The result of the subject is "10" of char type;

Java Fundamentals-Basic data types

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.