Home  >  Article  >  Java  >  Default values ​​for eight basic data types in Java

Default values ​​for eight basic data types in Java

高洛峰
高洛峰Original
2017-01-22 10:15:371926browse

Use a piece of code to test the default values ​​of 8 basic data types

package dierge;
public class Ceshi {
int a;
double b;
boolean c;
char d;
float f;
byte e;
long h;
short j;
public static void main(String args[]){
Ceshi a=new Ceshi();
System.out.println("整型的默认值是:"+a.a);
System.out.println("双精度浮点型的默认值是:"+a.b);
System.out.println("布尔型的默认值是:"+a.c);
System.out.println("字符型的默认值是:"+a.d);
System.out.println("byte的默认值是:"+a.e);
System.out.println("单精度浮点型的默认值是:"+a.f);
System.out.println("短整型的默认值是:"+a.j);
System.out.println("长整型的默认值是:"+a.h);
}
}

The running results are as follows:

The default value of integer type is: 0

Double precision The default value of floating point type is: 0.0

The default value of Boolean type is: false

The default value of character type is:

The following conclusions are drawn:

Basic type default value

byte
short
int
long
0L
float
0.0f
double
0.0d
char
'\u0000'
boolean
false

The above are the default values ​​​​of the eight basic data types in Java introduced by the editor. I hope it will be helpful to you. Everyone is helpful. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!

For more articles related to the default values ​​of the eight basic data types in Java, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn