Java.lang提供Java语言程序设计的基础类,可以不通过import直接使用。

Object

Java中处理基本类型,剩下的都是对象。Object类是所有类的超类,所有对象都继承了Object的方法,必要时可以重写这些方法。

  1. public class Object {
  2. private static native void registerNatives();
  3. static {
  4. registerNatives();
  5. }
  6. /**
  7. * equals
  8. * ‘==’ 对于基本数据类型,比较的是其值是否相等;对于引用类型则比较是否为同一对象
  9. * 如果没有对equals进行重写,则使用的是object中的equals方法,比较是否为同以对象
  10. */
  11. public boolean equals(Object obj) {
  12. return (this == obj);
  13. }
  14. /**
  15. * System.out.print打印命令会调用toString方法
  16. */
  17. public String toString() {
  18. return getClass().getName() + "@" + Integer.toHexString(hashCode());
  19. }
  20. /**
  21. * finalize
  22. * 对象被GC回收时会调用的方法
  23. */
  24. protected void finalize() throws Throwable { }
  25. /**
  26. * Causes the current thread to wait until either another thread invokes the
  27. * notify() or notifyAll() method for this object or
  28. * a specified amount of time has elapsed
  29. * The current thread must own this object's monitor.
  30. */
  31. public final native void wait(long timeout) throws InterruptedException;
  32. /**
  33. * Wakes up a single thread that is waiting on this object's monitor.
  34. *
  35. * This method should only be called by a thread that is the owner
  36. * of this object's monitor.
  37. */
  38. public final native void notify();
  39. /**
  40. * Wakes up all threads that are waiting on this object's monitor. A
  41. * thread waits on an object's monitor by calling one of the
  42. * {@code wait} methods.
  43. */
  44. public final native void notifyall();
  45. /**
  46. * getClass()
  47. * 返回该对象的类对象
  48. */
  49. public final native Class<?> getClass();
  50. /**
  51. * hashCode
  52. * 根据对象内存地址或者字符串或者数字算出来int类型的数值
  53. */
  54. public native int hashCode();
  55. /**
  56. * clone
  57. * 该对象需要实现Cloneable接口,否则会抛出CloneNotSupportedException异常
  58. * Object实现的clone(super.clone)方法为浅克隆,只能克隆对象本身和对象中的基本变量;
  59. * 如果要克隆引用对象,需要自己实现。
  60. * https://www.jianshu.com/p/ea8f7b1fbbb1
  61. */
  62. protected native Object clone() throws CloneNotSupportedException;
  63. }

MATH

  • floor
  • ceil
  • round

String

String对象保存在堆中,当以引号出现的时候保存在StringPool中
java.lang.string

  • string.substring() 获取子串
  • String join(CharSequence delimiter, CharSequence… elements)
  • char[] toCharArray()
  • boolean equals(0bject other)
  • boolean equalsIgnoreCase(String other)
  • char string.charAt()
  • boolean startsWith(String prefix)
  • boolean endsWith(String suffix)
  • String trim()
  • intern() 将字符放入StringPool中,如果调用的字符“abc”已经在池中,则返回池中的字符串地址。否则,新建一个常量加入池中,并返回地址

System

System类由final修饰,不能被继承;构造器由private修饰,不允许被实例化,方法都是static修饰的静态方法。

  • 标准输入输出流
    • public final static InputStream in 标准输入流
    • public final static PrintStream out 标准输出流
    • public final static PrintStream err 标准错误输出流
  • arraycopy,数组复制
  • exit() 退出虚拟机
  • System.currentTimeMillis, 获取系统当前时间
  • System.gc(), 主动进行垃圾回收
  • System.getProperties(), 获取系统属性,包括Java工作目录,os架构,jvm版本等信息

Exception

  1. ![image.png](https://cdn.nlark.com/yuque/0/2020/png/217875/1599296528463-3ab75826-7ad1-4f0d-a2b7-8aa1c2b4ea02.png#align=left&display=inline&height=335&margin=%5Bobject%20Object%5D&name=image.png&originHeight=670&originWidth=1117&size=407978&status=done&style=none&width=558.5)
  • Throwable
    • Exceptrion
      • 可查异常,在代码中必须被捕获,不然编译器会报错,要求在方法的末尾表明可能抛出的异常。
      • 运行时异常 ,不要求强制捕获,之所以会设计运行时异常的原因之一,是因为下标越界,空指针这些运行时异常太过于普遍,如果都需要进行捕捉,代码的可读性就会变得很糟糕。
  • Error 描述了Java运行系统中的内部错误以及资源耗尽的情形。应用程序不应该抛出这种类型的对象.一般是由虚拟机抛出。

参考:
错误信息的阅读:https://www.yuque.com/zhanghang-xhy01/gc0uxk/kofdmy/edit
https://blog.csdn.net/yshysh8/article/details/80015789