Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
编写高质量Java代码的7个建议
Search
uictechparty
July 08, 2012
Programming
220
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
Transcript
12 slides
编写高质量 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
More Decks by uictechparty
See All by uictechparty
产品经理是做什么的呢?
uictechparty
1
280
找人
uictechparty
3
490
香港研究生申请经验分享
uictechparty
0
430
css.pdf
uictechparty
1
220
Introduction to Design Patterns
uictechparty
2
210
视觉障碍出行辅助仪 -The Third Eye
uictechparty
1
200
jQuery 快速入门
uictechparty
1
190
Introduction to NodeJS
uictechparty
1
250
Introduction to Hadoop
uictechparty
3
250
Other Decks in Programming
See All in Programming
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
430
自宅サーバはどこまで再現できるのか - Proxmox VE上のVM環境をIaCとバックアップで戻してみた
youto
0
450
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
300
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
410
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
410
Getting Started with Vibe Coding
miccheng
0
250
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
210
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.6k
AI Augmentation Techniques with Liberty
ivargrimstad
1
550
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
150
Featured
See All Featured
Test your architecture with Archunit
thirion
2
2.5k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
760
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Optimizing for Happiness
mojombo
378
72k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
640
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
360
Optimising Largest Contentful Paint
csswizardry
37
4k
Mind Mapping
helmedeiros
1
450
We Are The Robots
honzajavorek
0
460