Lesson two, basic data types and operators for Java

Source: Internet
Author: User

Basic data types for Java

(1), Basic data Types overview

|-data type, in the computer for data storage has a certain specification.

|-What kind of data is needed to load the data container.

|-in Java; The basic data type is not a standard object-oriented design, but it is retained to manipulate the processing of data by accommodating some basic values and representations of special States (such as Boolean types).

(2) Classification and introduction of data types

|-int (integer type)

|-byte

|-Short

|-int (when representing integers, the system will customize the default usage of the int type as the Java integer data if there is no explicitly defined int, or 3 other types)

|-long

|-floating point (decimal type)

|-Float

|-double (when representing decimals, the system will customize a double type as the default usage of Java floating-point data if it is not explicitly defined as whether it is a float or a double)

|-character

|-char (Character, serializable character set, low-level Unicode encoding set) and does not allow the presence of negative forms

|-Char ch = ' A '; or char CH2 = ' country ';

|-Boer

|-Boolean flag = True/false; Either "true" or "false", there is no value in addition to it.

(3), conversion of data types

|-Implicit conversion

|-Automatic type conversion: The amount of data in a small range, stored to a large range of data.

|-Explicit conversion

|-Coercion type conversion: The opposite is the above, but the target data type needs to be provided.

|-such as:

int i = 100;

Short s = i;//This is wrong, even if the value of I is within the short range, because the assignment, the conversion is not the size of the value as the standard, but the data type as the stored legal datum.

Should read: Short s = (short) i; This means that the value of I is converted to a short type of data, which is then assigned to short s variable (memory interval).

Second, Java operators

(1), arithmetic operators

|-Four mixed operation

|-for remainder (%), the symbol of the remainder is always the same as the symbol of the divisor!

(2), relational operators

|-The operation result of the relational operator is always a Boolean type value!

|-such as: larger than size, greater than, equal to, less than equals ...

(3), logical operators

|-Non (! )

|-With (&&)

|-or (| | )

(4), bitwise operators

|-Left Shift (2 's exponentiation)

|-Move right (unsigned right, but Java says itself must be signed)

(5), other operators

|-such as: + =,-=, *=, etc...

(6), trinocular operator

|-(expression 0)? (expression 1: expression 2)

(7), object operators

|-String str = "HelloWorld";

Boolean flag = (str instanceof String);

Returns true to indicate that STR is a string object or is its subclass object

Returns false to indicate that STR is not a string object

" priority: do not need to remember in daily development, all use parentheses, flexible design expression operator execution sequence!" "

Lesson two, basic data types and operators for Java

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.