Search Interview Questions | 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. |
|
| |||||||||||
Interview Questions and Answers - Order By Newest | |||||||||||
| |||||||||||
Ans. Exception wrapping is wrapping an exception object within another exception object and then throwing the outer exception. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  exception handling  exception wrapping  exceptions intermediate   rare | |||||||||||
| |||||||||||
Ans. The error states that Hibernate is not able to initialize proxy / dependent entity objects as there is no session or transaction present. Very likely we are trying to load the dependent entities lazily but the call to dependent object property is not wrapped within the session or transaction. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Lazy Loading  Lazy Initialization  org.hibernate.LazyInitializationException | |||||||||||
| |||||||||||
Ans. First resolution is a big No as it conveys no lazy loading in complete app. even second is advocating the same but for a particular mapping. third one is most appropriate if loading and dependent entity property access is closer to each other in code and can be accomplished. I don't mind using 4th too. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  lazy loading  lazy initialization  LazyInitializationException | |||||||||||
| |||||||||||
Ans. No. It's a resource and performance overhead. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  LazyInitializationException  Lazy Loading | |||||||||||
| |||||||||||
Ans. We can declare the reference as final to avoid reassignment but again we can always initialize the final reference to null. Even if there was any such facility available , it would have meant poor use of resources by assigning a new object in memory to each reference that's created. Many a times references are just meant to refer to other objects which already have a reference i.e sharing object by multiple references. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  null  NullPointerException | |||||||||||
| |||||||||||
Ans. Application is unable to insert a record as it violates a unique constraint. The exception states the constraint and Table can be located by the Entity mapping. So I will go to the DB and will first check to which all columns the unique constraint applies. And then I will go and check the code and logs to see how come the duplicate column values were attempted to be inserted when they were not supposed to be. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  ConstraintViolationException  SQLIntegrityConstraintViolationException | |||||||||||
| |||||||||||
Ans. The exception is thrown when a database constraint is violated. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  ConstraintViolationException | |||||||||||
| |||||||||||
Ans. This looks like the case for optimistic locking wherein hibernate suspects that the information in table was updated by some other transaction after the entity was loaded by current transaction. One way is to have synchronized entity state and don't detach the entity. Other could be to merge the entity with the table record rather than just directly persisting the entity. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  StaleObjectStateException  Optimistic locking | |||||||||||
| |||||||||||
Ans. It would result in endless function calls and hence eventually would result in stackoverflow exception. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  recursion  stackoverflowexception Basic   frequent | |||||||||||
| |||||||||||
Ans. Yes we can try { // code } catch (Error ex) { // handling code } but we shouldn't ideally do that as errors are mostly JVM based and not application based and there is rarely we can do something about it. Very likely catching and not re throwing would lead to muting their response or trace. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  exception handling  error handling  errors Asked in 1 Companies intermediate | |||||||||||
| |||||||||||
Ans. Sometimes the calls move across layers of classes and functions and hence each layer needs to perform some function like cleaning if something goes wrong deep inside. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  exceptions  exceptions handling  rethrowing exception | |||||||||||
| |||||||||||
Ans. never initialise local to null,yes it is bad pratice | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  null  nullpointerexception | |||||||||||
| |||||||||||
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  ArithmeticException | |||||||||||
| |||||||||||
Ans. The regular behavior of exception handling will occur. It will look for any immediate catch handler and if none is provided, it would be transmitted to the callers until a catch handler is found or it's out of main function. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  exceptions  finally | |||||||||||
| |||||||||||
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  exception handling | |||||||||||
| |||||||||||
Ans. It's an exception that is thrown when we attempt to add value of an incompatible type to an array. For example - Object[] strArray = new String[2]; strArray[0] = 5; In this code, strArray reference of type Object has currently been assigned the String array but at line 2 we are trying to add an integer value. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays   ArrayStoreException | |||||||||||
| |||||||||||
Ans. No. But It will throw ArrayStoreException at runtime. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  ArrayStoreException  arrays | |||||||||||
| |||||||||||
Ans. ExceptionHandler is Used to handle at Method level | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  @ExceptionHandler | |||||||||||
| |||||||||||
Ans. If we do not mention, Cloneable Interface to the Class which we want to Clone then we get this exception, only if we try to clone an object Like: public class TestClone{ @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } } In Main, You try to do: TestClone clone = new TestClone(); TestClone clone2 = (TestClone) clone.clone(); You will get CloneNotSupportedException. Just add -> public class TestClone implements Cloneable { and things are fixed. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  exceptions handling  cloning | |||||||||||
| |||||||||||
Ans. Returning from inside a finally block will cause exceptions to be lost. A return statement inside a finally block will cause any exception that might be thrown in the try block to be discarded. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  exception handling  finally block Asked in 1 Companies | |||||||||||
| |||||||||||
Ans. Throwable in java is a class that is the superclass of all exceptions and errors which may occurs in java program.It extends obcect class. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  exception handling   throwable Asked in 1 Companies basic | |||||||||||
| |||||||||||
Ans. Yes, We can pass the test even if the tested method throws an exception. One way is know as exception testing in which the tested method is expected to throw exception and hence the expectation is set accordingly. @Test(expected = IndexOutOfBoundsException.class) public void test(){} Other way is to just ignore if the tested code throws an exception. In that case , we can enclose the tested method call in the try block and within exception block, we just return gracefully. Exception testing is perfectly ok to be done as we would like test code in case an exception occurs and if the code is handling the exception properly. Ignoring the exception by putting the tested method call within try block isn't something normal and should be avoided. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Junit exception testing | |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||