Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
编写高质量Java代码的7个建议
Search
uictechparty
July 08, 2012
Programming
2
190
编写高质量Java代码的7个建议
By Zelong Liang, 2nd TechParty@UIC
uictechparty
July 08, 2012
Tweet
Share
More Decks by uictechparty
See All by uictechparty
产品经理是做什么的呢?
uictechparty
1
220
找人
uictechparty
3
470
香港研究生申请经验分享
uictechparty
0
420
css.pdf
uictechparty
1
220
Introduction to Design Patterns
uictechparty
2
150
视觉障碍出行辅助仪 -The Third Eye
uictechparty
1
120
jQuery 快速入门
uictechparty
1
150
Introduction to NodeJS
uictechparty
1
220
Introduction to Hadoop
uictechparty
3
230
Other Decks in Programming
See All in Programming
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
290
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.9k
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
280
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
130
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
560
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
150
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
110
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
160
The free-lunch guide to idea circularity
hollycummins
0
240
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
8.1k
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
460
20260228_JAWS_Beginner_Kansai
takuyay0ne
5
550
Featured
See All Featured
Designing for Timeless Needs
cassininazir
0
170
Joys of Absence: A Defence of Solitary Play
codingconduct
1
310
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
140
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
240
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
680
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
470
[SF Ruby Conf 2025] Rails X
palkan
2
830
The untapped power of vector embeddings
frankvandijk
2
1.6k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
160
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Transcript
编写高质量 Java 代码的 7 个 建议
Who I am ? • @ 龙 mol_ 才不是小 眼睛
建议 1 :不要在变量和常量中出现 容易混淆的字母 • 包名,全小写 test • 类名,首字母全大写 Client
• 常量,全部大写并用下划线分隔 NUM_1 • 变量,采用驼峰命名方法 • KillDragon1
• l -> L • o/O( 增加注释 )
建议 2 :少用静态导入 • 从 Java5 开始引入了静态导入方法 ( import static
) • 减少字符输入量 • 提高代码可读性 • KillDragon2
建议 3 :提倡异常封装 • Java 异常处理机制确保程序健壮性 • 但不易看懂 • 开发人员
• 用户 • 异常封装
优点 • 1. 提高系统的友好性 • 2. 提高系统的可维护性 • KillDragon3
建议 4 :使用线程异常处理器提升 系统可靠性 • 数据交互时要监听指定端口,实现数据包 的接收和发送逻辑 • 避免线程阻塞 •
借口稳定性和可靠性问题 • KillDragon4
建议 5 :提升 Java 性能基本方 法 • 1. 不要再循环条件中计算 •
2. 尽量把变量、方法声明为 final static • 3. 频繁字符串操作使用 StringBulider 或 SreingBuffer • KillDragon5
建议 6 :让注释正确、清晰、简洁 • 1. 废话式注释 • 2. 故事式注释 •
3. 不必要的注释 • 4. 过时的注释 • 5. 大块注释的代码 • 1. 警示式注释 • 2.TODO 注释 • 注释是美化剂,不是催化剂,或为优秀加分,或为拙劣减 分
建议 7 :增强类的可替换性 • 多态,一个接口可以有多个实现方式,一 个父类可以有多个子类,并且可以把不同 的实现或子类赋给不同的借口和父类。 • 好处:替换性 •
1. 子类必须完全实现父类方法 • 2. 前置条件可以被放大 • KillDragon6
Q&A