﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Treacle-随笔分类-Java</title><link>http://www.blogjava.net/Blake/category/1582.html</link><description>Java Toxication!</description><language>zh-cn</language><lastBuildDate>Wed, 07 Mar 2007 11:38:43 GMT</lastBuildDate><pubDate>Wed, 07 Mar 2007 11:38:43 GMT</pubDate><ttl>60</ttl><item><title>Language Oriented Programming 面向语言编程</title><link>http://www.blogjava.net/Blake/archive/2005/06/17/6285.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Fri, 17 Jun 2005 05:31:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/17/6285.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/6285.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/17/6285.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/6285.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/6285.html</trackback:ping><description><![CDATA[<FONT face=Arial size=2>你还在使用Java吗？还在研究.Net吗？在你忙于此的时候，一种新的技术又诞生了，完全打破了传统编程的格局。这就是<A href="http://www.onboard.jetbrains.com/is1/articles/04/10/lop/">LOP(Language Oriented Programming)</A>。这项技术是由<A href="http://www.jetbrains.com/">JetBrains</A>的CEO <A href="http://www.sergeydmitriev.com/">Sergey Dmitive</A>提出的。他认为现在的编程模式还停留在石器时代，OO只是我们的石斧，提供给我们足够的帮助，但是他将会在最困难的问题面前土崩瓦解。于是，他便提出了伟大的LOP。<BR>LOP放弃了传统的基于文本的语言，用创造新的语言来代替类库，可以和编辑器所整合，并且每个程序员都可以创造自己的语言。<BR>也许你对LOP并不屑一顾，但著名的<A href="http://martinfowler.com/">Martin Flower</A>却对此饶有兴趣，并写了<A href="http://www.martinfowler.com/articles/languageWorkbench.html">Language Workbenches</A>和<A href="http://www.martinfowler.com/articles/mpsAgree.html">A Language Workbench in Action - MPS</A>两部著作。<BR>今天，JetBrain终于发布了支持LOP的<A href="http://www.jetbrains.com/idea/">IDEA</A>插件<A href="http://www.jetbrains.com/mps/">MPS(Meta Programming System)</A>&nbsp;<A href="http://www.jetbrains.net/confluence/display/MPS">download</A>。虽然这只是一个原形，但给人的感觉却是非常震撼的。<A href="http://www.martinfowler.com/articles/languageWorkbench.html">这里</A>是一个Hello World的教程。<BR>今后软件行业将会如何？什么才是未来的趋势？在未来的5年里我们会用language workbenches编程吗？<BR>Let's go and see. </FONT>
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/LOP" rel=tag>LOP</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/17/6285.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/17/6285.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/6285.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-17 13:31 <a href="http://www.blogjava.net/Blake/archive/2005/06/17/6285.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AjaxFaces 1.0 released</title><link>http://www.blogjava.net/Blake/archive/2005/06/06/5634.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Mon, 06 Jun 2005 13:59:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/06/5634.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/5634.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/06/5634.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/5634.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/5634.html</trackback:ping><description><![CDATA[<FONT face=Arial size=2><A href="http://www.cyberxp.net/">CyberXP.NET</A> has released </FONT><A href="http://www.ajaxfaces.com/" target=_blank><FONT face=Arial size=2>AjaxFaces</FONT></A><FONT face=Arial size=2>, an easy, general and complete integration solution for </FONT><A href="http://jcp.org/en/jsr/detail?id=127" target=_blank><FONT face=Arial size=2>JavaServer Faces </FONT></A><FONT face=Arial size=2>and </FONT><A href="http://www.adaptivepath.com/publications/essays/archives/000385.php" target=_blank><FONT face=Arial size=2>Ajax</FONT></A><FONT face=Arial size=2>. This solution makes any JavaServer Faces UI component Ajaxable: either trigger Ajax process or change user interface using the output from Ajax process.<BR><BR>The CyberXP.NET AjaxFaces Components also provide various user-interface components with built-in functionality - such as trees, and calendars - that can be customized and re-used in your application. Some of these components have built-in Ajax functionality.<BR><BR>A fully functional evaluation version of AjaxFaces 1.0 is available for </FONT><A href="http://www.cyberxp.net/ajaxfaces/myaccount_downloads.php" target=_blank><FONT face=Arial size=2>download</FONT></A><FONT face=Arial size=2>.</FONT> 
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/Java" rel=tag>Java</A> | <A href="http://www.technorati.com/tags/AjaxFaces" rel=tag>AjaxFaces</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/06/5634.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/06/5634.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/5634.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-06 21:59 <a href="http://www.blogjava.net/Blake/archive/2005/06/06/5634.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Core Java Interview Questions</title><link>http://www.blogjava.net/Blake/archive/2005/06/06/5629.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Mon, 06 Jun 2005 12:06:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/06/5629.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/5629.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/06/5629.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/5629.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/5629.html</trackback:ping><description><![CDATA[<FONT face=Arial size=2><STRONG><FONT face=Georgia size=3>30 Java Interview Questions</FONT><BR><BR></STRONG></FONT>
<DIV><FONT face=Arial size=2></FONT></DIV>
<DIV><B><FONT face=Arial size=2>*Q1. How could Java classes direct program messages to the system console, but error messages, say to a file? (怎样改变Java程序的标准输出输出到一个文件，而不是console<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. The class System has a variable <I>out</I> that represents the standard output, and the variable <I>err</I> that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:<BR></FONT></DIV>
<DIV><SPAN class=Code><FONT style="BACKGROUND-COLOR: #f5f5dc" face=Arial color=#006400 size=2>Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st);</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q2. What's the difference between an interface and an abstract class?(Interface和抽象类的区别。老生常谈的问题了……<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q3. Why would you use a synchronized block vs. synchronized method?(什么时候你会用synchronized 方法？什么时候会用synchronized 块<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Synchronized blocks place locks for shorter periods than synchronized methods.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV>
<DIV><STRONG><BR><FONT face=Arial size=2>*Q4. Explain the usage of the keyword transient?(谈一下关键字transient的作用<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></STRONG></DIV>
<DIV><BR><FONT face=Arial size=2>A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).</FONT></DIV></DIV>
<DIV><B><BR><BR><FONT face=Arial size=2>*Q5. How can you force garbage collection?(你能强制执行垃圾回收吗？<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><FONT face=Arial size=2></FONT></DIV>
<DIV><BR><FONT face=Arial size=2>A. You can't force GC, but could request it by calling System.gc(). <STRONG><FONT color=#ff0000>JVM does not guarantee that GC will be started immediately.</FONT></STRONG></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q6. How do you know if an explicit object casting is needed?(什么时候要做强制类型转换？<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:</FONT></DIV>
<DIV><SPAN class=Code>
<DIV><FONT style="BACKGROUND-COLOR: #f5f5dc" face=Arial color=#006400 size=2>Object a; Customer b; b = (Customer) a;</FONT></DIV></SPAN><BR><FONT face=Arial size=2>When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q7. What's the difference between the methods sleep() and wait() (sleep() 和 wait() 的区别<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. The code <SPAN class=Code>sleep(1000); </SPAN>puts thread aside for exactly one second. The code <SPAN class=Code>wait(1000), </SPAN>causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q8. Can you write a Java class that could be used both as an applet as well as an application? (你能写一个程序即作为Applet又作为Application吗？<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>&nbsp;——经常干的<IMG height=19 src="http://www.blogjava.net/Emoticons/QQ/22.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Yes. Add a main() method to the applet.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q9. What's the difference between constructors and other methods? (构造函数和其他的方法有什么区别<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q10. Can you call one constructor from another if a class has multiple constructors (在另外一个构造函数里怎么调其他的构造函数<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Yes. Use this() syntax.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q11. Explain the usage of Java packages.(说说Package的用处<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you'd need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:</FONT></DIV>
<DIV><SPAN class=Code><FONT face=Arial size=2>c:\&gt;java com.xyz.hr.Employee</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q13. What's the difference between J2SDK 1.5 and J2SDK 5.0? (J2SDK 1.5 和 J2SDK 5.0 有什么区别<IMG height=19 src="http://www.blogjava.net/Emoticons/75_75.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial><FONT size=2>A.There's no difference, Sun Microsystems just re-branded this version.<BR><BR><BR><STRONG>*Q14. What would you use to compare two String variables - the operator == or the method equals()? (比较两个String的时候用==还是equals()方法<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</STRONG></FONT></FONT>&nbsp; 
<DIV><BR><FONT face=Arial><FONT size=2>A. I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.<BR><BR><BR><STRONG>*Q15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?(如果同时捕捉FileNotFoundException&nbsp;和IOExceptipon catch写的顺序需要注意吗<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</STRONG></FONT></FONT> 
<DIV><BR><FONT face=Arial size=2>A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q16. Can an inner class declared inside of a method access local variables of this method?</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. It's possible if these variables are final.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV><B>
<DIV><BR><FONT face=Arial size=2>*Q17. What can go wrong if you replace &amp;&amp; with &amp; in the following code: (如果不小心用&amp;代替了&amp;&amp;下面这句话会怎么样<IMG height=20 src="http://www.blogjava.net/Emoticons/QQ/25.gif" width=20 border=0>)</FONT></DIV>
<DIV><SPAN class=Code><FONT face=Arial size=2>String a=null; if (a!=null &amp;&amp; a.length()&gt;10) {...}</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT></DIV></B>
<DIV>
<DIV><FONT face=Arial size=2>A. A single ampersand here would lead to a NullPointerException.</FONT></DIV></DIV></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV><BR><STRONG><FONT face=Arial size=2>*Q18. What's the main difference between a Vector and an ArrayList (Vector和ArrayList的主要区别<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></STRONG> 
<DIV><BR><FONT face=Arial size=2>A. Java Vector class is internally synchronized and ArrayList is not.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><BR><FONT face=Arial size=2>*Q19. When should the method invokeLater()be used? (invokeLater()什么情况下会被用到？<IMG height=20 src="http://www.blogjava.net/Emoticons/QQ/21.gif" width=20 border=0>重来没有用到过……)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. This method is used to ensure that Swing components are updated through the event-dispatching thread.<BR><BR><BR></FONT>
<DIV><B><FONT face=Arial size=2>*Q20. How can a subclass call a method or a constructor defined in a superclass? (子类怎么调用父类的方法<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.<BR><!--StartFragment -->&nbsp;</FONT> 
<P><SPAN style="FONT-WEIGHT: bold"><FONT face=Arial><EM>For senior-level developers:</EM></FONT></SPAN></P>
<DIV><B><BR><FONT face=Arial size=2>**Q21. What's the difference between a queue and a stack? (队列和堆栈有什么区别<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>学过数据结构的都应该知道……)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><STRONG><BR><FONT face=Arial size=2>**Q22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces? (又是抽象类和Interface的问题<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></STRONG><FONT face=Arial size=2> </FONT>
<DIV><BR><FONT face=Arial size=2>A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.</FONT></DIV></DIV>
<DIV><FONT face=Arial size=2></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>**Q23. What comes to mind when you hear about a young generation in Java? (这种问题也拿来面试<IMG height=20 src="http://www.blogjava.net/Emoticons/QQ/20.gif" width=20 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Garbage collection.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>**Q24. What comes to mind when someone mentions a shallow copy in Java? (当提到浅拷贝的时候，你会想到什么<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Object cloning.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>**Q25. If you're overriding the method equals() of an object, which other method you might also consider? (在你重写equals方法的时候，你还会想到重写什么方法<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. hashCode()</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>**Q26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: <BR>ArrayList or LinkedList? (你打算对一些Object进行索引搜索，你会用ArrayList还是LinkedList<IMG height=19 src="http://www.blogjava.net/Emoticons/72_72.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. ArrayList</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>**Q27. How would you make a copy of an entire Java object with its state? (怎样才能克隆一个Java对象<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Have this class implement Cloneable interface and call its method clone().</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2></FONT></B></DIV>
<DIV><B><FONT face=Arial size=2>**Q28. How can you minimize the need of garbage collection and make the memory use more effective? (怎样才能需要最少的GC以及最大效率的使用内存<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. Use object pooling and weak object references.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><FONT face=Arial size=2>**Q29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it? (class A 要通知 class B， 你应该怎么做？<IMG height=19 src="http://www.blogjava.net/Emoticons/72_72.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. If these classes are threads I'd consider notify() or notifyAll(). For regular classes you can use the Observer interface.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><B><BR><FONT face=Arial size=2>*Q30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it? (怎样定义default的访问级别<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0>)</FONT></B></DIV>
<DIV><BR><FONT face=Arial size=2>A. You do not need to specify any access level, and Java will use a default package access level.<BR><BR><FONT color=#9acd32>总的来说老外的Java面试体太简单了……让人昏昏欲睡啊……<IMG height=19 src="http://www.blogjava.net/Emoticons/77_77.gif" width=19 border=0><BR></FONT></FONT></DIV></DIV></DIV></DIV>
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/Java" rel=tag>Java</A> | <A href="http://www.technorati.com/tags/Interview" rel=tag>Interview</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/06/5629.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/06/5629.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/5629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-06 20:06 <a href="http://www.blogjava.net/Blake/archive/2005/06/06/5629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JDK5.0时代的"XDoclet" for Hibernate</title><link>http://www.blogjava.net/Blake/archive/2005/06/06/5606.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Mon, 06 Jun 2005 07:15:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/06/5606.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/5606.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/06/5606.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/5606.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/5606.html</trackback:ping><description><![CDATA[<SPAN style="FONT-FAMILY: arial"><FONT size=2>JDK5.0有了一个新特性：Annotation. 通过Annotation，我们就可以在运行时读取代码中的注解，或者通过这些Annotation动态生成Code。在JDK5.0之前很多工具都是通过JavaDoc来实现类似的功能的。如：XDoclet。<BR>随着JDK5.0的诞生，XDoclet也将面临的重大的改变。更多的工具会使用</FONT></SPAN><SPAN style="FONT-FAMILY: arial"><FONT size=2>Annotation来代替JavaDoc。这就是<A href="http://www.peelmeagrape.net/h8a8/index.html">Hibernate Annotator (H8A8)</A>&nbsp;(<A href="http://www.peelmeagrape.net/h8a8/peelmeagrape-h8a8-0.1-preview.zip">download</A>)诞生的原因了。<BR>下面让我们来认识一下H8A8：<BR></FONT></SPAN>
<UL>
<LI style="FONT-FAMILY: arial"><FONT size=2>H8A8可以通过class中的Annotation来生成Hibernate Mapping。 </FONT>
<LI style="FONT-FAMILY: arial"><FONT size=2>H8A8是<A href="http://www.hibernate.org/72.html">XDoclet for Hibernate</A>的另一个代替品（针对Hibernate 3 和 JDK5.0）。 </FONT>
<LI style="FONT-FAMILY: arial"><FONT size=2>H8A8是<A href="http://www.hibernate.org/247.html">Hibernate Annotations</A>的另一个代替品。（Hibernate Annotations采用了<A href="http://jcp.org/en/jsr/detail?id=220">EJB3.0</A>的Annotation规范，但是不支持所有的Hibernate特性。） </FONT>
<LI style="FONT-FAMILY: arial"><FONT size=2>H8A8几乎支持用Java Annotation来生成所有Hibernate Mapping里的属性。</FONT></LI></UL>
<P><FONT face=Arial size=2>下面是一个简单的例子：<BR><FONT color=#ffa500><EM>Java Code：</EM></FONT><BR><IMG height=250 alt=h8a8_codesample.JPG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/h8a8_codesample.JPG" width=568 border=0><BR><BR><FONT color=#ffa500><EM>Hibernate Mapping文件：</EM></FONT><BR><IMG height=255 alt=h8a8_xmlsample.JPG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/h8a8_xmlsample.JPG" width=568 border=0><BR><BR></FONT></P>
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/H8A8" rel=tag>H8A8</A> | <A href="http://www.technorati.com/tags/Hibernate" rel=tag>Hibernate</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/06/5606.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/06/5606.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/5606.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-06 15:15 <a href="http://www.blogjava.net/Blake/archive/2005/06/06/5606.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Code Cleaning</title><link>http://www.blogjava.net/Blake/archive/2005/06/06/5602.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Mon, 06 Jun 2005 05:40:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/06/5602.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/5602.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/06/5602.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/5602.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/5602.html</trackback:ping><description><![CDATA[<P style="FONT-FAMILY: arial"><FONT size=2>Whipping inherited code into shape</FONT></P>
<BLOCKQUOTE style="FONT-FAMILY: arial">
<P><FONT size=2>When I receive code, and before adding anything new to it, I always spend a little time (1 hour, 1 day) on "preparing" the code for the later modifications. This preparation is made in 2 steps:</FONT></P>
<UL>
<LI><FONT size=2>code cleaning</FONT> 
<LI><FONT size=2>code clarifying</FONT></LI></UL>
<P><FONT size=2>Once I've done that, I understand the code/project better, and I can start adding tests, and functionalities.</FONT></P>
<P><FONT size=2>Note: all the actions below are possible thanks to modern tools, and 100% safe refactorings =&gt; no need to write tests first. </FONT></P>
<P><FONT size=2><B>Code cleaning :</B> First, I run a quick and fully automated analysis of the code, with just a few rules:</FONT></P>
<UL>
<LI><FONT size=2>remove dead code (classes, methods).</FONT> 
<LI><FONT size=2>remove unused method parameters, variables</FONT> 
<LI><FONT size=2>remove useless variable initialisation</FONT> 
<LI><FONT size=2>remove useless Casting </FONT>
<LI><FONT size=2>tighten visibility (public =&gt; private)</FONT> 
<LI><FONT size=2>move tests code to a separate code tree</FONT> 
<LI><FONT size=2>modernize (Java1.4 =&gt; Java5)</FONT></LI></UL>
<P><FONT size=2>Second: amongst the hundreds of inspections rules offered by IDEA, a few dozens will spot oddities and probable bugs in the code (like modifying the contents of a collection passed as parameter, etc..). In those "hot" locations, I add a "todo: check", or "todo: modernize" tag, for later review. </FONT></P>
<P></P>
<P><FONT size=2><B>Code clarifying :</B> I examine the code structure, starting with the 2-mile high view of the project, and going down. Along the way, I would perform :</FONT></P>
<UL>
<LI><FONT size=2>rename : (package, class, method, parameter</FONT> 
<LI><FONT size=2>move : package, classes, methods, ...</FONT> 
<LI><FONT size=2>extract/inline method</FONT> 
<LI><FONT size=2>introduce variable</FONT></LI></UL>
<P><FONT size=2>Note: As this has to be fast, I only "cure" the worst problems. I tag the others for later reviews: "to optimize", "to betterize", "to fix", "danger", etc..<BR></FONT></P></BLOCKQUOTE>
<HR style="WIDTH: 100%; HEIGHT: 2px">

<P style="FONT-FAMILY: arial"><FONT size=2><SPAN style="COLOR: rgb(154,205,50); FONT-STYLE: italic">Some advice from Rod:</SPAN><BR></FONT></P>
<DIV style="MARGIN-LEFT: 40px; FONT-FAMILY: arial">
<DIV class=section>
<H3 class=sect3-title><FONT size=2><A name=276></A><A name=ch04lev2sec24></A>Help! API Overload</FONT></H3>
<P class=first-para><FONT size=2><A name=277></A><A name=page167></A>Today, there are many API and technology choices for most problems in J2EE.</FONT></P>
<P class=para><FONT size=2>Even Sun now seems to be at the point where pulling it all together is so complex that we're seeing significant duplication of effort. For example, JDO and EJB 2.0 entity beans with CMP seem to overlap significantly.</FONT></P>
<P class=para><FONT size=2>Ultimately, we all pay for duplication of effort in increased effort and decreased quality. At least we can do our utmost to control it within our organization. I believe that code reuse impossible, and we should do our best to achieve it.</FONT></P>
<P class=para><FONT size=2>There are many ways to avoid duplication of effort and leverage existing code. I suggest the following practices as a starting point:</FONT></P>
<UL class=square-list type=square>
<LI class=first-listitem>
<P class=first-para><FONT size=2>Adopt existing frameworks where possible. For example, use a standard logging framework and an existing framework for web applications. However, don't force developers to use organization-wide standard frameworks if it seems that they're not proving a good fit to the problem in hand. Where multiple alternative frameworks exist, survey the options. Don't automatically assume that the first product you look at, or the most popular, will best meet your needs.</FONT></P>
<LI class=listitem>
<P class=first-para><FONT size=2>Have zero tolerance for code duplication. This indicates the need for generalization: try to avoid code duplication in the first place, but refactor it out of the way as soon as it appears.</FONT></P>
<LI class=listitem>
<P class=first-para><FONT size=2>Ensure good communication amongst developers. For example, have developers give presentations on modules they've recently completed, so that other developers know what common needs are emerging or have already been met. Encourage developers to encourage other developers to use the infrastructure components they've implemented.</FONT></P>
<LI class=listitem>
<P class=first-para><FONT size=2>Develop and maintain some simple infrastructure packages that implement functionality that's widely used. Document them well and ensure that all developers are aware of them.</FONT></P>
<LI class=listitem>
<P class=first-para><FONT size=2>Adopt standard architectural patterns, even where it's not possible to share code. It's much easier to avoid duplication of effort when working with familiar patterns.</FONT></P>
<LI class=listitem>
<P class=first-para><FONT size=2>Use code reviews. This not only helps to boost quality, but also spurs communication within a team.</FONT></P></LI></UL></DIV></DIV>
<BLOCKQUOTE style="FONT-FAMILY: arial">
<P><FONT size=2></FONT></P></BLOCKQUOTE>
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/Java" rel=tag>Java</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/06/5602.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/06/5602.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/5602.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-06 13:40 <a href="http://www.blogjava.net/Blake/archive/2005/06/06/5602.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>