- 1
- 0
- 约1.2万字
- 约 13页
- 2017-09-07 发布于河南
- 举报
用六大代码问题检验你的java知识能力(Test your java knowledge with six major code problems)
用六大代码问题检验你的java知识能力(Test your java knowledge with six major code problems)
Test your Java knowledge with six major code problems
--------------------------------------------------------------------------------
Do you feel like a Java expert? Are you sure youre fully aware of the Java exception handling mechanism? In the following code, are you able to quickly identify six problems with exception handling?
1 OutputStreamWriter out =...
2 java.sql.Connection conn =...
Try {/ / the 3
4 Statement stat = conn.createStatement ();
5 ResultSet rs = stat.executeQuery
6 select, uid, name, from, user;
7 while (rs.next ())
{8
9 out.println (ID: + rs.getString (uid) / /.
10 name: + rs.getString (name));
11}
12 (conn.close); / / 3
13 out.close ();
14}
15 catch (Exception Ex) / / 2
{16
17 (ex.printStackTrace); / / 1, 4
18}
As a Java programmer, you should at least be able to find two problems. However, if you cant find all six questions, please continue reading this article.
This article does not discuss the general principles of Java exception handling, as these principles have been well known by most people. We want to do is to analyze all can be called counterexamples (anti-pattern) against the common bad habits good encoding standard. To help readers familiar with the typical example, which can perceive and avoid these problems in practical work.
One of the counterexamples: discard exceptions
Code: 15 lines, -18 rows.
This code captures exceptions without any processing and can be considered a killer in Java programming. The point of view from the frequent problems and harm degree, as a notorious it may and C/C++ program problem?? do not check whether the buffer is full.
If you see this discarded (not thrown) abnormal situation, be sure to code ninety-nine percent problems (in rare cases, this code has the reason of existence, but the best and complete notes, so as to avoid the misunderstanding of others).
This code is wrong, abnormal (almost) always means something wrong, or
您可能关注的文档
- 指令引用内存错误解决办法(Instruction reference memory error solution).doc
- 拥有领先技术支撑体系 云烟是这样炼出来的(With the leading technology support system, Yunyan is refining it).doc
- 指令引用的,该内存不能为read或written(Instruction referenced, this memory cannot be read or written).doc
- 指令表(Instruction list).doc
- 指导发动机冷却液泄漏故障实例检修(Troubleshooting of coolant leakage in engine).doc
- 指环王3攻略(The Lord of the rings 3).doc
- 指纹的提取鉴定方法(Method for extracting and identifying fingerprints).doc
- 振动电机的应用范围、工作原理及使用规范(Application range, working principle and operation specification of vibrating motor).doc
- 掌握快乐的钥匙(Master the key to happiness).doc
- 掌握建筑防水材料的特性与应用(Mastering the characteristics and application of building waterproof materials).doc
- 广东省广州省实验中学教育集团2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州大学附属中学2025-2026学年八年级上学期奥班期中物理试题(解析版).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(含答案).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(解析版).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 2026《中国人寿上海分公司营销员培训体系优化研究》18000字.docx
- 《生物探究性实验教学》中小学教师资格模拟试题.docx
最近下载
- 《专业工程管理与实务》.pdf VIP
- 中国血栓性疾病防治指南(2025版).docx VIP
- 施工质量日志-.xls VIP
- 2025年国家公务员全国总工会面试题及答案.docx VIP
- 合肥市普通高中六校联盟2025-2026学年高三第一次语文教学质量监测+答案.docx VIP
- 局部晚期食管癌患者新辅助免疫治疗与常规新辅助治疗的比较:系统评价和meta分析.pdf
- 2025以骑手为代表的新就业群体研究报告:职业技能与跑单时长对收入的共同作用.pdf VIP
- 年产一亿片别嘌呤醇的车间工艺设计.doc VIP
- 商务型(带电梯、地下室、效果图)三层别墅设计图.pdf VIP
- 2026年详版个人信用报告征信报告最新Word可编辑模版样板doc文件.docx
原创力文档

文档评论(0)