java常用关键字总结
发布日期:2021-05-15 01:31:25 浏览次数:19 分类:精选文章

本文共 7101 字,大约阅读时间需要 23 分钟。

Java���������������������

Java������������������������������������������������������������������������������������������������������������������������������������������static���synchronized������������������Java������������������������


1. static

������������������static������Java������������������������������������������������������������������������������������������������������������������������������������������������static������������������

  • ���������������������������

    ������������������������������������������������������������������������������.serName=���;static������������������������������������������������������������������������public static final String VERSION = "1.0";
    ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������CopyOnWriteArrayList������������������

  • ������������������������������

    ���������������������������������������������������Void main(String[] args);
    ��������������������������������������� utility������������������������������������������������������������
    ������������������������������������������������������������������������������������class������������

  • ������������������������������������������

    ���������������������������������������������������������������������������������������������������������������������������������������������������
    ���������static { System.out.println("������������������..."); }


2. final

final������������������������������������������������������������������

  • ������������final���������������������������������������field���method���������������������������������������������������������������
  • ���������������final������������������������������������������������������������������������������������������
  • ���������������final������������������������������������������������������������������������������������������ Field private static final List
    list = new ArrayList();
    final���������������������������������������������������������������������

3. try-catch-finally

try-catch-finally���������������������������������������������������������������������������������������

  • try������������������������������������������������������������������������
  • catch������������������������������������������������������������������������������������
  • finally���������������������������������������������������������������������������������

���������

try { readFile(); } catch (IOException e) { log.error(e); } finally { closeResource(); }

������������������try���catch���������������������finally������������������������������������������������������������������finally���������������������������������������������������


4. volatile

volatile������������������������������������������������������������������������������������������������������������������CPU������������������������������volatile���������������������������

4.1 ���������������

mallow���������������������������������������������������������������������������������������������������

4.2 ������������

voluble���������������������������������������������������������

public class Singleton {
private volatile static Singleton instance;
private Singleton() {}
public static Singleton getInstance() {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
return instance;
}
} ������used volatile������������������������������������������������������������


5. default

default���������������������������������������������������������������������������������������������������������������������������������

public default void method();

���������������������������������������������������������������������������������������������������


6. this

this���������������������������������������������������������������������������������������������������

  • ������������������������������������this���������������������Persona.name = this.name;
  • this������������������������������������������������������������������������staticField = this.staticField;
  • ������������������this(...)������������������������������������public Person(Address address) { this(address); }

7. super

super���������������������������������������������������������

  • ������������������������������������������������������super()���������������������������������������

    super();
    ���������������������������
    super(������);

  • ������������������������������������������������������������������������������super.���������������������

    super.fieldName;
    super.methodName();


8. throws

throws���������������������������������������������������������throw���������throws���������������������������������������������������������������������������������

public int calculate(int x, int y) throws ArithmeticException {
return x / y;
}

���������������java���������������������throws��������������������������������� ������������������������������


9. throw

throw������������������������������������������������������������������������������������������

public static void main(String[] args) {
throw new IOException("������������������������...");
}

���throws���������throw������������new������������������������������������������


10. synchronized

synchronized���Java��������� synchronize���������������������������������������������������������������������������������������

  • ���������������public synchronized void synchronizedMethod();
  • ������������synchronized {...}
  • ���������������synchronized(someObject);

10.1 ���������

synchronized������������������������������������������������������������������������������������

���������
public class SyncThread implements Runnable {
private static int count = 0;
public synchronized void run() {
for (int i = 0; i < 5; i++) {
System.out.println(Thread.currentThread().getName() + ":" + count++);
Thread.sleep(100);
}
}
}

10.2 ���������������

synchronized���������������������������������������������������������������������������������������������������������������������������


������������������������

������������������������������������������final���static���������

���������

  • static������������������������������������������������������������������������������������������������������
  • final���������������������������������������������������������������������������������������������������������������

���������catch������������������������finally������������������

���������
���������������try-catch���������������������������finally������������������������JVM������������������������������������������������������������������catch���finally���������������

���������throw���throws������������������

���������

  • throw������������������������������������������������������������
  • throws���������������������������������������������������������������������������

������

Java������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������static���final������������������������������������������������������������������Java������������������������������

上一篇:java常用类--Arrays工具类
下一篇:java常用类--包装类

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年04月15日 22时05分15秒