Java基础(2)-基础类型

时间:2024-03-21 15:33:08

java基础类型

基础类型

package knowledge.base;

public class Properties {
    /**
     * 整型
     * int      4字节 -2 147 483 648 ~2 147 483 647(正好超过20亿)
     * short    2字节 -32 768 ~ 32 767
     * long     8字节 -9 223 372 036 854 775 808 ~ 9 223 372 036 854 775 807
     * byte     1字节 -128 ~ 127
     */
    public int numberInt = 1;
    public short numberShort = 2;
    public long numberLong = 3;
    public byte numberByte = 4;

    /**
     * 浮点型
     * float    4字节 有效数字 6~7位
     * double   8字节 有效数字 15位
     */
    //无线大
    public double numberDouble = Double.POSITIVE_INFINITY;
    //无穷小
    public double numberDouble2 = Double.NEGATIVE_INFINITY;
    //不是数字
    public double numberDouble3 = Double.NaN;

    /**
     * char 型
     * 用于记录一个字符单元
     */
    public char strChar = 'a';

    /**
     * boolean 型
     */
    public boolean b = false;
    /**
     * 定义静态常量
     */
    public final static  int BUMBER_STATIC = 1;
    /**
     * 程序入口
     */
    @SuppressWarnings("unused")
    public static void main(String[] args) {
        /**
         * 定义一个变量
         */
        int variable = 1;
        /**
         * 定义一个常量 一般使用大写命名
         */
        final int CONSTANT = 1;

        /**
         * 数值转换
         * 精确转换
         *                char
         *                 ↓
         * byte → short → int → long
         *                    ↘
         *                float  double
         *
         * 失去精度
         * int → float
         * long → float
         * long → double
         */
        System.out.println("Java 属性类型知识");
    }

}