What’s New in the Updated Java Development Handbook? 21 Rules, Lock Pitfalls, and Float Tricks
The latest Java Development Handbook introduces 21 new coding rules, revises over a hundred guidelines, and adds clearer examples on lock handling, switch‑null checks, floating‑point comparisons, collection conversions, and guard statements, while inviting developers to download the free PDF and join a live discussion.
To all Java developers worldwide, the Alibaba Java Development Handbook has been renamed and updated, now offering a free downloadable PDF that reflects contributions from over 2.6 million engineers.
The new edition features three major upgrades:
21 newly added coding rules covering topics such as lock usage, switch‑null handling, date‑format pitfalls, and more.
112 revised descriptions, including IFNULL checks, collection toArray length handling, and log placeholder processing.
Enhanced examples for variable naming, guard statements, enum usage, and finally‑return patterns.
Lock usage pitfalls : When acquiring a lock, the lock call must be placed outside any try block, and no method that can throw an exception should be invoked between the lock and the try block; otherwise unlocking may fail and cause deadlocks or IllegalMonitorStateException.
Switch NPE issue : If a switch expression involves a potentially null String parameter, a null check is required before the switch to avoid NullPointerException.
public class SwitchString {
public static void main(String[] args) {
method(null);
}
public static void method(String param) {
switch (param) {
// case "sth":
// System.out.println("it's sth");
// break;
// case "null":
// System.out.println("it's null");
// break;
default:
System.out.println("default");
}
}
}Floating‑point comparison problem : Because decimal numbers like 0.1 cannot be represented exactly in binary, using == for float comparison or equals for Float objects may yield false even when mathematically equal.
float a = 1.0f - 0.9f;
float b = 0.9f - 0.8f;
if (a == b) {
// expected to enter, but result is false
}
Float x = Float.valueOf(a);
Float y = Float.valueOf(b);
if (x.equals(y)) {
// expected to enter, but result is false
}Collection toArray rule : The array passed to toArray should have length zero; this rule proved correct under high concurrency scenarios.
ScheduleService removal : The guideline concerning ScheduleService deletion was dropped after evaluating its practicality and potential misuse.
Guard statements example (illustrated with a dating‑scenario analogy):
public class GuardStatementsDemo {
public void findBoyfriend(Man man) {
if (man.isBadTemper()) {
System.out.println("月球有多远,你就给我滚多远.");
return;
}
if (man.isShort()) {
System.out.println("我不需要武大郎一样的男友.");
return;
}
if (man.isPoor()) {
System.out.println("贫贱夫妻百事哀.");
return;
}
System.out.println("可以先交往一段时间看看.");
}
}The handbook aims to make foundational guidelines more accessible, with vivid explanations and real‑life analogies to help developers grasp the underlying logic.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
