JAVA- basis - the basic data types

First, the amount of direct

  1. Digital direct quantity

    java support in decimal, binary, octal amount directly, on behalf of hexadecimal digits, where the binary, octal, hexadecimal need to begin with a different prefix.

    

  2. The amount of characters directly

    java by single quote character represents a character directly enclosed amount

    A character can only represent a direct amount of character, can not be written directly to the amount of more than one character in a character

    Available characters are not allowed direct amount

    

 

  3. The amount of direct Boolean

    java having true and false boolean amount directly representative of the logic determination time.

    The amount of direct boolean has only two:

    

Second, an overview of the data type

    java language can handle a wide variety of different types of data, characterized by different types of data in the java language data type, which is called the concept of data types.

    java data type is divided into the basic data types and the reference data type (complex data types)

Third, the basic data types

  1 Overview

    

    About boolean byte length of one still under dispute will explain in detail, in advance say is a byte

  2.byte

    Byte number, one byte

    May represent a number in the range -2 ^ 2 ^ 7 ~ 7-1 (-128 to 127)

    Its binary representation, the first binary bit that indicates negative, n 0, a negative value the other binary bit representation.

    The maximum value of a byte in the minimum of -1 or +1 will cause data overflow annular configuration

    

  3.short

    Representative short integer numbers, occupies two bytes.

    May represent 15 -2 ^ 15-1 to 2 ^ (-32768 to 32767).

    Its binary representation, the first binary bit that indicates negative, n 0, a negative value the other binary bit representation.

    Byte type and the like, on the maximum or minimum value -1 +1 will cause data overflow annular configuration

  4.int

    On behalf of plastic figures. It occupies four bytes.

    It may represent -2 ^ 31 to 2 ^ 31-1 (-2147483648 2147483647)

    Digital type most used in the java

    Digital direct quantity of java If not specified, the default type is int

    Its binary representation, the first binary bit that indicates negative, n 0, a negative value the other binary representation.

    Byte type and the like, on the maximum or minimum value -1 +1 will cause data overflow annular configuration

  5.long

    代表长整形数字,占用八个字节。

    可以表示  -2^63 ~2^63-1(-9223372036854775808  ~  9223372036854775807)

    所有long型数据直接量都要在数字后面加  l  表示。

    其二进制表示形式中,第一个二进制位表示正负,0位正,1位负,其他二进制位表示数值。

    和byte类型类似,在最大值上+1 或 最小值上-1都会造成数据溢出,构成环形

  6.float

    代表单精度浮点数。占用四个字节。

    所有float型数据直接量都要在数字后面加f表示。

    其二进制表示形式中,第一个二进制位表示正负,0位正,1位负,其他二进制位表示数值。

    和byte类型类似,在最大值上+1 或 最小值上-1都会造成数据溢出

    浮点数在进行运算时,可能存在精度不准确的问题,且没有办法完全的避免。

    

 1 package DataTaye;
 2 
 3 public class PrecisionProblem {
 4     public static void main(String[] args) {
 5         System.out.println(0.05+0.01);
 6         System.out.println(1.0-0.42);
 7         System.out.println(4.015*100);
 8         System.out.println(123.3/100);
 9     }
10 }

  结果:

    

  7.Double

    代表双精度浮点数,占用八个字节

    所有double型数据直接量可以在数字后加d表示。

    如果浮点数没有加  f  或  d ,默认就是double。

    浮点数也可以用科学记数法形式表示。例如, 2.1231e3

    和byte类型类似,在最大值上+1 或 最小值上-1都会造成数据溢出

    浮点数在进行运算时,可能存在精度不准确的问题,且没有办法完全的避免。

    例子同上!

  8.char

    代表字符类型。占用2个字节。

    可以代表0~2^16-1  即  0~65535个字符。

    对于无法直接显示的符号支持通过转义字符来间接表示。

    转义字符以反斜杠开始,后跟一个普通字符来表示,不同转义字符有不同含义:

    

  9.boolean

    代表布尔类型,下篇详细讲解。

 

Guess you like

Origin www.cnblogs.com/xiaoluohao/p/11295472.html