生活随笔
收集整理的這篇文章主要介紹了
Java必读源码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
有能力了,必讀,看懂注釋,眼見為實
import sun.misc.Unsafe;import java.io.FileInputStream;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class NeedToRead {public static void main(String[] args) {String string =
"原來整型字面量編譯后是這樣的," +
"調用了Integer.valueOf(i),可以取緩存";Boolean bool =
true;Byte b =
1;Character character =
'c';Short shortI =
64;Integer integer =
127;Long l =
127L;Float f =
0.0F;Double d =
0.0;Class clazz = Class.
class;StringBuilder stringBuilder =
new StringBuilder(
16);StringBuffer stringBuffer =
new StringBuffer(
16);Thread thread =
new Thread();ThreadLocal threadLocal =
new ThreadLocal();ThreadLocalRandom random = ThreadLocalRandom.current();threadLocal.
set(random);Object o = threadLocal.
get();System.out.println(
"o = " + o.getClass());ThreadLocal threadLocal2 =
new ThreadLocal();threadLocal2.
set(threadLocal);Object o1 = threadLocal2.
get();System.out.println(
"o1.getClass() = " + o1.getClass());TreeMap rbTree =
new TreeMap();HashMap hashMap =
new HashMap(
8);Iterator iterator = hashMap.entrySet().iterator();ArrayList arrayList =
new ArrayList();LinkedList linkedList =
new LinkedList();AbstractQueue priorityQueue =
new PriorityQueue();BlockingQueue lbQueue =
new LinkedBlockingQueue();ConcurrentMap concurrentMap =
new ConcurrentHashMap();CopyOnWriteArrayList copyOnWriteArrayList =
new CopyOnWriteArrayList();AtomicInteger atomicInteger =
new AtomicInteger();LongAdder longAdder =
new LongAdder();ReentrantLock lock =
new ReentrantLock();ReentrantReadWriteLock readWriteLock =
new ReentrantReadWriteLock();ExecutorService executorService = Executors.newFixedThreadPool(
5);ForkJoinPool forkJoin =
new ForkJoinPool();ExecutorService threadPoolExecutor =
new ThreadPoolExecutor(
5,
10,
5,TimeUnit.SECONDS,
new LinkedBlockingQueue<>());FutureTask futureTask =
new FutureTask<>(()->
new Random().nextInt(
100));
final String returnObj =
"";futureTask =
new FutureTask<>(() -> {}, returnObj);CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
return "Hello CompletableFuture!";});CompletableFuture future = completableFuture.thenAccept(o2 -> {System.out.println(
"thenAccept: " + o2);});FileInputStream fileInputStream;Field theUnsafe =
null;
try {theUnsafe = Unsafe.
class.getDeclaredField(
"theUnsafe");theUnsafe.setAccessible(
true);
final Unsafe UNSAFE = (Unsafe) theUnsafe.
get(
null);System.out.println(UNSAFE);}
catch (NoSuchFieldException | IllegalAccessException e) {e.printStackTrace();}}
}
總結
以上是生活随笔為你收集整理的Java必读源码的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。