corejavae10v1p3.3 3rd Java BASIC Programming Structure-3.3 data types

Source: Internet
Author: User

3.3 Data types

The data type mentioned here refers to the basic data type in Java 8, which is the original existence.

Method of literal representation of different binary numbers

In-process Literal representation method Example Whether the default JDK Version Support
2 binary 0b or 0 B prefix (every 4 bits available _ delimited) 0b1001,0b1111_0100_0010 Java SE 7 Start
8 binary 0 prefixes 010
10 binary 010
16 binary 0x or 0X prefixes 0xCAFE

No number of unsigned types in Java

It makes no sense to talk about default values in Java, where the default value of a data exists only when it is declared as a member variable or as a static variable and initialized, and a compiler error occurs when a variable is not initialized.

3.3.1 Integer type (4 kinds)

td> 
type bytes indicates range default approximate range literal representation method /td> Example is the default literal type recommended
byte 1 –128 to 127 0 [        
short 2 –32,768 to 32,767  0 30,000 &NB SP;      
int 4 –2,147,483,648 to 2,147,483, 647 0 2 billion
long 8 – 9, 223,372,036,854,775,808 to 9,223,372,036,854,775,807 0L 9*1018 l or L suffix (400L) 400l< /td>    

3.3.2 Floating point type (2 kinds)

Type Number of bytes Representation Range Default value Valid digits (accuracy) (10 binary) Literal representation method Example Is the default literal type Is it recommended to use
Float 4 ±3.40282347e+38f 0.0f 6-7 Guests F or F suffix 3.14F
Double 8 ±1.79769313486231570e+308 0.0d 15 Guests D or D suffix 3.14d,3.14

16 binary exponential floating-point numeric representation method

Base Representation method Example General presentation Methods
With 2 as the base 0x***p*** Mark (Mantissa with 16-in, exponent with 10-binary) 0x1.0p-3 1.0x2-3

3 Special floating-point numbers

Double.positive_infinity Positive Infinity
Double.negative_infinity Negative infinity
Double.NaN Non-number (0/0 or negative square root)

The 1.Double class is an object wrapper over the Double type, java.lang.Double

System.out.println (2.0-1.1)

The output is 0.8999999999999999 instead of 0.9, the floating-point number in the actual storage with 2 binary storage, there is a loss of precision, a stake in the numerical calculation can not have any rounding error, using the BigDecimal class

3.3.3 character type (1 kinds)

The char characters in Java represent Unicode (that is, UTF-16) encoded characters.

Type Number of bytes Representation Range Default value Representation method Example
Char 2 \u0000 to \uffff ' \u0000 ' ' tags, which can be translated using \u and special characters ' A ', ' \u2122 ', ' \ n '

Commonly used char characters and translation characters

form of translation Name Unicode value
\ n Line break \u000a
\ r Enter \u000d
\ t Tab \u0009
\" \u0022
\‘ \u0027
\\ \ \u005c
π, the symbol of the digital pi \u03c0
?, trademark symbol \u2122

Unicode-type translatable characters can be used directly in the source code

 Public Static void Main (string\u005b\u005d args)

Equivalent to

 Public Static void Main (string[] args)

3.3.4 Unicode with Char

3.3.5 Boolean type

Type Default value Number of bytes Representation method Example
Boolean False After compilation, the int data type in the JVM is used instead, and the Boolean array is encoded into a byte array of the Java virtual machine, with each element having a Boolean element of 8 bits. This way we can conclude that the Boolean type takes up 4 bytes, and is 1 bytes in the array. True,false True,false

Boolean and other types are non-convertible, in C + +, 0 means false, and non-0 means no in True,java.

corejavae10v1p3.3 3rd Java BASIC Programming Structure-3.3 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.