Q1. What is the difference between List, Set and Map ?
Ans. List - Members are stored in sequence in memory and can be accessed through index.
Set - There is no relevance of sequence and index. Sets doesn't contain duplicates whereas multiset can have duplicates. Map - Contains Key , Value pairs.
Q2. Difference between Public, Private, Default and Protected ?
Ans. Private - Not accessible outside object scope.
Public - Accessible from anywhere.
Default - Accessible from anywhere within same package.
Protected - Accessible from object and the sub class objects.
Q3. Does Java support Multiple Inheritance ?
Ans. Interfaces does't facilitate inheritance and hence implementation of multiple interfaces doesn't make multiple inheritance. Java doesn't support multiple inheritance.
Q4. Difference between Checked and Unchecked exceptions ?
Ans. Checked exceptions and the exceptions for which compiler throws an errors if they are not checked whereas unchecked exceptions and caught during run time only and hence can't be checked.
Q5. What is a Final Variable ?
Ans. Final variable is a variable constant that cannot be changed after initialization.
Q6. Difference between HashMap and Hashtable?
Ans. Hashtable is synchronized whereas HashMap is not.
HashMap allows null values whereas Hashtable doesn’t allow null values.
Q7. What is casting?
Ans. There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference
Q8. What is difference between Encapsulation And Abstraction?
Ans. 1.Abstraction solves the problem at design level while encapsulation solves the problem at implementation level
2.Abstraction is used for hiding the unwanted data and giving relevant data. while Encapsulation means hiding the code and data into a single unit to protect the data from outside world.
3. Abstraction lets you focus on what the object does instead of how it does it while Encapsulation means hiding the internal details or mechanics of how an object does something.
4.For example: Outer Look of a Television, like it has a display screen and channel buttons to change channel it explains Abstraction but Inner Implementation detail of a Television how CRT and Display Screen are connect with each other using different circuits , it explains Encapsulation.
Q9. Difference between Abstract and Concrete Class ?
Ans. Abstract classes are only meant to be sub classed and not meant to be instantiated whereas concrete classes are meant to be instantiated.
Q10. Difference between Overloading and Overriding ?
Ans. Overloading - Similar Signature but different definition , like function overloading.
Overriding - Overriding the Definition of base class in the derived class.
Q11. Difference between Vector and ArrayList ?
Ans. Vectors are synchronized whereas Array lists are not.
Q12. What is a final variable ?
Ans. Final variable is a constant variable. Variable value can't be changed after instantiation.
Q13. What is a Final Method ?
Ans. A Method that cannot be overriden in the sub class.
Q14. What is a Final Class ?
Ans. A Class that cannot be sub classed.
Q15. What is an immutable class ?
Ans. Class using which only immutable (objects that cannot be changed after initialization) objects can be created.
Q16. Name few Java Exceptions ?
Ans. IndexOutofBound , NoClassDefFound , OutOfMemory , IllegalArgument.
Q17. What is "super" used for ?
Ans. Used to access members of the base class.
Q18. What is "this" keyword used for ?
Ans. Used to represent an instance of the class in which it appears.
Q19. What is a finalize method ?
Ans. finalize() method is called just before an object is destroyed.
Q20. Difference between Process and Thread ?
Ans. Process is a program in execution whereas thread is a separate path of execution in a program.
Q21. What is an Enum type ?
Ans. An enum type is a special data type that enables for a variable to be a set of predefined constants
Q22. Difference between StringBuffer and StringBuilder ?
Ans. StringBuffer is synchronized whereas StringBuilder is not.
Q23. Can we overload constructors ?
Ans. Yes.
Q24. Difference between nested and inner classes ?
Ans. Inner classes are non static nested classes.
Q25. what is the difference between collections class vs collections interface ?
Ans. Collections class is a utility class having static methods for doing operations on objects of classes which implement the Collection interface. For example, Collections has methods for finding the max element in a Collection.
Q26. Explain Thread States ?
Ans. Runnable - waiting for its turn to be picked for execution by the thread schedular based on thread priorities.
Running - The processor is actively executing the thread code. It runs until it becomes blocked, or voluntarily gives up its turn.
Waiting: A thread is in a blocked state while it waits for some external processing such as file I/O to finish.
Sleeping - Java threads are forcibly put to sleep (suspended) with Thread.sleep. they can resume using Thread.resume method.
Blocked on I/O - Will move to runnable after I/O condition like reading bytes of data etc changes.
Blocked on synchronization - Will move to Runnable when a lock is acquired.
Dead - The thread is finished working.
Q27. What is the advantage of using arrays over variables ?
Ans. Arrays provide a structure wherein multiple values can be accessed using single reference and index. This helps in iterating over the values using loops.
Q28. Advantage of Collection classes over Arrays ?
Ans. Collections are re-sizable in nature. We can increase or decrease the size as per recruitment.
Collections can hold both homogeneous and heterogeneous data's.
Every collection follows some standard data structures.
Collection provides many useful built in methods for traversing,sorting and search.
Q29. What is the difference between float and double?
Ans. Float can represent up to 7 digits accurately after decimal point, where as double can represent up to 15 digits accurately after decimal point.
Q30. What is the difference between System.out ,System.err and System.in?
Ans. System.out and System.err both represent the monitor by default and hence can be used to send data or results to the monitor. But System.out is used to display normal messages and results whereas System.err is used to display error messages and System.in represents InputStream object, which by default represents standard input device, i.e., keyboard.
Q31. Why is Java considered Portable Language ?
Ans. Java is a portable-language because without any modification we can use Java byte-code in any platform(which supports Java). So this byte-code is portable and we can use in any other major platforms.
Q32. Difference between throw and throws ?
Ans. throw is used to explicitly throw an exception especially custom exceptions, whereas throws is used to declare that the method can throw an exception.
We cannot throw multiple exceptions using throw statement but we can declare that a method can throw multiple exceptions using throws and comma separator.
Q33. What is an Object ?
Ans. Object is a run time entity whose state is stored in fields and behavior is shown via methods. Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.
Q34. What is a Class ?
Ans. A class is a blue print or Mold using which individual objects are created. A class can contain fields and methods to describe the behavior of an object.
Q35. How finally used under Exception Handling?
Ans. The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred.
Q36. What is the difference between a break statement and a continue statement?
Ans. Break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
Q37. What is an enum or enumeration?
Ans. An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection.
Q38. What are the features of encapsulation ?
Ans. Combine the data of our application and its manipulation at one place.
Encapsulation Allow the state of an object to be accessed and modified through behaviors.
Reduce the coupling of modules and increase the cohesion inside them.
Q39. Difference between Compositions and Inheritance ?
Ans. Inheritance means a object inheriting reusable properties of the base class. Compositions means that an abject holds other objects.
In Inheritance there is only one object in memory ( derived object ) whereas in Composition , parent object holds references of all composed objects.
From Design perspective - Inheritance is "is a" relationship among objects whereas Composition is "has a" relationship among objects.
Q40. Difference between PATH and CLASSPATH ?
Ans. PATH is the variable that holds the directories for the OS to look for executables. CLASSPATH is the variable that holds the directories for JVM to look for .class files ( Byte Code ).