- 浏览: 127879 次
- 性别:
- 来自: 北京
最新评论
-
C_J:
有必要这么鸡冻咩?
编写自己的ClassLoader知识点 -
jason61719:
你这不是说了等于没说吗……就解析个loadClass(),谁不 ...
编写自己的ClassLoader知识点 -
jiming:
tedeyang 写道很好的改进,不过话说回来,mybatis ...
开源,从关注产品社区做起(ibatis3.x的最近一个issue展示) -
C_J:
独爱Java 写道好像实际用处并不是很大,只是多了解了有这个东 ...
Java内存模型笔记 -
独爱Java:
好像实际用处并不是很大,只是多了解了有这个东西而已。。。
Java内存模型笔记
Chapte 2:when and how to create objects,when and how to avoid creating objects
Item 1:Consider static factory methods instead of constructors{
};
-------------------------Beautiful Cutline-------------------------
Item 2:Consider a builder when faced with many constructor parameters{
Method 1#:Constructor pattern
Method 2#:JavaBean pattern
Method 3#:SubClass pattern
};
-------------------------Beautiful Cutline-------------------------
Item 3:Enforce the singleton property with a private constructor or an enum type{
Before release 1.5,there were two ways.
way 1:
pulbic class Elvis{ public static fina Elvis INSTANCE=new Elvis(); private Elvis(){...} }
Disadvantage:A privileaed client can invoke the private constructor reflectively with the adi of the AccessibleObject.setAccessible method.
way 2:
pulbic class Elvis{ private static fina Elvis INSTANCE=new Elvis(); private Elvis(){...} public static Elvis getInstance(){...} }
Disadvantage:with the same caveat above.
Advantage:Make it clear that the class is singleton.
As of release 1.5:the best way to declare singleton is with Enum
way 3:
public enum Elvis{ INSTANCE; }
-------------------------Beautiful Cutline-------------------------
Item 4: Enforce noninstantiablility with a private constructor.
Attempting to enforce noninstantiability by making a class abstract does not work.the class can be subclassed and the subclass instantiated.
-------------------------Beautiful Cutline-------------------------
Item 5:Avoid creating unneccessary objects
Avoid creating objects when using final class
Reusing mutable objects if you know they won't be modified.
Prefer primitives to boxed primitives.
-------------------------Beautiful Cutline-------------------------
Item 6:Eliminate obsolete object references
Whenever a class manage own memory,programmer should be alert for memory leaks.
Whenever an element is freed,any object reference contained in the element should be nulled out.
-------------------------Beautiful Cutline-------------------------
Item 7: Avoid finalizers
It maybe happen that the finalizer thread will never run as the priority is low.
Don't use finalizers except as a safty net or to terminate noncritical native resources.In those rare instances where you do use a finalizer,remember to invoke super.finalize.
-------------------------Intentional Cutline-------------------------
Chapt 3:Methods Common to All Objects
Item 8: Obey the general contract when overriding equals
The easist way to avoid problems is not to overide the equals method,in which case echo instance of the class is equal only to itself.
Item9: Always override hashCode when you override equals
Chapter 7 Methods
Item 38 Check parameters for validity
在函数开始前作必要的检查工作,利用if或assert语句
Item 39 make defensive copies when needed
对于类的成员变量赋值工作要非常的小心,不要轻易暴露类的内部成员变量,充分考虑client端的信任问题,书写安全的代码。
Item 41 use overloading judiciously
你可以使用重载但并不意味着你应该使用,一旦你使用重载你需要确认重载函数的行为像你预期的一样工作,不然往往会发生诡异的问题。
item 42 use varargs judiciouly
不要滥用多参数,即便用了,也需要做一定的检查工作。
item 43 return empty arrays or collections, not nulls
当函数返回值为集合的时候,最好不要返回null,而返回空集合,这样也省去了上层判空检查,使代码更高效,重构的时候搜索下有没有return null这种语句。
item 44 write doc comments for all exposed api elements.
chapter 5 generics
item 23 don't use raw types in new code.
item 24 eliminate unchecked warnings.
item 25 prefer lists to arrays List集合在编译期就进行类型检查,而数组在运行期。
item 26 favor generic types
item 27 favor generic methods
chapter 8
item45 minimize the scope of local variables--
item46 prefer for-echo loops to traditional for loops-更简洁和高效
item47 know and use the libraries-不要重复造已有的轮子。
item48 avoid float and double if exact answers are required-使用BigDecimal
item49 prefer primitive types to boxed primitives-基本类型更简单更快
item50 avoid strings where other types are more appropriate
item51 beware the performance of string concatenation-string是个immutable类型的
item52 refer to objects by their interface-用接口定义,提高可扩展性
item53 prefer interfaces to reflection-反射式个好工具,但他的缺点是你放弃了所有编译器检查,牺牲了效率,代码的可读性
item54 use native method judiciously 减弱了可调试性、可读性、非平台无关的
item55 optimize judiciously
item56 adhere to generally accepted naming conventions
chapter 10
item66 synchronize access to shared mutable data
item67 avoid excessive synchronization-防止死锁和数据不正确,尽量少用同步
item68 prefer executors and tasks to threads.1.5提供了一套执行框架(executor framework),提供了一整套线程池解决方案。
item69 prefer concurrency utilities to wait and notify.更改传统的线程间通讯方式,利用一些CountDownLatch,CyclicBarrier。
item71 use lazy initialization judiciously-对于静态实例,采用私有静态类实现延迟加载,对于一般实例,可使用double-check or single-check 来实现。
item72 don't depend on the thread scheduler-不要依靠系统来管理线程执行情况,利用thread的sleep方法来代替yield,线程的优先级别也不太可靠。
item73 avoid thread groups-线程组管理目前已经不太提倡使用了,他提供的函数没有太大的意义,建议不再使用。
发表评论
-
iOS入门(ongoing)
2012-09-13 11:32 1301Record it: The overview of ... -
Stuff about Android
2011-07-09 16:15 1065Foreword: long time ... -
JQuery初体验(Demo)
2011-05-22 13:43 1458Demo:Show <meta content ... -
Java内存模型笔记
2011-04-13 15:48 1538题记: 看到C/C++ ... -
Radiant_The Popular Ruby's CMS Demo篇
2011-04-02 14:49 1241题记: 上篇 记录我第一次安装Rodiant经过和 ... -
Radiant_The Popular Ruby’s CMS安装篇
2011-03-28 00:48 1278题记: 今天第一次参加JE的线下活动,robbin等 ... -
关于Azul 并发垃圾回收器
2011-03-26 14:40 1317题记: 总感觉JE讨论的帖子的东西都比较滞后,所以会 ... -
phpCMS & jQuery是我该做的(阉割了)
2011-02-27 23:02 81WD讲究以plugin挂载为结构,我需要构造一个p ... -
我的玩意:J2ME的Criteria初探
2011-01-20 21:59 1019题记: 前几天跟初中同学聊天,他问我能不能做一个GP ... -
编写自己的ClassLoader知识点
2011-01-13 14:41 1871题记: 看到InfoQ关于ClassLoader的文 ... -
周末好玩,用短信控制你的计算机
2011-01-10 16:34 2986Snapshot: 详情 ... -
About Dock Plugin on Mac
2010-11-21 22:47 1463题记: 第一次接触MAC的开发..... ... -
可变hashcode的隐患和序列化安全
2010-10-25 00:55 1369可变hashcode的隐患 为识别对象,JDK ... -
体验OSGi(helloworld.jar)—富app的热拔插
2010-10-18 23:22 2436记得以前工作的时候,有天direct manager问 ... -
MongoDB on DAO with Java Language
2010-08-26 19:17 1425A Quick Tour Using the Java d ... -
Getting Start on Mongodb
2010-08-26 01:29 1504题记: 最近老和同学聊到non-relational ... -
Java Media Framework本地玩转摄像头
2010-08-04 00:57 17351、简介The JavaTM Media Framework ... -
从WeakLogHandler应用看Java的引用、引用队列
2010-06-14 00:58 1499题记: 前几天讨论到WeakHashMap(这个是个弱引用的 ... -
《重构》读书笔记
2010-05-09 00:05 1045Martin Fowler于2003年出版 ... -
RPC之WebServices&RMI&JMS,phprpc框架?(待续)
2010-05-06 22:31 55前段时间写过基本的WebServices,也没再做深入 ...
相关推荐
《More Effective C++》是C++编程领域的一本经典书籍,由Scott Meyers撰写,它为程序员提供了35个实用的技巧和最佳实践,旨在帮助他们编写更高效、更易于维护的C++代码。这本书是《Effective C++》系列的一部分,...
<div class="block">This package contains the example classes used in various tutorials and examples.</div> </div> <p>See: <a href="#package.description">Description</a></p> </div> <div class=...
<<effective c++>>这本圣经的作者Scott Meyesr在给<<modern c++ design>>序言的时候高度的赞赏了Andrei同志的工作:C++社群对template的理解即将经历一次巨大的变化,我对它所说的任何事情,也许很快就会被认为是...
<<effective c++>>这本圣经的作者Scott Meyesr在给<<modern c++ design>>序言的时候高度的赞赏了Andrei同志的工作:C++社群对template的理解即将经历一次巨大的变化,我对它所说的任何事情,也许很快就会被认为是...
<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td><td>7</td><td>8</td></tr> <tr><td>9</td><td>10</td></tr> </table> ``` 5. **个人兴趣**: 面试官可能会问及你的学习资源,...
"Effective Java读书笔记" Effective Java是一本关于Java编程语言的经典书籍,本笔记主要总结了Java语言的发展历程、静态工厂方法的应用、构造器模式的使用等重要知识点。 一、Java语言的发展历程 Java语言的发展...
<br><br>《Effective STL》目录:<br><br>前言<br>致谢<br>导读<br>容器<br>条款1:仔细选择你的容器<br>条款2:小心对“容器无关代码”的幻想<br>条款3:使容器里对象的拷贝操作轻量而正确<br>条款4:用empty来代替...
B<br>DESCRIPTION:<br>US=HP Windows Format Utility for USB Drive Key or DiskOnKey<br><br>PURPOSE: Initial Release<br>SOFTPAQ NUMBER: SP27213<br>EFFECTIVE DATE: February 6, 2004<br>CATEGORY: ...
《Effective Java》是Java编程领域的一本经典著作,由Joshua Bloch撰写,该书的第三版继续提供了关于如何编写高效、优雅、可维护的Java代码的指导。以下是基于给出的目录和部分内容提取的一些关键知识点: ### 第一...
effective way to manipulate INI files.<END><br>55,SoundSource.zip<br>BrainFusion Presents The Dancer.Ocx Which is capable of reading The Sound Peak Form Sound Card When Mp3 or Wav File Is Played <END>...
<title>Effective Java</title> <author>杰伊·格洛斯曼</author> <year>2001</year> </book> </library> ``` 我们可以创建对应的Java类来映射XML元素: ```java public class Book { @Attribute(name = "id...
<book title="Effective Java"> <author> Joshua Bloch </author> <year>2001</year> </book> </category> <category name="Movies"> <!-- ... --> </category> </root> ``` 使用JDOM解析这样的文件,可以...
- **《Java 编程思想》(Thinking in Java)**:这是一本深入讲解Java编程语言及其设计思想的书籍,对于想要理解Java内部工作原理的读者来说是一本不可多得的好书。 ##### 在线课程 - **Coursera: Java ...
interoperability, and more <br><br>Running case study: see how concepts work together when you build .NET applications <br><br>Experienced C++, Java, and Visual Basic programmers: become effective ...
标题“effective-java.pdf”与描述“effective-java.pdf”表明本文档是关于Java编程实践的指南,且内容可能来自于一本名为《Effective Java》的书籍,该书是由Joshua Bloch编写,被广泛认为是Java编程的权威指南。...
<br> How to Use this Book<br> How This Book Is Organized<br> Conventions Used in This Book<br> Using Code Examples<br> We'd Like to Hear from You<br> Chapter 1. Customizing the User Environment<br> ...
and use that knowledge for more effective debugging<br/><br/>Includes a production-ready data collection script that can save you hours or days in debugging mission-critical Linux systems!<br/><br/>...
<title>Effective Java</title> <author>杰拉德·霍恩瑟</author> </book> </books> ``` 我们可以找到所有`book`元素并打印其信息: ```java List<Element> bookElements = rootElement.getChildren("book"); ...