Thrown when an application attempts to use null in a case where an object is required. These include:
Calling the instance method of a null object.
Accessing or modifying the field of a null object.
Taking the length of null as if it were an array.
Accessing or modifying the slots of null as if it were an array.
Throwing null as if it were a Throwable value.
Applications should throw instances of this class to indicate other illegal uses of the null object.
1. What is the difference between the class ArrayList and LinkedList ? When do you use ArrayList and when do you use LinkedList ?
2. What is an Iterator interface in Java?
3. What are the capabilities provided with the ListIterator interface that are not available with the Iterator when using a List collection ?
4. In Collection Framework, if we need to insert elements in the middle of the list, which implementation of the List interface is more suitable ?
5. In an application, if the requirement is to set up a list of elements initially and later on there are very few insertions and deletions and accessing of the elements is what is done more frequently, which implementation of the List interface is more suitable ?
6. The requirement in an application is to store unique elements in a data structure and the elements should not be duplicated. Which is the Collection interface that can be used ?
7. The requirement in an application is to store elements and the elements can be repeated. Which is the Collection interface that can be used ?
8. Does the Set interface add any new methods to the Collection Interface ?
9. If the requirement in an application is to store only elements that are unique and if on iteration through the collection, can result in any order of elements, which is the most suitable Collection class that can be used ?
10. If the requirement in an application is to store only elements that are unique and if on iteration through the collection, should result in the same order as the elements were inserted, which is the most suitable Collection class that can be used ?
11. If the requirement in an application is to store only elements that are unique and if on iteration through the collection, should result in the sorted order of the elements, which is the most suitable Collection class that can be used ? Also, if we need to have the elements sorted in a different order rather than the default order, how can we achieve this ?
12. What is the difference between a Iterator and ListIterator interface ?
13. If the requirement in an application is to store the key value pairs and there is no requirement to be in any particular order of the keys, which is the most suitable Collection class that can be used ?
14. If the requirement in an application is to store the key value pairs and the keys should be stored in a sorted order, which is the most suitable Collection class that can be used ? Also, if we need to have the keys sorted in a different order rather than the default order, how can we achieve this ?
15. If the requirement in an application is to store the key value pairs and the keys should be stored in the insertion order, which is the most suitable Collection class that can be used ?
16. Explain the use of the hashCode method which is present in Object class.
[ Hint: Refer the SCJP book by Khalid Mughal and Rolf Rasmussen for a detailed explanation of equals and hashCode ]
17. What is the difference between element access in ArrayList and HashMap ?
18. What is the difference between a Comparator interface and Comparable interface ?
[ Hint: Comparator interface - Total ordering; Comparable interface - Natural ordering ]
19. What is the difference between a HashSet and LinkedHashSet ?
20. What is the difference between a LinkedHashSet and TreeSet ?
21. What is the difference between a ArrayList and LinkedList ?
22. What is the difference between a HashMap and LinkedHashMap ?
23. What is the difference between a LinkedHashMap and TreeMap ?
24. What is the difference between a HashMap and Hashtable ?
25. What is the difference between a Vector and ArrayList ?
26. While creating LinkedHashMap, what is the use of the boolean parameter "accessOrder" in the constructor ?
.
Threads
-------
1. How do you create a thread and start it running ?
2. For what purpose is the keyword synchronized used for ?
3. Explain the use of wait, notify and notifyall in Java.
4. What is the difference between a daemon thread and a user thread ?
5. Explain the join feature in Threads.
6. What are the different states in which a thread can get into ?
7. Can a thread move directly into a running state from the blocked state ?
8. Explain about Singleton pattern and how to synchronize ?
help
9. What is the difference between class level synchronization and instance level synchronization ?
10. What is synchronized block and what is the difference between synchronized block and synchronized method ?
11. What is the yield method in Threads ?
12. What is the use of sleep method in Threads ?
13. What is the difference between multitasking and multithreading ?
14. When you write a normal Java application, a thread called the "main" thread is created ? What type of thread is it "user" thread or "daemon" thread ?
15. In order for a multithreaded application to end, which type of thread should not be running ? User thread or daemon thread.
16. Which is the preferable way of creating a thread ? Using Runnable interface or extending a Thread. Why ?
17. If we invoke the "run" method of a class implementing the Runnable interface directly, what will happen ? How is it different from using a "start" method to start a thread ?
18. Can a dead thread be restarted ?
19. Say 2 threads, t1 and t2 are created and then t1.start() and then t2.start() is invoked ? Which thread will move into the running state first ?
20. In a single CPU system, how many threads can be in the running state at one point of time ?
Abstract Classes and Interfaces
----------------------------------
1. Explain the difference between abstract class and interface.
2. Can we declare private methods in an interface? Explain the reason.
3. If we just declare the variables in an interface as "int i;" what does it actually expand to.
4. Is it legal to declare a class to be final abstract ? Explain why or why not.
Class / Constructors / OO Concepts / Access Modifers / Other specifiers
--------------------------------------------------------------------------
1. What is the difference between an instance method and a class method ?
2. What is difference between overloading and overriding ?
3. What is the "super" and "this" keyword used for ?
4. What are packages and what are they used for ?
5. What is the difference between finally, finalize and final ?
6. Describe instanceof operator and its use.
7. What does the following error message mean: Can't make a static reference to nonstatic variable ? Explain with a code example.
8. In method invocation, does Java pass arguments by reference or by value ? Explain with code examples.
9. What is polymorphism? Explain with example.
10. Explain the difference between overloading and overriding.
Exceptions
-----------------
1. What is an exception ? What are checked and unchecked exceptions ?
2. Given a method that doesn't declare any exceptions, can I override that method in a subclass to throw an exception ? Explain with code examples of valid and invalid method declaration in subclass/superclass throwing exceptions.
3. In a try-catch-finally statement, under what circumstances does the finally clause gets executed?
Serialization
----------------------
1. What is Serialization in Java?
2. When you serialize an object, how do you ensure that some of the variables in the object do not get stored in the persistent medium?
3. What interface must a class implement before it can be serialized ?
Subscribe to:
Posts (Atom)