用六大代码问题检验你的java知识能力(Test your java knowledge with six major code problems).docVIP

  • 1
  • 0
  • 约1.2万字
  • 约 13页
  • 2017-09-07 发布于河南
  • 举报

用六大代码问题检验你的java知识能力(Test your java knowledge with six major code problems).doc

用六大代码问题检验你的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

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档