Overview of Java data types and their operators

Source: Internet
Author: User

I. Java overview

1, the cross-platform of Java

Applications written in the Java language can be run on different system platforms, as long as a Java virtual machine (JVM Java VM) is installed on the operating system that needs to run the Java application.

2, JRE and JDK

JRE: Includes the core class libraries required for Java virtual machines and Java programs, and if you want to run a well-developed Java program, you only need to install the JRE on your computer.

JDK:JDK is available to Java developers, and includes Java development tools and JRE.

Java programs developed using the JDK are delivered to the JRE to run and are guaranteed to be cross-platform by the JVM.

Ii. Data types

650) this.width=650; "title=" K0my@1uk]ma ' JMJQ0@PIC3K.png "alt=" Wkiol1lgjxcjswq9aaa5szsdnra531.png "src=" https:// S5.51cto.com/wyfs02/m00/99/44/wkiol1lgjxcjswq9aaa5szsdnra531.png "/>

Note: integers default to int type, float type defaults to double type (double) takes 8 bytes

Float (single-precision float) takes 4 bytes, and if the data is float, f/f should be added at the end of the data.

1, default initial value

Integer type: 0; floating-point type: 0.0; character: space; reference data type: null; Boolean: false;

2, type Conversions (Boolean types cannot be converted to other data types )

(1) Automatic type conversion: small capacity → large capacity

Egg:char, Byte, short→int→long→float→double

(2) Forced type conversion: Large capacity → small capacity ( may result in loss of precision )

650) this.width=650; "Width=" 410 "height=" 239 "title=" D (o5r '} (LE ' BGYEJ4) [01pp.png "style=" WIDTH:433PX;HEIGHT:239PX; " alt= "Wkiom1lglutdszmaaaar-g3ngi0948.png" src= "https://s3.51cto.com/wyfs02/M00/99/45/ Wkiom1lglutdszmaaaar-g3ngi0948.png "/>

Three operators

1, arithmetic operator +-*/% + +--

(1) The string is an operation between the base data type, only the join operation, and the result is still a string.

(2) The symbol for the result of the% modulus (take remainder) depends on the preceding number.

Egg:5% 3 = 2

-5% 3 = 2

5%-3 = 2

(3) difference between front + + and post + + (--same)

First + + 1, after doing the operation, after + + to do the first operation, after the increase of 1.

650) this.width=650; "title=" QQ picture 20170619173629.png "Src=" https://s4.51cto.com/wyfs02/M01/99/5E/ Wkiol1lhm1kxbo0daaavikngbbe010.png "alt=" Wkiol1lhm1kxbo0daaavikngbbe010.png "/>

2, assignment operator = + = = *=/=%=

Egg:i + = 3; i = i + 3; (recommend the former notation)

Note: note the difference = (Assignment, assign the right value to the left) = = = (denotes equal sign, both sides)

3, logical operators & with | or! Non-^ XOR && short circuit with | | Short Circuit or

(1) A logical operator can only be used to connect a Boolean type expression.

Egg: 3 < x < 6; (wrong notation) x > 3 & x < 6;

(2)differences between & and && (| || Similarly, it is recommended to use && | | )

&: No matter the left side is true/false, the right side will be calculated;

&&: False on the left and no operation on the right.

4, bitwise operators << left shift >> right shift >>> unsigned Right shift & | ^ ~ Anti-code

bitwise operators are moved at the bottom of the computer, and are all complementary operations .

>> after the highest level is 1 with 1 complement, is 0 with 0;>>> shift after the highest level, whether 1, 0, are used 0 to fill.

Application of Egg (^): 12 ^ 5 ^ 12 = 5; 12 ^ 5 ^ 5 = 12;

5 , trinocular operator (can be replaced with If-else)

Format: (conditional expression)? Expression 1: Expression 2;

If conditional expression result is turn, the result of operation is expression 1;

The IF condition expression evaluates to False, and the result of the operation is expression 2. (expression 12 must be of the same type)

If-else Replace: if (conditional expression) {

Expression 1;

}else{

Expression 2;

}

Overview of Java data types and their operators

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.