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
190
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
编写高质量Java代码的7个建议
By Zelong Liang, 2nd TechParty@UIC
uictechparty
July 08, 2012
More Decks by uictechparty
See All by uictechparty
产品经理是做什么的呢?
uictechparty
1
230
找人
uictechparty
3
480
香港研究生申请经验分享
uictechparty
0
420
css.pdf
uictechparty
1
220
Introduction to Design Patterns
uictechparty
2
160
视觉障碍出行辅助仪 -The Third Eye
uictechparty
1
140
jQuery 快速入门
uictechparty
1
150
Introduction to NodeJS
uictechparty
1
230
Introduction to Hadoop
uictechparty
3
240
Other Decks in Programming
See All in Programming
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
190
The NotImplementedError Problem in Ruby
koic
1
610
tsserverとは何だったのか、これからどうなるのか
nowaki28
1
450
OSもどきOS
arkw
0
450
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
830
dRuby over BLE
makicamel
2
320
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
640
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
340
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
230
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
350
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
140
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
The Limits of Empathy - UXLibs8
cassininazir
1
350
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
エンジニアに許された特別な時間の終わり
watany
107
250k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
The SEO Collaboration Effect
kristinabergwall1
1
480
Designing Experiences People Love
moore
143
24k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
160
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
260
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
380
The Mindset for Success: Future Career Progression
greggifford
PRO
0
350
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.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