Java Learning note 01--data types

Source: Internet
Author: User

Java Learning note 01--data types22 people read

Java Data type Partitioning

are divided into two main types:

    • Basic data type: similar to normal values.

    • Reference data type: The address of the memory is passed.

Floating-point types are actually representing decimals.

Java Basic data types

Overflow of data

When the data size of an integer exceeds the range that can be represented, and the value range is not checked in the program, the values output by this integer variable will be confused.

And not the expected run result. Example: Finding the maximum value of an integral type

public class T Span class= "o" >{public static void main (string[] args) {int max = integer. Max_valuesystem.. (" the maximum value of the integer is: "+max//integer is: 2147483647 }         

Now the maximum value to be asked for the addition operation

PublicClassT{PublicStaticvoidMain(String[]Args){IntMax=Integer.Max_value;System.Out.println (+max //the maximum value for the integer is: 2147483647 system. Out. ( "int" Maximum value + 1: "+ (max+1//integer maximum value + 1: -2147483648 system.. ( "int" Maximum value + 2: "+ (max+2//integer Maximum value + 2: -2147483647 }         

If you want to avoid data overflow now, you can expand the data type in a way. Int-->long

PublicClassT{PublicStaticvoidMain(String[]Args){IntMax=Integer.Max_value;System.Out.println("The maximum value for an integer is:"+Max);The maximum value of the integral type is: 2147483647System.Out.println("Maximum value of integer + 1:"+(max+1//integer maximum value + 1: -2147483648 system.. ( "int" Maximum value + 2: "+ (max+2//integer Maximum value + 2: -2147483647 system.. (+ ((longmax+2//2147483649 } }         

Character type

The character type occupies 2 bytes in memory and can be used to hold characters such as English letters. When a computer handles character types, it treats these characters as different integers.

Therefore, strictly speaking, the character type is also considered as one of the integer types.

PublicClassT{PublicStaticvoidMain(String[]Args) {char ch1 =  ' a ' //character is used "in the data char ch2 = 97< Span class= "O"; //defines character variables system.. ( "CH1 =" +ch1system.. ( "CH2 =" +ch2} }             /span>                

Commonly used escape characters

Floating-point type and double-precision floating-point number type

In daily life, the number of decimal types is often used, such as height, weight and so on, the whole number can not meet the requirements of the program designer.

In mathematics, these numbers with decimal points are called real numbers, and in Java this data type is called a floating-point type (float) with a length of 32 bytes.

The valid range is -3.4E1038 to 3.4E1038. There is also a double-precision floating-point number to use when the range of floating-point numbers is not large enough.

Double-precision floating-point number type is 64 bytes long and valid from -1.7E10308 to 1.7E10308

In Java, a number or a decimal actually has a default type:

    • The default type for decimals (1.1,1.2) is double type

    • The default type of integer (All-in-one) is type int

Boolean type

Boolean (Boolean) type of variable, only true (true) and false (false) two kinds

Default values for basic data types

Copyright NOTICE: This article uses the BY-NC-SA agreement to authorize, reproduced the Wheat Field Technical blog article please indicate the source

Original address: Http://itmyhome.com/2015/03/java-study-notes-datatype

Java Learning note 01--data types

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.