More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. But Collections.emptyList() returns an Immutable list whereas new arraylist() creates a mutable list.
Advantage of getting an empty list using Collections.emptyList is that it returns a singleton list which can be shared among many references and hence made immutable. This is good fit for situations where we would like to initialize a list to basic minimum empty to avoid null pointer exception.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The prototype pattern is a creational design pattern. It is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. Prototype is used when we need duplicate copies of objects.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Synchronize is used to achieve mutual exclusion i.e at one time, the segment of the code, method that has been declared synchronized should be executed by single thread only and hence the lock needs to be retrieved before executing the segment and then released.
Help us improve. Please let us know the company, where you were asked this question :
Ans. This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive.
Help us improve. Please let us know the company, where you were asked this question :
Ans. That depends if the interface for the resource in Project B gets changed. If only the internal implementation is changed, No change is required in Project A. Project A is not even required to be rebuilt.
Help us improve. Please let us know the company, where you were asked this question :
Ans. A dirty read occurs when a transaction is allowed to read data from a row that has been modified by another running transaction but not yet committed.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, When either we don't want an object to be created ( class having all static elements and hence not required ) or object to be created using a static method or static block.
One such example could be a situation when we would like app to load objects at start up and we would like to restrict new object creation by any request.
Help us improve. Please let us know the company, where you were asked this question :
Ans. I use trace for debugging purpose. Info for displaying some important info, thought its rare as we have enabled info logging in production. Warn in case something went wrong but we still resume the flow in spite of it or have take alternate flow as its expected sometimes. Error logging in case it was completely unexpected and mostly when it breaks the flow.
Help us improve. Please let us know the company, where you were asked this question :
Ans. When executing tests it is common that multiple tests need similar objects to be created before they can run. @before specifies a method that provide that initialization for the set of Unit Tests.
Help us improve. Please let us know the company, where you were asked this question :
Ans. NumberFormatException is the exception that Java throws when we try to convert one data type to the Number data type but the value is not parsable to be a Number.
For example , the following code will result in the NumberFormatException
String string = "Buggy";
int strtoInt = Integer.parseInt(string);
Help us improve. Please let us know the company, where you were asked this question :
Ans. Though there are many differences the way internally they both iterates the collections and streams respectively, but the main difference in performance that is achieved by spliterator as it can iterate Streams in Parallel whereas iterator only iterates collections sequentially.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Spliterator has better performance potential than iterators but only if the potential is used. Spliterator can iterate streams in parallel as well as in sequence whereas iterator can only iterate in sequence.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Such return is only expected in methods that returns void. the purpose of having return in such a method is to return the flow out of method and return to the place where it was called. Its actually used to prematurely return the control from the method.
Help us improve. Please let us know the company, where you were asked this question :