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
210
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
270
找人
uictechparty
3
490
香港研究生申请经验分享
uictechparty
0
430
css.pdf
uictechparty
1
220
Introduction to Design Patterns
uictechparty
2
200
视觉障碍出行辅助仪 -The Third Eye
uictechparty
1
180
jQuery 快速入门
uictechparty
1
170
Introduction to NodeJS
uictechparty
1
240
Introduction to Hadoop
uictechparty
3
240
Other Decks in Programming
See All in Programming
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
33k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
AWSに止められる覚悟してますか?
morizo_1984
2
540
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Event is what happens
moro
2
860
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
500
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
100
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
730
Domain-Driven Transformation
hschwentner
2
2.3k
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.3k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
Typedesign – Prime Four
hannesfritz
42
3.2k
Bash Introduction
62gerente
615
220k
Navigating Weather and Climate Data
rabernat
0
560
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
580
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Scaling GitHub
holman
464
140k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
490
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
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