JAVA : Good Interview questions.
1. Printing collection object reference in SOP -> All collection classes implemented toString() and prints in [....]
2. All Collection objects are implemented Serializable and Clonable interfaces.
3. Only ArrayList and Vector implements "RandomAccess" Interface (Retrieval is very very fast)
4. ArrayList Disadvantage and Advantage
5. LinkedList Disadvantage and Advantage
6. Assume "A", "B", "C" is added in Stack, if i print SOP(stackRef) what should i get..?
7. Does adding duplicate to HashSet will throw compile time or run time error...?
No compile time or No run time error, HashSet.add() -> simply returns true/false
8. LinkedHashSet vs HashSet
9. What are collection objects where sorting is there and heterogeneous objects are not allowed.
1. TreeSet
2. TreeMap
If we try to add Hetrogeneous objects, we get run time exception : ClassCasteException
10. Inheritance - what methods goes to child..?
11. If class level variable is private and there are no getter and setter how will you assign value..?
12. Inheritance No Reduction concept
13. JAVA Constructor chaining
14. Can we mark subclass method as abstract method...?
15. Can we write catch block after sop()....?
16. Some invalid try catch finally declarations..
Since from 1.7 version all resources are closed automatically no need to write finally block, just try with out catch/finally is valid.
17. Writing single catch block is good or multiple catch block..?
Multiple catch block is good : we can handle differently for each type of exception in each catch block.
Order of adding catch block is also important, If we define parent 1st than child, then compile time error will throw.
18. Exception - throw e
19 . Can we write statement after throw statement.
20. Can we write throws to main method..?
YES, we can write.
21 . Can we delegate throws to multiple level.
YES
22. Can we write throws to constructor..?
YES
23. Check below throw of Exception and Error
24. Difference b/n throw and throws
throw - handover created manual object to JVM
throws - deligate the responsbility of exception to caller.
If throw is there then throws is mandatory (only for checked exceptions)
If throws is there then throw is not mandatory.
25. If there is no chance of raising exception in try, can we write catch block for that..?
This rule is applicable only for : fully checked exception.
26. try with resource java 1.7v
27. Multi catch block in java 1.7v
28. Can we call start() already started Thread.
No . we get IllegalThreadStateException
29. Want to print "Exception in thread pavan" instead of "Exception in thread main" message...?
YES, we can change the name of main thread -> using Thread.currentThread().setName("Pavan");
30. Correct method to call from MyThread.
myThread.start() - Correct way
31. Generic - does JVM know about generic...?
No, JVM does not know generic, compiler will remove all generic syntax as part of its last step.
32 . Generic - Is super is allowed in bounded types...?
YES, possible but only for '?' not for 'T' type

33. Generic - is '?' is allowed while creating object..?
No. only in declaration part we should use '?'

34. Generics - is multiple class extends is possible..?
No, as same as java inheritance, multiple extends is not possible.

35. Generics - what declartion's are equal..?
Note : specifying "Parameter type" at declaration level only valid.
36. Generics - same method signature behavior
Note : Compiler steps
1. compile
2. remove generics
3. compile again
No comments:
Post a Comment