首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

查漏补缺2012下(持续更新)

2012-09-03 
查漏补缺2012上(持续更新)2012.2-2012.61、Notepad++中的“Show All Characters”可以查看windows和unix下的

查漏补缺2012上(持续更新)
2012.2-2012.6

1、Notepad++中的“Show All Characters”可以查看windows和unix下的不同的换行符,windows下的换行符为CRLF,unix下的换行符为LF


2、单元素的枚举类型目前是实现Singleton的最佳方法。枚举表示简洁,并提供了序列化机制,即使在面对复杂的序列化或者反射攻击的时候,能够绝对防止多次序列化。

public enum Elvis {INSTANCE;public void leaveTheBuilding() {System.out.println("Whoa baby, I'm outta here!");}// This code would normally appear outside the class!public static void main(String[] args) {Elvis elvis = Elvis.INSTANCE;elvis.leaveTheBuilding();}}

?

3、IOC(控制反转)/DI(依赖注入)

它的主要目的是实现松散耦合,以便提升整个解决方案的可维护性。松散耦合可被概述为基于接口而不是具体实现进行编程的思想。但是,因为接口没有构造函数,如何创建那些接口的实例马上就成了一个问题。

参考Martin Fowler的两篇文章


first: http://martinfowler.com/bliki/InversionOfControl.html


second: http://martinfowler.com/articles/injection.html


4、Servlet技术简介: http://www.ibm.com/developerworks/cn/education/java/j-intserv/index.html

里面有一个简单的demo,可以帮助学习或者复习基本的Servlet,里面的例子稍稍修改了一点,主要是I/O操作方面的,还有这个例子的代码感觉有个别地方有点小错误,修改了一下。附件contacts.zip是代码。

?

另一篇文章:http://www.oschina.net/question/12_52027

再一篇:http://www.ibm.com/developerworks/cn/java/j-lo-servlet/


5、float和double类型不适合用于货币计算,使用BigDecimal、int、long进行货币计算。

相对于int和long类型,BigDecimal(可以处理超过18位的数字)使用起来相对麻烦,但对于完全控制舍入进行业务计算,使用它非常方便。

另外一点是,使用float和double进行比较的时候,应该使用他们包装类的compare方法,如Float.compare和Double.compare,至于为什么要这样使用,可以查看你Double和Float的API,其中的equals方法。


6、ANT常用标签:http://ant.apache.org/manual/index.html

之后点击Ant Tasks, 然后点击Overview of Ant Tasks, 可以看到所有的标签,如果你想了解某一个,可以自行查看。


7、关于注解的基础知识: http://www.infoq.com/cn/articles/cf-java-annotation


import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHOD)public @interface RequiredRoles {    String[] value();}


import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;import java.security.AccessControlException;import java.util.Arrays;public class AccessInvocationHandler<T> implements InvocationHandler {final T accessObj;public AccessInvocationHandler(T accessObj) {this.accessObj = accessObj;}public Object invoke(Object proxy, Method method, Object[] args)throws Throwable {RequiredRoles annotation = method.getAnnotation(RequiredRoles.class); // 通过反射API获取注解if (annotation != null) {String[] roles = annotation.value();// String role = AccessControl.getCurrentRole();String role = "user";if (!Arrays.asList(roles).contains(role)) {throw new AccessControlException("The user is not allowed to invoke this method.");}}return method.invoke(accessObj, args);}}

?

???? Effective java中的item35(注解优先于命名模式)也有一些较好的解释。附件中的effective java second edition是电子书(英文版的)。


8、上面的注解代码中出现了动态代理,所以有必要了解动态代理的相关知识,下面是IBM上的一篇文章: Java 动态代理机制分析及扩展

?????? 关于代理的另一篇文章: http://www.iteye.com/topic/448655


9、深入理解java虚拟机(翻译):http://www.cnblogs.com/gengyulong/archive/2011/04/11/2012560.html


10、A filesystem is a higher level of abstraction. Filesystems are a particular method of arranging and interpreting data stored on a disk (or some other random-access, block-oriented device).


文件系统是更高层次的抽象,是安排、解释磁盘(或其他随机存取块设备)数据的一种独特方式。


11、深入学习java NIO,附件中有java NIO电子书。

????? a、? http://tutorials.jenkov.com/java-nio/index.html

????? b、 查看java编程思想的nio那一章(18.10-第十八章第十小节)

?

?

12、 pl/sql中NUMBER变量默认值是null。

?

DECLARE    v_num1 NUMBER := 0;    v_num2 NUMBER;BEGIN    IF v_num1 = v_num2 THEN        DBMS_OUTPUT.PUT_LINE ('v_num1 = v_num2');    ELSE        DBMS_OUTPUT.PUT_LINE ('v_num1 != v_num2');    END IF;END;

?输出结果是:

???????????????? v_num1 != v_num2
???????????????? PL/SQL procedure successfully completed.


13、RFCRequest for Comments)是各个标准机构提交的标准文档,研究人员和开发人员可以通过这些文档跟踪新技术。

?

14、jsoup使用:http://www.ibm.com/developerworks/cn/java/j-lo-jsouphtml/index.html?ca=drs-

?

15、shell中[ ]与[[ ]]条件测试有什么区别?
[ ]是shell内建的测试命令,[[ ]]是由外置命令/usr/bin/test进行测试,[[]]结构比Bash 的[]更加灵活,在[[]]结构中,将没有文件扩展或者是单词分离,但是会发生参数扩展和命令替换.:使用[[]],而不是[],能够阻止脚本中的许多逻辑错误.比如,尽管在[]中将给出一个错误,但是&&,||,<>操作还是能够工作在一个[[]]test 之中。

?

16、15.18.1.2 Optimization of String Concatenation(JLS中关于字符串连接操作符‘+’的性能说明)

An implementation may choose to perform conversion and concatenation in one
step to avoid creating and then discarding an intermediate String object. To
increase the performance of repeated string concatenation, a Java compiler may
use the StringBuffer class or a similar technique to reduce the number of intermediate
String objects that are created by evaluation of an expression.
For primitive types, an implementation may also optimize away the creation
of a wrapper object by converting directly from a primitive type to a string.?

还可以参考effective java2(items 51)

?

热点排行