0% found this document useful (0 votes)
125 views9 pages

Core Java Interview Questions Guide

The document is a comprehensive list of core Java interview questions covering various topics such as JVM, JRE, object-oriented programming principles, constructors, exception handling, collections, and threading. It includes questions about Java features, memory management, and differences between various Java classes and interfaces. This resource serves as a guide for candidates preparing for Java-related interviews.

Uploaded by

cskb96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views9 pages

Core Java Interview Questions Guide

The document is a comprehensive list of core Java interview questions covering various topics such as JVM, JRE, object-oriented programming principles, constructors, exception handling, collections, and threading. It includes questions about Java features, memory management, and differences between various Java classes and interfaces. This resource serves as a guide for candidates preparing for Java-related interviews.

Uploaded by

cskb96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CORE JAVA INTERVIEW QUESTIONS

1. Explain about JVM ?


2. Explain about JRE ?
3. What is mean by bytecode?
4. Explain about [Link](" ..........");
1. why we want to use "System" ? and what is the "System"?
2. what is "out" and what it's use?
3. what is println?
5. Explain about public Static void main(String args[]) ?
1. why we are using “Static” in main method?
[Link] we are passing only (String args[]) as parameter?
6. Explain flow of java program execution?
7. Explain about JIT compilation?
8. Explain JAVA features?
9. Why java is object oriented programming language?
10. What are the principles of OOPS?
11. What is an object, explain properties of an object ?
12. What is class?
13. What is class class?
14. Explain Object class methods?
15. What is Encapsulation give me one example?
16. What is Abstraction give me one example?
17. What is mean by polymorphisms and types of polymorphism explain?
18. What is the difference between dynamic polymorphism and static
polymorphism?
19. Explain Is-a & has-a relationship?
20. What is object life time?

1
21. What is inheritance and explain types of inheritance?
22. What is constructor?
23. How many types of constructors are there and explain?
24. Can we call explicitly constructor?
25. How can we call from default constructor parameterized constructor?
26. Does a class inherit the constructor of its super class?
27. Can we make constructor static?
28. Can we make final keyword before constructor?
29. What is the difference between constructor and method?
30. What is hash code?

[Link] default value?


[Link] you declare a class as private?
[Link] is a constructor called, before or after creating the object?
[Link] is the difference between default constructor and parameterized
constructor?
[Link] is constructor over loading?
[Link] we make access specifiers before constructor?
[Link] is mean by Access specifier and types of access specifier?
[Link] order of Access specifier?
[Link] order of Access specifier?
[Link] is mean by access modifiers and explain?
[Link] is the difference between the instance variables and static variables?
[Link] are instance methods?
[Link] are static methods?
[Link] instance variable not available to static methods?
[Link] how many ways can you create an object in java?
[Link] is anonymous inner class?
[Link] are factory methods?

2
[Link] it possible to compile and run a java program without writing main
method()?
[Link] objects are passed to methods in java?
[Link] is the use of this(),this(..) keywords?
[Link] is the use of super(),super(..) keywords?
[Link] is the difference between this() and super() keywords?
[Link] we override private methods?
[Link] we take private methods and final methods as same?
[Link] is final?
[Link] to prevent method overriding?
[Link] to prevent inheritance in java?
[Link] is mean by shadowing?
[Link] we possible to override the static methods?
[Link] is static block and explain?
[Link] is instance block and explain?
[Link] is difference between instance block and static block?
[Link] more than one constructor in a class is called?
[Link] is specialization and generalization?
[Link] is implicit casting?
[Link] is explicit casting?
[Link] we call class as a data type?
[Link] happens if main() method is written without String args[ ] ?
[Link] you call the main() of a class from another class?
[Link] are the modifiers in java?
[Link] is abstract method?
[Link] is abstract class?
[Link] classes can contain abstract methods?
[Link] about transient modifier?
[Link] about native modifier?

3
[Link] about volatile modifier?
[Link] is mean by synchronisation?
[Link] would you use a synchronized block verses synchronized method?
[Link] is interface?
[Link] you write an interface without any methods?
[Link] do you call the interface without any members?
[Link] can you force your programmer to implement only the features of
your class?
[Link] we declare a class as abstract and final?
[Link] we override abstract methods?
[Link] we implement one interface from another?
[Link] the method of interfaces are public and abstract by default?
[Link] we write a class with in an interface?
[Link] is the difference between an interface and an abstract class?
[Link] we create an object to interface?
[Link] we go for abstract and interface in java?
[Link] we use interfaces?
[Link] is the difference between a class and an abstract class?
[Link] is the difference between an interface and an abstract class?
[Link] is class loader and explain types of class loaders?
[Link] about system class loader?
[Link] Annotations in java?
[Link] about memory management in java?
[Link] String a class or data type?
99. String s = “ pooji ” ;
String s1 = new String(“ pooji”);
[Link](s=s1);
[Link]([Link](s1));
What is the output?

4
100. What is object reference?
101. What is the difference between == and equals() while comparing
String? Which one is reliable?
102. What is string constant pool?
103. Why overrides equals() and hashcode()?
104. What is difference between String and StringBuffer classes?
105. What is main different between StringBuffer and StringBuilder
classes?
106. What is an Error?
107. Write an exception hierarchy?
108. What is an Exception?
109. What is the difference between error and an Exception?
110. What is mean by Exception handling?
111. What are the types of Exceptions?
112. What is throwable?
113. What is the super class for all Exceptions?
114. What is the difference between throws and throw?
115. Is it possible to re-throw exceptions?
116. What is the purpose of finally block?
117. What is the purpose of finalization?
118. Explain final, finally, finalization?
119. If i write [Link](0); at the end of the try block, will the finally
block will execute?
120. If i write return at the end of try block, will the finally block will
execute?
121. How to create user defined exceptions?
122. How to override methods in exception handling?
123. Can a top level class be private or protected?

5
124. What is the default value of an object reference declared as an
instance variable
125. Is it necessary that each try block must be fallowed by a catch
block?
126. What is fail fast exception?
127. How can you call the garbage collector?
128. What is the scope of default access specifier?
129. What is the difference between return and [Link](0)?
130. What is difference between [Link](0) and [Link](1);
131. Write collection hierarchy?
132. What are limitations of object Arrays?
133. What are differences between arrays and collections?
134. What is Collection API ?

135. What is Collection framework?


136. What is difference between Collections and Collection?
137. Explain about Collection interface?
138. Explain about List interface?
139. Explain about Set interface?
140. Explain about SortedSet interface?
141. Explain about NavigableSet ?
142. Explain about Queue interface?

143. Explain about Map interface?


144. Explain about SortedMap ?
145. Explain about NavigableMap?
146. Explain about ArrayList class?
147. What is RandomAccess Interface?
148. Explain about LinkedList class?
149. Explain about Vector class?

6
150. What is difference between ArrayList and Vector?
151. How we can get synchronized version of ArrayList?
152. What is difference between size and capacity of a Collection
Object?
153. What is difference between ArrayList and Linked List?
154. What are legacy classes and interfaces present in Collections
framework?
155. What is difference Enumeration and Iterator?
156. What are limitations of Enumeration?
157. What is difference between enum and Enumeration?
158. What is difference between Iterator and ListIterator?
159. What is relation between ListIterator and Iterator?

160. Explain about HashSet class?


161. If we are trying to insert duplicate values in Set what will happen?
162. What is LinkedHashSet?
163. Differences between HashSet and LinkedHashSet?
164. Explain about TreeSet?

165. What are differences between List and Set interfaces?


166. What is Comparable interface?

167. What is Comparator interface?


168. What are differences between Comparable and Comparator?
169. What is difference between HashSet and TreeSet?
170. What is Entry interface
171. Explain about HashMap?
172. Explain about LinkedHashMap?
173. Differences between HashMap and LinkedHashMap ?
174. Differences between HashMap and Hashtable?

7
175. What is IdentityHashMap?
176. What is TreeMap?
177. What is Hashtable?

178. Why ArrayList is faster than Vector?


179. What is introspection in java?
180. What is a reflection? How can you achive in java?
181. What is resource bundle?
182. Which thread always runs in a java program by default?
183. Why threads are called light_weight?
184. How can you stop a thread in java?
185. Which method is executed by the thread by default?
186. What is the difference between synchronized block and
synchronized keyword?
187. What is thread deadlock?
188. What is difference between the sleep() and wait() methods?
189. What is default priority of a thread?
190. What is a daemon thread?
191. What is thread life cycle?
192. What is the difference between extends thread and implements
runnable? Which one is advantageous?
193. How to create a thread?
194. What is serialization?
195. What is externalization?
196. How to prevent serialization?
197. What is wrapper class?
198. What is difference between int and Integer?
199. Objects are passed by value or passed by reference?
200. Primitive data types are passed by value or passed by reference?

8
201. What is difference between shallow copy and deep copy?

Common questions

Powered by AI

Java provides synchronization mechanisms crucial for the proper functioning of multi-threaded applications, primarily through the synchronized keyword and blocks. The synchronized keyword can be applied to methods and blocks to ensure that only one thread can execute the code block at a given time, thereby preventing data inconsistency and race conditions. Additionally, synchronized blocks can be used to synchronize a specific piece of code on an object, allowing for more fine-grained control over synchronization. The use of synchronized methods or blocks ensures thread safety when accessing shared resources simultaneously .

Java provides several mechanisms for memory management, including automatic garbage collection and explicit memory handling features. The garbage collector automatically reclaims memory by destroying objects that are no longer referenced, which helps prevent memory leaks. Additionally, Java uses a memory model that includes stack and heap memory, where method calls and local variables are stored in the stack, while objects are allocated on the heap. This separation helps manage memory more efficiently during program execution. Moreover, finalization allows an object to clean up resources before being garbage collected, though it is generally not used in favor of try-with-resources or explicit resource management .

Exception handling in Java is a mechanism to manage runtime errors, allowing a program to continue execution rather than terminate abruptly. It involves the use of try-catch blocks, where code that may throw exceptions is placed in the try block, and potential exceptions are caught and handled in the catch block. Additionally, a finally block can be used to execute code regardless of whether an exception occurs, such as resource cleanup. By providing a structured way to handle errors, exception handling improves program robustness and stability, ensuring that critical processes are completed even when unexpected issues arise .

Interfaces in Java can only declare methods and cannot provide any implementation (prior to Java 8 where default methods are allowed), allowing a class to implement multiple interfaces. Abstract classes, on the other hand, can have both fully defined and abstract methods, providing a base implementation that can be shared across subclasses. Abstract classes can also contain fields and constructors. Interfaces are used when a contract needs to be defined across classes without requiring common code, whereas abstract classes are chosen when there is a clear hierarchical relationship with shared code across subclasses. Use interfaces when you want to enforce a certain capability across different classes and abstract classes when creating a shared base class .

HashMap and Hashtable in Java both implement the Map interface and store key-value pairs. However, Hashtable is synchronized, meaning it is thread-safe and suitable for concurrent access by multiple threads, which can result in slower performance compared to HashMap. In contrast, HashMap is not synchronized and allows for more efficient single-threaded access. HashMap permits null keys and values, whereas Hashtable does not. These differences influence their usage; HashMap is preferred for non-threaded applications or when manual synchronization is used, while Hashtable is suitable for legacy multi-threaded environments where built-in synchronization is necessary .

Java is considered an object-oriented programming language because it is based on the concepts of objects and classes, which encapsulate data and behavior in a way that can be reused and manipulated. The key principles of OOP that Java follows include encapsulation, abstraction, inheritance, and polymorphism. Encapsulation is achieved through access modifiers that restrict access to certain components of an object. Abstraction allows developers to focus on essential qualities rather than specific characteristics of one particular object. Inheritance enables the creation of new classes based on existing ones, promoting code reuse. Polymorphism allows methods to do different things based on the objects they are dealing with .

'Shadowing' in Java occurs when a subclass or inner class declares a field with the same name as a field in its superclass or outer class. This can affect variable visibility as the subclass's field shadows or hides the inherited superclass field, making it inaccessible directly by its name. Accessing the superclass field then requires using super or fully qualified names depending on context. While shadowing can be intentional for overriding purposes, it can also lead to confusion and errors if developers are unaware of which variable they are referencing, introducing potential bugs in the program .

The Java Virtual Machine (JVM) executes a Java program by taking the compiled bytecode from the Java compiler and interpreting or compiling it into machine code suitable for the host system through Just-In-Time (JIT) compilation. The JVM starts by loading the class files and verifying bytecode, then it proceeds to interpret or use the JIT compiler to convert sections of bytecode into native machine code to improve performance. The JIT compiler optimizes the execution by translating frequently called methods to native code once and caching them for future use, reducing overhead and leveraging execution speed .

Polymorphism in Java can be classified into two main types: compile-time (static) polymorphism and runtime (dynamic) polymorphism. Compile-time polymorphism is achieved through method overloading, where multiple methods have the same name but differ in parameter type or number, allowing for invocation based on the signature. This type of polymorphism is resolved during compile-time. Runtime polymorphism is achieved through method overriding, where a subclass provides a specific implementation of a method declared in its superclass. This ensures that the method call is resolved at runtime, based on the object's actual type. This flexibility allows for more dynamic and reusable code structures .

The 'final' keyword in Java is used to declare constants, prevent method overriding, and inheritance. When applied to a variable, it makes the variable's value immutable; for methods, it prevents overriding; for classes, it prevents inheritance. 'Finally' is a block used in conjunction with try-catch that executes code after a try block, ensuring resource deallocation or cleanup regardless of whether an exception occurred. 'Finalization' is a process linked to the garbage collection that allows an object to clean up resources before being collected, though it is often replaced by explicit resource management due to its unpredictable nature. Each serves distinct purposes but collectively ensures effective resource management and program correctness .

You might also like