1. package com.yuque.phil616.datatype;
  2. public class DataType {
  3. public static void main(String[] args) {
  4. /**
  5. * **********CHAPTER ONE*************
  6. * there are eight basic datatype in java.
  7. * they are
  8. * byte short int long boolean char
  9. * double float
  10. * and when the basic data type variable have been declared
  11. * each variable will be assignment a default value.
  12. * following statement shows the default value
  13. */
  14. showDefaultValue();
  15. /**
  16. * ***********CHAPTER TWO*************
  17. * reference data type
  18. * reference type just like pointer in C/C++, it cannot be changed or modify
  19. * once the reference type be confirm, it can refer any familiar
  20. * like String type
  21. */
  22. String str = new String("Hello World!");
  23. /**
  24. * constant type, the constant data type in java is distinguish between C/C++
  25. * in C/C++, we use key word const to represent a constant value, however ,in java
  26. * we use key word 'final' to represent a constant value;
  27. */
  28. }
  29. public static void showDefaultValue(){
  30. int varInt = 0;
  31. byte varByte = 0;
  32. short varShort = 0;
  33. long varLong = 0L;
  34. double varDouble = 0.0D;
  35. float varFloat = 0.0F;
  36. /**
  37. * We suggest add big F behind the value of float instead of small f
  38. * and it also suggest use double data type instead of float, because
  39. * they do not have much differences in universal computer
  40. */
  41. boolean varBool = false;
  42. char varChar = '\u0000';
  43. System.out.println(varInt);
  44. System.out.println(varByte);
  45. System.out.println(varShort);
  46. System.out.println(varLong);
  47. System.out.println(varDouble);
  48. System.out.println(varFloat);
  49. System.out.println(varBool);
  50. System.out.println(varChar);
  51. }
  52. }

类型转换

  1. package com.yuque.phil616.datatype;
  2. public class DataTypeConversion {
  3. /**
  4. * in fact, data type is not fixed in java, we can converse some of data type
  5. * into another type of data.
  6. * byte,short,char—> int —> long—> float —> double
  7. * byte type take one byte in ram space, however, short take up two
  8. * and int take up four
  9. * when we converse small space type into a large space type, it calls
  10. * auto data converse
  11. * on the contrary, it calls force data converse.
  12. * in some of situation, we need add f or F in the value of float
  13. * and at same reason, we need add d or D in the value of double
  14. * In the basic of computer, int,short,long,type,char are stored
  15. * in same way, because they represents the same kind of data
  16. * which is integer numbers, just with different length.
  17. * and we can invest more at runoob.com/java/java-basic-datatypes.html
  18. */
  19. }