What are the basic Java data types? What is the automatic entry box?

"Fate Fu"

Accidents will happen, people have always happens. Centipede centipedes, snakes row less; rooster wings, fly, but the crow. Arima thousand miles away, can not ride no self to; people have towering ambition, not a non-operational self-taught.
Cover smell: A life, wealth can not be obscene, humble can not be moved. Article K-Swiss, Confucius Stranded on Chen Pang; superior military strategy, great-grandfather fishing in the Wei. Yan Yuan short life, the only special non evil; Pirates of the plantar older, did doer.
Emperor Yao Ming St., was born unworthy children; blind old man a fool, anti-big Takayuki birth to a son. Zhang was originally a commoner, Xian Li Xiao title. Yan Zi body without five feet, Qi Feng as prime minister; Cao Lu Ming lying ranking, can make Shu military advisor. Although the male Chu Pa, defeated Wujiang Suicide; Hanwang though weak, as much as rivers and mountains. Guang Wei have shot the tiger, not to the old seal; Pingtang have only the dragon, once in a lifetime. When Han did not encounter it, no three meals a day, until the case of the line, three feet Yaoxuan jade seal, once when bad, negative people died in the hands.

Daily chicken blood:

Chong Chong Chong!  !  !

text:

The basic concept of type:

      Java的基本类型可以简称为“四类八种”:
  • Integer: byte, short, int, long (integer data type defaults to int)
  • Floating point: float, double. (Floating-point data type defaults to double)
  • Character: char
  • Boolean: boolean (true true, false false)

       数据类型转换:
  • Automatic type conversion (automatic), is converted to a smaller type larger Type:
    byte -> Short -> char -> int -> Long -> float-> Double

  • Cast (hand), cast a larger to a smaller type:
    Double -> float-> Long-> INT-> char-> SHORT-> byte

       数据类型对比表:

Here Insert Picture Description

What is packaging?

    因为Java是一种面向对象语言,很对地方都需要使用对象而不是基本数据类型
    比如,在集合中,我们是无法将int,double等类型放进去的.因为集合的容器要
    求的是Object类型.

     为了让基本类型也具备对象的特征,就出现了包装类型,他相当于将基本类型”包
     装起来”,使得他具有了对象的性质,并为其添加了属性和方法,丰富了基本类型的操作.

What is the automatic entry box?

  在Java SE5中,为了减少开发人员的工作量,Java提供了自动拆箱和自动装箱的功能。
  • Automatic unboxing: basic data type is automatically converted to the corresponding type of packaging
  • Automatic packing: the package type is automatically converted into a target basic data types

Automatic packing and unpacking those scenes will happen?

  • The basic data types into collections
  • Package type and size comparison of basic data types
  • Package Type of operation
  • Calculation using trinocular
  • Function parameters and return values

intwithIntegerWhat's the difference?

 基本使用对比:
Compared
Integer Slow stack package type = null initial value
int Basic data types stack faster initial value = 0
 深入对比:
  • New Integer two objects are generated, different memory addresses:
Integer i = new Integer(100);
Integer j = new Integer(100);
System.out.println(i==j);//false
  • Packaging and basic types int Integer comparison, Integer is automatically unpack int:
Integer i = new Integer(100);
int j = 100;
System.out.println(i==j);//true
  • New generation of non-Integer array variable points to a cache static constant pool of storage, while the new generation of Integer variable to point to the heap, both on the show refers to a different address in memory:
Integer i = new Integer(100);
Integer j = 100;
System.out.println(i==j);//false
  • Integer values ​​will be the number of cache [-128-127], will not be reused outside Integer, corresponding to each packing have a new Integer object
Integer i = 100;
Integer j = 100;
System.out.println(i==j);//true
Integer ii = 128;
Integer jj = 128;
System.out.println(ii==jj);//false  

Inspirational sentence ->The darkness will pass, the dawn will eventually come

Here Insert Picture Description

If you help us, then, not white prostitute Austrian ~ ~ ~
the wrong place, welcomed the comments below, I see every day ~ ~ ~

Released four original articles · won praise 6 · views 91

Guess you like

Origin blog.csdn.net/weixin_45302340/article/details/103947884