Java Notes

Home首页

Java in English · for a complete beginner英文 Java · 写给完全零基础

One small page. One idea.一次只读一页,一次只学一个概念。

I know nothing about Java. I want to learn it in English, not in Chinese. So every page gives one idea, five new words, and three questions I answer out loud.我不懂 Java,而且我想用英文学,不是用中文背。所以每一页只讲一个概念、给五个新词、三道要出声回答的题。

Short answer先给答案This site teaches Java in English, one idea per page: seven short lessons, then the HashMap interview question.这个站用英文教 Java,一页只讲一个概念:先上七节短课,再读 HashMap 那道面试题。

7 lessons7 节课2 questions2 道题8 stations8 站

01The line: one question, many branches主线:从一个问题长出去

Everything starts from one question. Each station below is a place the answer opens a new question. Read down the line, not across the table.所有内容都从一个问题长出来。线上一站就是一处“答案又生出一个新问题”的地方。顺着线往下读,不要横着扫。

  1. 01What is a HashMap, really?HashMap 到底是个什么东西?An array of buckets; each bucket holds a short list.一个桶数组,每个桶挂一条短链。第 1 题 · 已上线
  2. 02How does a key end up in one bucket?一个 key 怎么就跑到某个桶里?hash it, then h & (n - 1).先算 hash,再 h & (n-1) 取下标。第 4 课
  3. 03Two keys, one bucket. Now what?两个 key 撞进同一个桶,怎么办?Stand in a line — a linked list; after 8, a tree.排队——挂成链表;到 8 个就转成红黑树。第 2–3 课
  4. 04The buckets are getting full. Then?桶快满了呢?At 75% the array doubles; each key stays or moves +n.装到 75% 翻倍;每个 key 要么原位、要么 +n。第 5 课
  5. 05Two threads put at the same time?两个线程同时 put 会怎样?Lost data, or a loop in JDK 7. Use ConcurrentHashMap.丢数据,JDK 7 还会成环。换 ConcurrentHashMap。第 7 课
  6. 06So how is it used as a cache at work?那工作中怎么拿它当缓存用?Redis in front of the DB — and three ways the cache bites back.Redis 挡在数据库前面——以及缓存咬你的三种方式。待写
  7. 07WeChat sends the same callback three times. Then?微信同时回调三条,怎么办?Idempotent table, then status CAS, then a lock.幂等表 → 状态 CAS → 再上锁。第 2 题 · 已上线
  8. 08Ten thousand people, one thousand items. No oversell?一万人抢一千件,怎么不超卖?Pre-deduct in Redis, then let the DB be the last check.先在 Redis 预扣,数据库做最后一道闸。待写

Grey stations are not written yet. The line grows as we go — that is the point.灰色的站还没写。线会一直长下去,这本来就是重点。

02Five minutes with your hands动手 5 分钟:把 key 放进桶里

Reading gives you the words. Playing gives you the mechanics. Three levels, about five minutes.读是把话记住,玩是把机制记住。三关,大约 5 分钟。

Play the bucket game →玩装桶小游戏 →

03The seven lessons: the ground under the line七节课:这条线脚下的地基

Each lesson is about 600 English words. They are the small pieces the line is built from.每节课大约 600 个英文词,是这条线用到的零件。

Lesson第几课Title标题What it answers讲什么内容
1What is an array?数组什么是数组
2What is a linked list?链表什么是链表
3What is a tree? What is a red-black tree?树什么是树、什么是红黑树
4What is a key? A hash? A collision?哈希什么是 key、hash、冲突
5What is O(1), O(n), O(log n)?复杂度什么是 O(1)、O(n)、O(log n)
6HashMap methods in real code方法HashMap 的常用方法和真实用法
7Why is HashMap not thread-safe?线程为什么 HashMap 线程不安全

04How to read a page怎么读一页

  1. Press 🔊 at the top. Follow the words with your eyes. Twice is enough.点页面顶部的 🔊,眼睛跟着字走。两遍就够。
  2. Switch to 中英 if a sentence is too hard. Read the English first, then the Chinese.句子太难就切到 中英:先读英文,再看中文。
  3. Click ▶ hear it on five new words. Say each one out loud three times.在新词里点 ▶ hear it,听真人发音,每个词大声说三遍。
  4. Answer the three questions at the bottom out loud, not in your head.页面底部三道题要出声回答,不要只在心里想。

Twenty minutes is enough. One station a day, and the line keeps growing.二十分钟就够。一天一站,线就一直在长。

05Why English, and why so slow为什么要英文、为什么这么慢

In an interview the words are English: bucket, collision, resize. If I only know the Chinese word, I hear a sound I cannot follow.面试里蹦出来的是英文词:bucket、collision、resize。如果我只知道中文说法,听到的就是一串抓不住的声音。

So this site is slow on purpose. One idea per page, five words, one picture.所以这个网站是故意慢的:一页一个概念、五个词、一张图。

→New words新词

bucket /ˈbʌkɪt/ One box in the array.桶:数组里的一格 ▶ hear it
collision /kəˈlɪʒn/ Two keys that land in the same bucket.冲突:两个 key 落进同一个桶 ▶ hear it
resize /ˌriːˈsaɪz/ Make the array bigger and move items.扩容:把数组变大并搬数据 ▶ hear it
thread /θred/ One worker inside a program.线程:程序里的一个干活的 ▶ hear it
complexity /kəmˈpleksəti/ How cost grows with size.复杂度:代价随数据量的增长方式 ▶ hear it

Click ▶ hear it for real people on YouGlish; 🔊 for the computer voice.点 ▶ hear it 听真人发音(YouGlish);点 🔊 听电脑朗读。

✓Check yourself自测

  1. Say the plan for today in one sentence.用一句话说出今天要做的事。
  2. Which page are you reading today?今天你读哪一页?
  3. Say one word you learned, out loud.说出一个今天学的词,出声。

Answer out loud first. Only then open the answers below.先自己出声答,再看下面的答案。

Answers参考答案
01I read one page, learn five words, and answer three questions out loud.今天要做的事:读一页、学五个词、出声答三道题。
02Start with Lesson 1, “What is an array?”.从第 1 课开始:什么是数组。
03bucket — one box of the array.bucket:数组里的一格。

Start Lesson 1 →开始第 1 课 →