package com.yuque.phil616.datatype;public class DataType { public static void main(String[] args) { /** * **********CHAPTER ONE************* * there are eight basic datatype in java. * they are * byte short int long boolean char * double float * and when the basic data type variable have been declared * each variable will be assignment a default value. * following statement shows the default value */ showDefaultValue(); /** * ***********CHAPTER TWO************* * reference data type * reference type just like pointer in C/C++, it cannot be changed or modify * once the reference type be confirm, it can refer any familiar * like String type */ String str = new String("Hello World!"); /** * constant type, the constant data type in java is distinguish between C/C++ * in C/C++, we use key word const to represent a constant value, however ,in java * we use key word 'final' to represent a constant value; */ } public static void showDefaultValue(){ int varInt = 0; byte varByte = 0; short varShort = 0; long varLong = 0L; double varDouble = 0.0D; float varFloat = 0.0F; /** * We suggest add big F behind the value of float instead of small f * and it also suggest use double data type instead of float, because * they do not have much differences in universal computer */ boolean varBool = false; char varChar = '\u0000'; System.out.println(varInt); System.out.println(varByte); System.out.println(varShort); System.out.println(varLong); System.out.println(varDouble); System.out.println(varFloat); System.out.println(varBool); System.out.println(varChar); }}
类型转换
package com.yuque.phil616.datatype;public class DataTypeConversion { /** * in fact, data type is not fixed in java, we can converse some of data type * into another type of data. * byte,short,char—> int —> long—> float —> double * byte type take one byte in ram space, however, short take up two * and int take up four * when we converse small space type into a large space type, it calls * auto data converse * on the contrary, it calls force data converse. * in some of situation, we need add f or F in the value of float * and at same reason, we need add d or D in the value of double * In the basic of computer, int,short,long,type,char are stored * in same way, because they represents the same kind of data * which is integer numbers, just with different length. * and we can invest more at runoob.com/java/java-basic-datatypes.html */}