*Q1.How could a Java program redirect error messages to a file while sending other messages to the system console?<o:p></o:p> |
A. We can use multiple thread:one thread is for redirect.the anothor is for sending messages to the system console;At the same time,We have to use synchronized modifer to limit our action when we send messages.<o:p></o:p> |
<o:p></o:p> |
*Q2.What's the difference between an interface and an abstract class?<o:p></o:p> |
A. Interface is absolute abstract class..All motheds in interface are abstract and we don not need public static modifer to modify abstract methods.All constant in interface are public static final.<o:p></o:p> B. Abstract class may have non abstract method.But if there is a method which is abstract,We need add abstract modifer to modify<o:p></o:p> This class;<o:p></o:p> |
<o:p></o:p> |
*Q3. Why would you use a synchronized block vs. synchronized method?<o:p></o:p> |
A. We use a synchronized block to synchronize a whole object.As you know some time We may reuse the same class which need not include a synchronized method.While we provided a class in which we implemented synchronized,we can not change it .So the first one is more flexible.<o:p></o:p> |
<o:p></o:p> |
**Q4. 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? <o:p></o:p> |
A.Partly we can.But Inheritence for java is single.We realize multiple inheritances through interface.For example,we only can extends one abstract class but we can implements more than one interfaces.<o:p></o:p> |
<o:p></o:p> |
*Q5. How can you force garbage collection?<o:p></o:p> |
A.We can not force garbage collection.Garbage collection is daemon thread which runs at backround.<o:p></o:p> |
<o:p></o:p> |
*Q6. How do you know if an explicit object casting is needed?<o:p></o:p> |
A. Most of runtime exception are needed to cast explicitly.Such as FilenotFoundException.But I get some information from IDE;<o:p></o:p> |
<o:p></o:p> |
*Q7. What's the difference between the methods sleep() and wait()<o:p></o:p> |
A. The method sleep is to halt a thread in a limited time.When the time is up,then this thread is alive.While wait() method have to be invoked by other thread with notify method or notifyAll method.<o:p></o:p> |
<o:p></o:p> |
*Q8. Can you write a Java class that could be used both as an applet as well as an application?<o:p></o:p> |
A. <o:p></o:p> |
<o:p></o:p> |
*Q9. What's the difference between constructors and other methods?<o:p></o:p> |
A. Constructors are used to initialize some values.When we did not surrply any customize constructors.The jvm can provide us a default <o:p></o:p> Construct without parameter.In java,in order to encapsulate,we need surrply some methods to access some private values.The constructors do not have return value and their name are the same with the class name and construct can not be overrided.<o:p></o:p> |
<o:p></o:p> |
*Q10. Can you call one constructor from another if a class has multiple constructors<o:p></o:p> |
A. ok,that is no problem.We can use this(…) method to call other constructors.<o:p></o:p> |
<o:p></o:p> |
*Q11. Explain the usage of Java packages.<o:p></o:p> |
A.Java package is for to archive some files in order to manage our class.We can use import XXXpackage.someclass to use class in this package if this class has public modifier.If these classes are in the same package,we need not use import …<o:p></o:p> |
<o:p></o:p> |
*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?<o:p></o:p> |
A. We don not need.We can use import XXXpackage.someclass to use class in this package if this class has public modifier.If these classes are in the same package,we need not use import …<o:p></o:p> |
<o:p></o:p> |
*Q13. What's the difference between J2SDK 1.5 and J2SDK 5.0?<o:p></o:p> |
A.I think they are the same.<o:p></o:p> |
<o:p></o:p> |
**Q14. What's the difference between a queue and a stack?<o:p></o:p> |
A. Queue’s character is first in first out. Stack’s character is last in first <o:p></o:p> |
Out.<o:p></o:p> |
*Q15. Explain the usage of the keyword transient?<o:p></o:p> |
A. When we do not want to serialize some values,we can declare some valuable with transient modifer.<o:p></o:p> |
<o:p></o:p> |
**Q16. What comes to mind when you hear about a young generation in Java?<o:p></o:p> |
A. I think it may bring us more functions and we can develop more convinent.<o:p></o:p> |
<o:p></o:p> |
**Q17. What comes to mind when someone mentions a shallow copy in Java?<o:p></o:p> |
A. I think most object are referenced.If we want to copy a object,we should override the clone method.If there is another object included in this object.We also need to orverride the clone method for another.Through this,we can realize deep copy.<o:p></o:p> |
<o:p></o:p> |
**Q18. If you're overriding the method equals() of an object, which other method you might also consider?<o:p></o:p> |
A. I might condider hashCode() method;<o:p></o:p> |
<o:p></o:p> |
**Q19. 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?<o:p></o:p> |
A. I will use ArrayList because it is fast in access.While LinkedList is fast in modify and delete.<o:p></o:p> |
<o:p></o:p> |
*Q20. What's the main difference between a Vector and ArrayList<o:p></o:p> |
A. The vector is a safe class while arraylist is not and vector should be initialize its capacity.such as Vector v = new Vector(10);<o:p></o:p> |
<o:p></o:p> |
*Q21. When should the method invokeLater()be used?<o:p></o:p> |
A. If we want to improve our response efficient,we can use invokeLater to do something else at background.<o:p></o:p> |
<o:p></o:p> |
**Q22. How would you make a copy of an entire Java object with its state?<o:p></o:p> |
A. . we should override the clone method.If there is another object included in this object.We also need to orverride the clone method for another.Through this,we can realize deep copy.<o:p></o:p> |
<o:p></o:p> |
*Q23. What would you use to compare two String variables - the operator == or the method equals()?<o:p></o:p> |
A.I will use equals() method if I need to know if their values are equal.<o:p></o:p> If I need to know the two strings object are the same object ,I will use operator ==.<o:p></o:p> |
<o:p></o:p> |
**Q24. How can you minimize the need of garbage collection and make the memory use more effective?<o:p></o:p> |
A. we can use single-pattern factory to create a object and try my best to avoid using new operator.<o:p></o:p> |
<o:p></o:p> |
*Q25. How can a subclass call a method or a constructor defined in a superclass?<o:p></o:p> |
A. We can use super().XXX method to call another method.<o:p></o:p> |
<o:p></o:p> |
**Q26. 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?<o:p></o:p> |
A. A class should include a reference to b class.<o:p></o:p> |
<o:p></o:p> |
*Q27. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?<o:p></o:p> |
A. We need not any declaration.<o:p></o:p> |
<o:p></o:p> |
*Q28. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?<o:p></o:p> |
A. no matter.<o:p></o:p> |
<o:p></o:p> |
*Q29. Can an inner class, declared inside of a method, access local variables of this method?<o:p></o:p> |
A. no problem.<o:p></o:p> |
<o:p></o:p> |
*Q30. What can go wrong if you replace && with & in the following code: |
A. It will throw nullpointrefferenceerexception.<o:p></o:p> |
<o:p> </o:p>