Sep 28, 2008

Some imp Java Faq's

1. what’s the difference between an interface and an abstract class?
Ans: Interface is pure abstract class that is all the methods are abstract.
In abstract class all the methods need not be abstract.
2. why would you use a synchronized block vs. synchronized method?3. Explain the usage of the keyboard transient?
4. How can you force garbage collection?
Ans: By using the method runtime.gc()
5. what’s the difference between the method sleep( )and wait( )?
Ans:wait() can be used only for synchronized sleep() is irrespective of it.
6. Can you write a java class that could be used both as an applet as well as an application?Ans:Yes
7. what’s the difference between constructors and other methods?Ans: Constructors don’t have any return type whereas methods have.
8. Can you call one constructor from another if a class has multiple constructors?Ans:Yes using the key word “this”.
9. If a class is located in a package , what do you need to change in the OS environment to be able to use it?Ans:We need to change the “ClassPath” variable
10. what would you use to compare two string variables –the operator= = or the method equals?Ans: “equals” (= = is used to compare # code)
11. Does it matter in what order catch statements for FileNotFoundException and IOexception are written?
Ans:Yes.(super class exception should succeed sub class exception so FileNotFoundException should placed before IOexception)
12. what can go wrong if you replace && with & in the following code:
string a = null: if (a!=null && a. length ()>10){…}
Ans: (&& is logical operator whereas & bitwise operator)
13. How can a subclass call a method or a constructor defined in a superclass?
Ans:Using the super keyword.
14. Can there be an abstract class with no abstract methods in it?Ans:Yes if the clas itself is declared Abstract.
15. Can an interface have be final?Ans: No.If it is final it can’t be implemented at all.
16. Can an interface have an inner class?Ans: Yes.
17. Can we define private and protected modifiers for variables in interface?Ans:No it has to be public
18. What is a local, member and a class variable?19. what does it mean that a method or fields is “static”?
20. what is synchronization and why is it important?21. Is null a keyword?
Ans: No it is the reserved word
22. what is the range of the char type?Ans: ( 0-2^16-1)
23. what is similarities/difference between an abstract class and interface?
24. Explain the user defined exceptions?
25. Differentiate between java and c++?
26. what is a Expression?
27. Is main a keyword in java?
28. If I write system . exit (0); at the end of the try block, will the finally block still execute?
29. what are wrapper classes?
30. what if the static modifier is removed from the signature of the main method?

No comments: