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,而且我想用英文学,不是用中文背。所以每一页只讲一个概念、给五个新词、三道要出声回答的题。
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.所有内容都从一个问题长出来。线上一站就是一处“答案又生出一个新问题”的地方。顺着线往下读,不要横着扫。
- 01What is a HashMap, really?HashMap 到底是个什么东西?An array of buckets; each bucket holds a short list.一个桶数组,每个桶挂一条短链。第 1 题 · 已上线
- 02How does a key end up in one bucket?一个 key 怎么就跑到某个桶里?hash it, then
h & (n - 1).先算 hash,再h & (n-1)取下标。第 4 课 - 03Two keys, one bucket. Now what?两个 key 撞进同一个桶,怎么办?Stand in a line — a linked list; after 8, a tree.排队——挂成链表;到 8 个就转成红黑树。第 2–3 课
- 04The buckets are getting full. Then?桶快满了呢?At 75% the array doubles; each key stays or moves +n.装到 75% 翻倍;每个 key 要么原位、要么 +n。第 5 课
- 05Two threads put at the same time?两个线程同时 put 会怎样?Lost data, or a loop in JDK 7. Use ConcurrentHashMap.丢数据,JDK 7 还会成环。换 ConcurrentHashMap。第 7 课
- 06So how is it used as a cache at work?那工作中怎么拿它当缓存用?Redis in front of the DB — and three ways the cache bites back.Redis 挡在数据库前面——以及缓存咬你的三种方式。待写
- 07WeChat sends the same callback three times. Then?微信同时回调三条,怎么办?Idempotent table, then status CAS, then a lock.幂等表 → 状态 CAS → 再上锁。第 2 题 · 已上线
- 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 分钟。
- Level 1 — place 5 keys, and watch
orderandnodecollide in bucket 15.第一关:放 5 个 key,看order和node在桶 15 撞成一条链。 - Level 2 — fill 12 of 16 (that is 75%), then watch the array double and every key either stay or move by 16.第二关:装满 12 个(16 的 75%),看数组翻倍,每个 key 要么原位、要么 +16。
- Level 3 — the 8th key in one bucket turns the chain into a red-black tree: 8 steps become 3.第三关:同一个桶放第 8 个,链子变成红黑树,8 次比较变成 3 次。
- Every word on a card can be clicked to hear it read aloud (five sites to choose from).卡片上的每个单词都能点开听真人发音(右上角可选 5 个站)。
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讲什么内容 |
|---|---|---|
| 1 | What is an array?数组 | 什么是数组 |
| 2 | What is a linked list?链表 | 什么是链表 |
| 3 | What is a tree? What is a red-black tree?树 | 什么是树、什么是红黑树 |
| 4 | What is a key? A hash? A collision?哈希 | 什么是 key、hash、冲突 |
| 5 | What is O(1), O(n), O(log n)?复杂度 | 什么是 O(1)、O(n)、O(log n) |
| 6 | HashMap methods in real code方法 | HashMap 的常用方法和真实用法 |
| 7 | Why is HashMap not thread-safe?线程 | 为什么 HashMap 线程不安全 |
04How to read a page怎么读一页
- Press 🔊 at the top. Follow the words with your eyes. Twice is enough.点页面顶部的 🔊,眼睛跟着字走。两遍就够。
- Switch to 中英 if a sentence is too hard. Read the English first, then the Chinese.句子太难就切到 中英:先读英文,再看中文。
- Click ▶ hear it on five new words. Say each one out loud three times.在新词里点 ▶ hear it,听真人发音,每个词大声说三遍。
- 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新词
Click ▶ hear it for real people on YouGlish; 🔊 for the computer voice.点 ▶ hear it 听真人发音(YouGlish);点 🔊 听电脑朗读。
✓Check yourself自测
- Say the plan for today in one sentence.用一句话说出今天要做的事。
- Which page are you reading today?今天你读哪一页?
- Say one word you learned, out loud.说出一个今天学的词,出声。
Answer out loud first. Only then open the answers below.先自己出声答,再看下面的答案。