Interview Questions and Answers - Order By Rating Q211. Can a class extend itself in Java ? Core Java
Ans. No Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts Q212. Why Concurrent Collection Classes are fail-fast in Java ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  concurrent collection classes   fail fast   fail-fast  collections  collection classes expert Q213. What is Lock interface in Java Concurrency API ? Core Java
Ans. Lock interface provide more extensive locking. They allow more flexible structuring and may support multiple associated Condition objects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  concurrency api Q214. What is context switching wrt Threads in Java? Core Java
Ans. Context Switching is the process of storing and restoring of CPU state so that Thread execution can be resumed from the same point at a later point of time. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Threads  multithreading  context switching Q215. What are the different ways to avoid multi Threading related problems in Java ? Core Java
Ans. Synchronization,
Concurrent classes,
Volatile keyword,
Implementing concurrent Lock interface,
Immutable classes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  multithreading  threads  ways to avoid thread related problems  synchronization  volatile  concurrent collections Intermediate Q216. How does multi threading improve performance ? Core Java
Ans. Every process in it's timeline require different resources. Utilization of resources can be optimized when they are shared among different processes or threads. When one thread is sleeping waiting for a peripheral to complete (e.g. a disk write, or a key press from the keyboard), other threads can continue using processor time and hence would lead to better usage of resources. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  multithreading  threads basic   frequent Q217. Create an event class in Java. Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  event class Q218. Which java version supports assertion ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q219. How will you enable or disable assertion for a package during runtime ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q220. Explain Transitive equals contract. Core Java
Ans. The equals contract is said to be transitive if
obj1.equals(obj2); and obj2(.equals(obj3)
then obj1.equals(obj3) also returns true. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Transitive equals contract   rare Q221. What is a reflexive equals contract ? Core Java
Ans. An equal contract is said to be reflexive is equality between 2 objects always returns to be true.
For example -
Object o1;
Object o2;
o1.equals(o2); // returns true
o2.equals(o1); //returns true Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  reflexive equals contract Q222. Which java feature is used to convert primitive type to reference type ? Core Java
Ans. AutoBoxing Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q223. Write code to create a folder if it doesn't exist. Core Java
Ans. File folder = new File(path);
if(!folder.exists()){
try {
folder.mkdir();
} catch (Exception e) {}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  code  coding  file handling basic Q224. Can Java be run on hardware with just the JVM and no OS ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q225. Why do we use getbytes in Java? Core Java
Ans. It is used to convert String into an array of bytes.
byte[] getBytes() - converts String into a byte array.
byte[] getBytes(Charset charset) - converts String to byte array, based on charset encoding. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q226. Have you ever used java.util.Objects class ? Core Java
Ans. Yes, We are using requireNonNull method for validating if the object is null. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  objects  util methods   rare Q227. How many VTables are there for each class ? Core Java
Ans. There is one VTable for each class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  virtual table method  vtable  runtime polymorphism  object oriented programming (oops)  oops concepts   method overriding intermediate   rare Q228. How is the virtual method table implemented in Java? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts expert   rare Q229. What is virtual table with respect to method overriding in Java ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  vtable  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts Q230. Are final methods faster than regular instance methods ? Core Java
Ans. Yes. As they cannot be overridden , there is no use of virtual table concept which is used for dynamic binding resolution. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final methods   final keyword expert Q231. What could be the reasons for restricting inheritance using final class ? Core Java
Ans. 1. Enforcing composition over inheritance
2. Restricting overriding of certain methods
3. Final methods are faster than regular instance methods
4. Enforcing Immutability Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final class   reasons for final class   restricting inheritance  object oriented programming (oops)  oops concepts expert Q232. Does use of Final class enforces composition over Inheritance in Java ? Core Java
Ans. Yes, to a certain extent. But the objective for Final class could be beyond just enforcing composition as certain classes might have been created without inheritance or composition in mind. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final class   composition  object oriented programming (oops)  oops concepts  inheritance  object oriented programming (oops)  oops concepts  composition  object oriented programming (oops)  oops concepts vs inheritance  object oriented programming (oops)  oops concepts expert Q233. Do we have references for the objects that are eligible for garbage collection ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q234. Which memory segment is cleaned by Garbage Collection - stack or heap ? Core Java
Ans. Heap as objects are stored ink heap. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  memory management   stack  heap  garbage collection This question was recently asked at 'Avis'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final class   final keyword Asked in 1 Companies basic Q236. What is the difference between scope and access modifiers ? Core Java
Ans. Scope modifiers changes the scope of a particular element or a method. For ex - static changes the scope of that of class and not of object.
Access modifiers changes the access priviledges of a particular element or a method. For ex - private , public etc. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  scope modifiers   access modifiers   scope vs access modifiers Asked in 2 Companies basic Q237. What are custom annotations and How can we create one ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  annotations  custom annotations basic Q238. Can we have interface as a replacement for utility class ? Core Java
Ans. Yes, With Java 8 we can use Interfaces as collection of utility methods through the use of default methods. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java 8  interfaces  utility class   utility classes Q239. How to sort objects based on one of the field ? Core Java
Ans. Using comparable and comparator and sorted collections like TreeSet or TreeMap.
or
use stream api from java 8 onwards which internally refers to comparable and comparator through lambda expressions Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sort  sorting  comprator  comparable  treeset  treemap  sorting collections Asked in 1 Companies Basic   frequent Ans. Generally used to indicate termination Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies