Character类

  1. package com.yuque.phil616.builtin;
  2. public class CharacterClass {
  3. char ch = 'a';
  4. // the form of character in Unicode:
  5. // 这个字符是栈内存储存的
  6. char uniChar = '\u039A';
  7. // array of a character:
  8. char[] charArray ={ 'a', 'b', 'c', 'd', 'e' };
  9. void testCharacterClass(){
  10. Character ch = 'a';
  11. /*
  12. * 下面的语句是标准的通过对象来创建一个字符类
  13. * Character ch = new Character('a');
  14. */
  15. // code above is the usage of Character object
  16. // the original character of 'a' boxing to Character object chs
  17. Character chs = 'a';
  18. }
  19. }

Math类

  1. package com.yuque.phil616.builtin;
  2. public class MathClass {
  3. /**
  4. * Java提供了八种基本的数据类型
  5. * 不过在开发过程中如果需要使用对象的时候,将基础的类进行封装boxing
  6. * 为了解决类的问题,java提供了如下类进行打包和拆包
  7. * the relations between them look like this.
  8. * Object ->|---Character
  9. * |---Boolean
  10. * |---Number --->|---Byte
  11. * |---Short
  12. * |---Integer
  13. * |---Long
  14. * |---Float
  15. * |---Double
  16. */
  17. Integer oi = 1;
  18. /**
  19. * for easy to develop and calculate,Java provide Math class.
  20. * the methods inside this class can help us to calculate special
  21. * math problems.
  22. *
  23. */
  24. void mathFunc() {
  25. System.out.println("Sin of 90 degree " + Math.sin(Math.PI / 2));
  26. System.out.println("cosine of 0 degree " + Math.cos(0));
  27. System.out.println("tangent of 60 degree " + Math.tan(Math.PI / 3));
  28. System.out.println("the arc-tangent of 1 " + Math.atan(1));
  29. System.out.println("degrees of π/2 " + Math.toDegrees(Math.PI / 2));
  30. System.out.println(Math.PI);
  31. }
  32. }

String类

  1. package com.yuque.phil616.builtin;
  2. public class StringClass {
  3. /**
  4. * String class is a very usual class in java.
  5. * Before the examples, we need to know some computer
  6. * concepts.
  7. * Public areas and Heap
  8. * Public areas are the common ram space, it stored the
  9. * local variables and some strings.
  10. * Heap is a spacial area in ram.
  11. * Heap can stored objects with new operator.
  12. */
  13. String str1 = "phil616";
  14. String str2 = new String("phil616");
  15. /**
  16. * str1 and str2 have the same context,however the java won't
  17. * think that.
  18. */
  19. void testStrings(){
  20. if(str1 == str2) {
  21. System.out.print("they are same");
  22. }else{
  23. System.out.print("they are not same");
  24. }
  25. }
  26. /**
  27. * key word 'new' comes from C++, it will create a empty space in
  28. * heap to stored information. In this case, different object are
  29. * not the same thing though they have the same context.
  30. */
  31. String str3 = new String("phil616");
  32. //objects belongs different heap ares, so they are not same concept
  33. //of values
  34. /**
  35. * different from the String, the objects created by StringBuffer
  36. * or StringBuilder are allow to change and operate by its methods
  37. * The methods below will show the usage of this classes
  38. */
  39. void StringBuilderTest(){
  40. StringBuilder sb = new StringBuilder(10);
  41. sb.append("phil616..");
  42. System.out.println(sb);
  43. sb.append("!");
  44. System.out.println(sb);
  45. sb.insert(8, "Java");
  46. System.out.println(sb);
  47. sb.delete(5,8);
  48. System.out.println(sb);
  49. }
  50. //When we are force to keep the thread secure, we have to use StringBuffer
  51. void StringBufferTest(){
  52. StringBuffer sBuffer = new StringBuffer("github public website");
  53. sBuffer.append("www");
  54. sBuffer.append(".github");
  55. sBuffer.append(".com");
  56. System.out.println(sBuffer);
  57. }
  58. }