Java basic data type conversion and operators, java Operators

Source: Internet
Author: User

Java basic data type conversion and operators, java Operators

The last time we talked about the basic data types in Java, today we will talk about the basic data type conversion in Java and the operators in Java

Basic data type conversion

Java can transform from any basic data type to an external Basic Data Type

Note: (boolean) data types cannot be converted to other data types.

Conversion is divided into default conversion and forced conversion.

Integer, complex, and floating point data are converted to each other in hybrid operations. The conversion follows the following principles:

(1) small data types are converted to large data types by default; data types are sorted by capacity:

Byte, short, char,-> int-> long-> float-> double;

Byte, short, and char are not converted to each other. They are first converted to the int type during calculation;

(2) When a data type with a large capacity is converted to a data type with a small capacity, it must be called a forced conversion character,

However, it may cause lower precision or overflow () (overflow occurs when double is converted to float;

(3) when there are multiple types of data mixed operations, the system will first automatically convert all the data into the data type with the largest capacity, and then perform the calculation;

(4) real number constants; Float Type: double by default; Integer constants: int by default;

Java program format;

(1) braces are aligned;

(2) If {indentation, Tab/Shift + Tab;

(3) adding blank lines between program blocks

(4) add spaces between side-by-side statements

(5) add spaces on both sides of the operator-specific conditions

(6) {leading space

(7) paired Programming

Operator

Java supports the following operators:

(1) Arithmetic Operators: +,-, *,/(entire division), %, ++ ,--;

(2) Relational operators: >,<,>=, <=, == ,! =;

(3) logical operators :! , &, |, &, |, (Short circuit and/or)

(4) bitwise operators: &, |, ^ (XOR ),~ (Reverse), >>,<<>>> (shifts right unsigned, fills with 0 );

(5) value assignment operator; =;

(6) extended value assignment operator; + =,-=, * =,/=,

(7) String concatenation operator; +;

(8) three-object operator X? Y: Z;

 

Value assignment operator and extended value assignment operator

 

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.