JAVA-Important Interview Questions
JAVA-Important Interview Questions
JAVA-Important Interview Questions
Basics of Java
1. Explain JDK, JRE and JVM?
2. Why Java is platform independent?
3. Why java is not 100% Object oriented?
4. Explain the Features of java?
5. What is local variable and global variable?
6. What is static block and non-static block?
7. What is class loading operation and object loading operation?
8. What is this and super keyword?
9. What are constructors in java?
10. What is class and Objects?
Inbuilt Classes
42. What is Object class and its methods?
43. What is array and String?
44. When we will get ArrayIndexOutOfBoundsException and
NegativeArraySizeException?
45. What is difference between " equals() " and " == " in java?
Ans. equals() – it is a method present in Object class which is used to
compare the address of two objects. It can be overridden and can be used
o compare the state of the object.
(==) Equality Operator – It is an operator used to compare address of 2
object.
46. What is String and explain atleast 6 inbuilt methods of String?
47. Why String is immutable?
48. String class can be inherited by any other class?
49. Why String class is final?
50. What is String vs String buffer vs String builder?
String Buffer: -
• It is a final class extending object class and implementing
CharSequence, Serializable and Appendable interfaces.
String Buffer is a ‘mutable’ class, we can modify the values present
Difference Page 2
• String Buffer is a ‘mutable’ class, we can modify the values present
inside the created object.
• String Buffer is synchronized and it is thread safe.
String Builder: -
• It is a final class extending object class and implementing
CharSequence, Serializable and Appendable interfaces.
• StringBuilder is unsynchronized and it is thread unsafe.
Advanced Questions
77. What is multi-threading?
Ans. Multithreading in Java is a process of executing multiple threads
simultaneously.
A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve
multitasking.
However, we use multithreading than multiprocessing because threads
use a shared memory area. They don't allocate separate memory area so
saves memory, and context-switching between the threads takes less
time than process.
78. What is difference between Thread and runnable?
Ans.
Thread
• Thread is a class. It is used to create a thread.
• Each thread creates a unique object and gets associated with it.
Runnable
• Runnable is a functional interface which is used to create a thread.
Difference Page 4
79. What is Synchronization?
Ans - Synchronization in java is the capability to control the access of
multiple threads to any shared resource.
Java Synchronization is better option where we want to allow only one
thread to access the shared resource.
The synchronization is mainly used to
1. To prevent thread interference.
2. To prevent consistency problem.
Difference Page 5
• Write file
• Change file permissions
Difference Page 6