锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Technorati Tags: LOP Technorati Tags: Java | AjaxFaces For senior-level developers: Technorati Tags: Java | Interview 涓嬮潰鏄竴涓畝鍗曠殑渚嬪瓙錛?BR>Java Code錛?/EM> Technorati Tags: H8A8 | Hibernate
Let's go and see.
]]>
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.
A fully functional evaluation version of AjaxFaces 1.0 is available for download.
]]>
)
A. The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:
*Q2. What's the difference between an interface and an abstract class?(Interface鍜屾娊璞$被鐨勫尯鍒傝佺敓甯歌皥鐨勯棶棰樹簡(jiǎn)鈥︹?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
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.
*Q3. Why would you use a synchronized block vs. synchronized method?(浠涔堟椂鍊欎綘浼?xì)鐢╯ynchronized 鏂規(guī)硶錛熶粈涔堟椂鍊欎細(xì)鐢╯ynchronized 鍧?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. Synchronized blocks place locks for shorter periods than synchronized methods.
*Q4. Explain the usage of the keyword transient?(璋堜竴涓嬪叧閿瓧transient鐨勪綔鐢?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
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).
*Q5. How can you force garbage collection?(浣犺兘寮哄埗鎵ц鍨冨溇鍥炴敹鍚楋紵)
A. You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.
*Q6. How do you know if an explicit object casting is needed?(浠涔堟椂鍊欒鍋氬己鍒剁被鍨嬭漿鎹紵)
A. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:
When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.
*Q7. What's the difference between the methods sleep() and wait() (sleep() 鍜?wait() 鐨勫尯鍒?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), 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.
*Q8. Can you write a Java class that could be used both as an applet as well as an application? (浣犺兘鍐欎竴涓▼搴忓嵆浣滀負(fù)Applet鍙堜綔涓篈pplication鍚楋紵 鈥斺旂粡甯稿共鐨?IMG height=19 src="http://m.tkk7.com/Emoticons/QQ/22.gif" width=19 border=0>)
A. Yes. Add a main() method to the applet.
*Q9. What's the difference between constructors and other methods? (鏋勯犲嚱鏁板拰鍏朵粬鐨勬柟娉曟湁浠涔堝尯鍒?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
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.
*Q10. Can you call one constructor from another if a class has multiple constructors (鍦ㄥ彟澶栦竴涓瀯閫犲嚱鏁伴噷鎬庝箞璋冨叾浠栫殑鏋勯犲嚱鏁?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. Yes. Use this() syntax.
*Q11. Explain the usage of Java packages.(璇磋Package鐨勭敤澶?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
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.
*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?
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:
*Q13. What's the difference between J2SDK 1.5 and J2SDK 5.0? (J2SDK 1.5 鍜?J2SDK 5.0 鏈変粈涔堝尯鍒?IMG height=19 src="http://m.tkk7.com/Emoticons/75_75.gif" width=19 border=0>)
A.There's no difference, Sun Microsystems just re-branded this version.
*Q14. What would you use to compare two String variables - the operator == or the method equals()? (姣旇緝涓や釜String鐨勬椂鍊欑敤==榪樻槸equals()鏂規(guī)硶)
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.
*Q15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?(濡傛灉鍚屾椂鎹曟崏FileNotFoundException 鍜孖OExceptipon catch鍐欑殑欏哄簭闇瑕佹敞鎰忓悧)
A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.
*Q16. Can an inner class declared inside of a method access local variables of this method?
A. It's possible if these variables are final.
*Q17. What can go wrong if you replace && with & in the following code: (濡傛灉涓嶅皬蹇?jī)鐢?amp;浠f浛浜?amp;&涓嬮潰榪欏彞璇濅細(xì)鎬庝箞鏍?IMG height=20 src="http://m.tkk7.com/Emoticons/QQ/25.gif" width=20 border=0>)
*Q18. What's the main difference between a Vector and an ArrayList (Vector鍜孉rrayList鐨勪富瑕佸尯鍒?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. Java Vector class is internally synchronized and ArrayList is not.
*Q19. When should the method invokeLater()be used? (invokeLater()浠涔堟儏鍐典笅浼?xì)琚敤鍒板Q?IMG height=20 src="http://m.tkk7.com/Emoticons/QQ/21.gif" width=20 border=0>閲嶆潵娌℃湁鐢ㄥ埌榪団︹?
A. This method is used to ensure that Swing components are updated through the event-dispatching thread.
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.
**Q21. What's the difference between a queue and a stack? (闃熷垪鍜屽爢鏍堟湁浠涔堝尯鍒?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>瀛﹁繃鏁版嵁緇撴瀯鐨勯兘搴旇鐭ラ亾鈥︹?
A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule
**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://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.
**Q23. What comes to mind when you hear about a young generation in Java? (榪欑闂涔熸嬁鏉ラ潰璇?IMG height=20 src="http://m.tkk7.com/Emoticons/QQ/20.gif" width=20 border=0>)
A. Garbage collection.
**Q24. What comes to mind when someone mentions a shallow copy in Java? (褰撴彁鍒版祬鎷瘋礉鐨勬椂鍊欙紝浣犱細(xì)鎯沖埌浠涔?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. Object cloning.
**Q25. If you're overriding the method equals() of an object, which other method you might also consider? (鍦ㄤ綘閲嶅啓equals鏂規(guī)硶鐨勬椂鍊欙紝浣犺繕浼?xì)鎯冲埌閲嶅啓浠涔堟柟娉?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. hashCode()
**Q26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:
ArrayList or LinkedList? (浣犳墦綆楀涓浜汷bject榪涜绱㈠紩鎼滅儲(chǔ)錛屼綘浼?xì)鐢ˋrrayList榪樻槸LinkedList)
A. ArrayList
**Q27. How would you make a copy of an entire Java object with its state? (鎬庢牱鎵嶈兘鍏嬮殕涓涓狫ava瀵硅薄)
A. Have this class implement Cloneable interface and call its method clone().)
A. Use object pooling and weak object references.)
A. If these classes are threads I'd consider notify() or notifyAll(). For regular classes you can use the Observer interface.
*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://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>)
A. You do not need to specify any access level, and Java will use a default package access level.
鎬葷殑鏉ヨ鑰佸鐨凧ava闈㈣瘯浣撳お綆鍗曚簡(jiǎn)鈥︹﹁浜烘槒鏄忔鐫″晩鈥︹?IMG height=19 src="http://m.tkk7.com/Emoticons/77_77.gif" width=19 border=0>
]]>
Hibernate Mapping鏂囦歡錛?/EM>
]]>
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:
- code cleaning
- code clarifying
Once I've done that, I understand the code/project better, and I can start adding tests, and functionalities.
Note: all the actions below are possible thanks to modern tools, and 100% safe refactorings => no need to write tests first.
Code cleaning : First, I run a quick and fully automated analysis of the code, with just a few rules:
- remove dead code (classes, methods).
- remove unused method parameters, variables
- remove useless variable initialisation
- remove useless Casting
- tighten visibility (public => private)
- move tests code to a separate code tree
- modernize (Java1.4 => Java5)
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.
Code clarifying : I examine the code structure, starting with the 2-mile high view of the project, and going down. Along the way, I would perform :
- rename : (package, class, method, parameter
- move : package, classes, methods, ...
- extract/inline method
- introduce variable
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..
Some advice from Rod:
Today, there are many API and technology choices for most problems in J2EE.
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.
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.
There are many ways to avoid duplication of effort and leverage existing code. I suggest the following practices as a starting point:
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.
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.
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.
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.
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.
Use code reviews. This not only helps to boost quality, but also spurs communication within a team.
Technorati Tags: Java