Java
共 3 篇文章
一些多线程的笔记
1. 保护方法原子性的同时,也要注意保护方法中使用到的变量。下面这段代码是否一定安全? public class Counter { private int counter = 0; public int getCounter() { return counter; } public synchronized void add1() { int count = counter; counter = count + 1; } //other method } 不一定,如果在other method中也处理counter但是又没有保护的情况下,会出现问题,例如 public class Coun…
2012-09-05 17:43 · Java
[JDK源码] HashMap
1. 参数介绍 /** * The default initial capacity - MUST be a power of two. */ static final int DEFAULT_INITIAL_CAPACITY = 16; /** * The maximum capacity, used if a higher value is implicitly specified * by either of the constructors with arguments. * MUST be a power of two <= 1<<30. */ static final int M…
2012-08-30 18:39 · Java
Chapter 1 - Declarations and Acess Control
1. Identifiers - It must start with a letter, a currency character($), or a connection character such as the underscore(_). It cannot start with a number!. - After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or number. - In pr…