- 浏览: 157126 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
semmy:
赞一个
displaytag的Excel导出实践 -
李君寻:
...
displaytag的Excel导出实践 -
xiaoz170:
不太明白为嘛包这一层 class ,反而使代码更复杂。难道是为 ...
试读《基于MVC的JavaScript Web富应用开发》— 不一样的JavaScript -
lingceng:
<mirror> <id>U ...
maven usage guide
这是一本只讲Java优点的书。
Jim Waldo先生是原Sun微系统公司实验室的杰出工程师,他亲历并参与了Java从技术萌芽、发展到崛起的整个过程。
类型系统
类、抽象类和接口。
用接口定义一种类型,再用一个类实现此接口,这样,要调用执行调用的性能损失是程序的设计者们不愿付出的。在早期的Java解释器中,可接受的性能是人们真正关心的,但即使在那时不通过接口的直接调用也只是一个微乎其微的优化,没有实际意义。考虑到如今的即时编译(just-in-time)编译器的性能,这种反对意见已经完全没有意义了。
关于效率,另一种反对意见在于接口导致系统中的信息重复,需要程序要录入更多的代码。集成开发环境(Integrated Development Environment,IDE)大大缓解。
方法参数和返回值的声明中,接口的概念第一次显得重要起来。编辑器要求传入方法或从方法中返回的对象必须符合声明的类型。这些对象的精确类型不必与声明的类型完全一致;编译器只要求它们“至少是”那种类型。多态。
接口的定义可以使实现任务交给可以信任的其他团队。
对象的接口实际上就是用户接口,只不过用户是程序员。它理清了整个系统设计的方法。
Java的接口不能区别同类方法;还有一个关于类加载器(classloader)的问题。但这两种情况都很少遇到。
异常
The Why
The reasoning behind the exception mechanism in Java is pretty simple. Bad things can happen, even to good programs. When such a bad thing happens, there is a need to react to it, either by figuring out some other way to accomplish what was trying to be done when the bad thing happened, by cleaning up and gracefully exiting, or by abort-ing the operation in which the bad thing happened and trying something else. But the code that deals with the problem shouldn't be mixed in with the code that is used when bad things don't happen, or the program can rapidly become unreadable. In addition, programmers are probably better off if they have to deal with problems as close as possible to the time and place that they occur.
The design also ties into the Java type system. Since an exception is an alternative return value, it forms part of the signature of the method. Not declaring an exception would be like not having to declare the type of the return value. It would be very difficult to write predictable code in such a situation, and it would be difficult for the compiler to help you find mistakes.
Finally, the exception mechanism allows a program to separate the mainline code and the error-handling code.
Use and Abuse
Take care
Exception next type
We can use the RuntimeException,but you should do everything in your power to warn users of your code that this ex-ception might be thrown, the circumstances under which it will be thrown, and what the caller might to do avoid the exception or deal with it if it is thrown. It isn’t the perfect solution, but it is the best that is open to you.
Example
Jim Waldo先生是原Sun微系统公司实验室的杰出工程师,他亲历并参与了Java从技术萌芽、发展到崛起的整个过程。
类型系统
类、抽象类和接口。
用接口定义一种类型,再用一个类实现此接口,这样,要调用执行调用的性能损失是程序的设计者们不愿付出的。在早期的Java解释器中,可接受的性能是人们真正关心的,但即使在那时不通过接口的直接调用也只是一个微乎其微的优化,没有实际意义。考虑到如今的即时编译(just-in-time)编译器的性能,这种反对意见已经完全没有意义了。
关于效率,另一种反对意见在于接口导致系统中的信息重复,需要程序要录入更多的代码。集成开发环境(Integrated Development Environment,IDE)大大缓解。
方法参数和返回值的声明中,接口的概念第一次显得重要起来。编辑器要求传入方法或从方法中返回的对象必须符合声明的类型。这些对象的精确类型不必与声明的类型完全一致;编译器只要求它们“至少是”那种类型。多态。
接口的定义可以使实现任务交给可以信任的其他团队。
对象的接口实际上就是用户接口,只不过用户是程序员。它理清了整个系统设计的方法。
Java的接口不能区别同类方法;还有一个关于类加载器(classloader)的问题。但这两种情况都很少遇到。
异常
The Why
The reasoning behind the exception mechanism in Java is pretty simple. Bad things can happen, even to good programs. When such a bad thing happens, there is a need to react to it, either by figuring out some other way to accomplish what was trying to be done when the bad thing happened, by cleaning up and gracefully exiting, or by abort-ing the operation in which the bad thing happened and trying something else. But the code that deals with the problem shouldn't be mixed in with the code that is used when bad things don't happen, or the program can rapidly become unreadable. In addition, programmers are probably better off if they have to deal with problems as close as possible to the time and place that they occur.
The design also ties into the Java type system. Since an exception is an alternative return value, it forms part of the signature of the method. Not declaring an exception would be like not having to declare the type of the return value. It would be very difficult to write predictable code in such a situation, and it would be difficult for the compiler to help you find mistakes.
Finally, the exception mechanism allows a program to separate the mainline code and the error-handling code.
Use and Abuse
try{ ... method1(); ... method2(); ... } catch (Type2Exception e){ //do something to recover } catch (Type1Exception e) { //do something else to recover }
Take care
Exception next type
We can use the RuntimeException,but you should do everything in your power to warn users of your code that this ex-ception might be thrown, the circumstances under which it will be thrown, and what the caller might to do avoid the exception or deal with it if it is thrown. It isn’t the perfect solution, but it is the best that is open to you.
Example
try { ... } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {} // will go on to do after catch // tack care the difference with the former example if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {} if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} }
发表评论
-
Hack struts2 json plugin: dynamically set includeProperty
2013-07-26 11:27 1242Here is not basic use of stru ... -
Calender to Date snip
2013-05-30 10:25 898The format is not stored in the ... -
Gson切面日志实践
2013-02-26 17:47 2345背景 应用切面做日志记录,记录操作实体详情时可以使用JSO ... -
读《深入分析Java Web技术内幕》
2013-01-16 21:37 3297这里这本书的预读章节,看完预读部分,解答了一些疑惑 ... -
Java泛型
2012-11-08 23:57 1580Java的泛型是5.0的特性,自己的业务代码中或许较少使用 ... -
lucene全文索引
2012-11-08 01:45 1459总听说lucene,总听到“全文检索”,一直不大明白什么意 ... -
displaytag的汇总功能
2012-11-07 10:39 1043displaytag 有列汇总功能,以前不知道step1:需要 ... -
native2ascii使用
2012-10-29 13:56 1189native2ascii -[options] [inputf ... -
有效使用Java异常
2012-10-26 15:58 886Java的异常机制是一大优点,可以快速定位错误。但在实际开 ... -
从springside看到的
2012-10-26 00:27 1129springside是一个JAVAEE的开发框架,作者运用 ... -
JSTL小结
2012-10-12 12:00 1075网上有很多内容讲解, ... -
memcache simple practice in Java
2012-09-24 17:58 1615Memcache is C/S structure, serv ... -
displaytag中使用struts的国际化资源
2012-07-30 19:09 1368使用displaytag打印表格的时候,表头有时需要使 ... -
newInstance() and new
2012-07-11 14:00 1011相同点 newInstance() and new can ... -
Java Decompile
2012-07-05 15:58 960较早的eclipse的Java反编译是jad.exe ... -
Use JUnit
2012-07-05 13:20 889Junit A programmer-oriented te ... -
Use JUnit (2)
2012-07-05 13:04 858Junit3 diff Junit4 包命名从 ... -
《Java语言精粹》读书笔记(3)
2012-04-27 15:13 879集合 数据结构中的关于大型结构在java.util中提 ... -
《Java语言精粹》读书笔记(2)
2012-04-27 14:37 983Package Like most objec ... -
JavaServer Pages Standard Tag Library
2012-03-29 14:45 917The JavaServer Pages Standa ...
相关推荐
在这本书里,Jim总结了他所认为的Java语言及其环境的诸多精良部分,包括:类型系统、异常处理、包机制、垃圾回收、Java虚拟机、Javadoc、集合、远程方法调用和并发机制。另外,他还从开发者的角度分析了在Java技术...
疯狂Java面试题(疯狂Java讲义精粹附赠).pdf
JavaScript语言精粹完整版,想要提升的朋友有福了。
JAVA案例精粹150例.pdf JAVA案例精粹150例.pdf
uml精粹读书笔记,包括类图、时序图、对象图、包图、部署图、用例、状态机图、活动图。
这是一份《javascript语言精粹》PDF版的压缩包,本书对于javascript的重要知识点介绍很到位,你值得拥有!
本书通过对JavaScript语言的分析,甄别出好的和坏的特性,从而提取出相对这门语言的整体而言具有更好的可靠性、可读性和可维护性的JavaScript的子集,以便你能用它创建真正可扩展的和高效的代码。 雅虎资深...
JavaScript语言精粹_修订版.pdf
avaScript语言精粹
疯狂java讲义精粹(第2版)的源代码,需要完整光盘的朋友可与我联系。
, 这是一本介绍 JavaScript 语言本质的权威书籍,值得任何正在或准备从事JavaScript 开发的人阅读,并且需要反复阅读。学习、理解、实践大师的思想,我们才可能站在巨人的肩上,才有机会超越大师,这本书就是开始。
JavaScript语言精粹,这本书是很值得阅读的,对前端人员是很有必要的
JavaScript语言精粹.pdf
JavaScript语言精粹
JavaScript语言精粹 包含pdf 与 epub
《Java项目开发案例精粹》是目前流行的Java开发的案例...《Java项目开发案例精粹》既可以作为Java初学者的项目培训教材,也可以作为具有一定编程经验的Java程序开发人员的参考书,还适合Java自学者和大专院校学生阅读。