第2章 一切都是对象

本章节的整体结构说明

第二章整体结构图

基本类型

基本类型变量,不需要用new来创建,而是直接赋值即可。而且变量直接存储“值”,并置于堆栈之中。

Java程序实例:

public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("char:\t" + Character.SIZE/8 + " byte");
        System.out.println("byte:\t" + Byte.SIZE/8 + " byte");
        System.out.println("short:\t" + Short.SIZE/8 + " byte");
        System.out.println("int:\t" + Integer.SIZE/8 + " byte");
        System.out.println("long:\t" + Long.SIZE/8 + " byte");
        System.out.println("float:\t" + Float.SIZE/8 + " byte");
        System.out.println("double:\t" + Double.SIZE/8 + " byte");
    }

运行结果如下:

char:   2 byte
byte:   1 byte
short:  2 byte
int:    4 byte
long:   8 byte
float:  4 byte
double: 8 byte

表格说明如下:

基本类型大小最小值最大值包装器类型
void---Void
boolean---Boolean
char16-bit(2-byte)02^16-1Character
byte8-bit(1-byte)-128127Byte
short16-bit(2-byte)-2^152^15-1Short
int32-bit(4-byte)-2^312^31-1Integer
long64-bit(8-byte)-2^632^63-1Long
float32-bit(4-byte)IEEE754IEEE754Float
double64-bit(8-byte)IEEE754IEEE754Double

基本类型的默认值

Java程序实例:

public class default {
    static boolean bool;
    static char c;
    static byte b;
    static short s;
    static int i;
    static long l;
    static float f;
    static double d;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("boolean:  " + bool);
        System.out.println("char:\t" + c);
        System.out.println("byte:\t" + b);
        System.out.println("short:\t" + s);
        System.out.println("int:\t" + i);
        System.out.println("long:\t" + l);
        System.out.println("float:\t" + f);
        System.out.println("double:\t" + d);
    }
}

运行结果如下:

boolean:  false
char:   
byte:   0
short:  0
int:    0
long:   0
float:  0.0
double: 0.0

表格说明如下:

基本类型默认值
booleanfalse
charnull
byte(byte)0
short(short)0
int0
long0L
float0.0f
double0.0d

嵌入式文档说明

标签说明
@see引用其他类
@version版本信息
@author作者信息
@since允许的最早版本
@param标识方法参数
@return描述方法返回值
@throws异常对象说明
@deprecated建议不要使用这些旧特性
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值