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. This collections class has been implemented in such a manner that it can never throw ConcurrentModificationException. As it performs update and write operations by creating a new copy of ArrayList, It's slower compared to ArrayList. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   list   arraylist   copyonwritearraylist   advantages-disadvantages   ConcurrentModificationException Asked in 4 Companies Expert | ||||
| ||||
Ans. Exception thrown by the application is we try to access an element using an index which is not within the range of array i.e lower than 0 or greater than the size of the array. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   exceptions   arrayindexoutofboundexception Asked in 1 Companies | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/java-list-of-error-exception-classes.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   exceptions   error | ||||
| ||||
Ans. To avoid ClassCastException. Though the following code will compile fine but will result in ClassCastException during runtime. Fruit fruit = new Apple(); Banana banana = Banana(fruit); // ClassCastException This code will not give compile time error as Banana and Fruit are related as Banana either extends or implement Fruit, So downcasting is acceptable. With this code we assume that the Fruit handler will have the Apple object at that point, violating which the code will throw the exception. This exception can be avoided by following code. Fruit fruit = new Apple(); if(fruit instanceOf Banana){ Banana banana = Banana(fruit); // ClassCastException } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   instanceof   classcastexception   runtime exceptions  instanceOf operator | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. OutOfMemoryError in Java is a subclass of VirtualMachineError and is thrown by JVM when it runs out of heap memory. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  outofmemoryerror   error   exceptions   jvm   java   heap memory   heap | ||||
| ||||
Ans. [Iterable] | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   BatchUpdateException   include | ||||
Ans. try block without catch or finally block | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exceptions   java   try-catch   finally | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. IllegalStateException | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   exception   threads | ||||
| ||||
Ans. Fail Safe systems are tolerant systems that continue processing even if they sense any problem. the objective here is to continue with the processing even if there are some problems instead of completely shutting it down. Example could be to catch an exception and still letting it complete with partial results. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  fail safe systems   system design   exception handling Asked in 3 Companies | ||||
| ||||
Ans. <a href="http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/" rel="nofollow">http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/</a> | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception hierarchy   exceptions Asked in 3 Companies | ||||
| ||||
Ans. Yes, with finally. Yes, finally block will be executed even if there is no exception in try block. If finally throws an exception, the exception gets thrown to the calling module. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling Asked in 1 Companies intermediate | ||||
| ||||
Ans. As with all other objects its garbage collected after its usage unless its rethrown. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exceptions  exception handling   rare | ||||
| ||||
Ans. http://stackoverflow.com/a/6548203/2789764 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling  exception expert   rare | ||||
| ||||
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 : | ||||
Like Discuss Correct / Improve  exceptions  NumberFormatException | ||||
| ||||
Ans. An Error indicates serious problems that a reasonable application should not try to catch whereas An Exception indicates conditions that a reasonable application might want to catch. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  error  exception handling  exceptions Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. In first case the whole loop will terminate as soon as any exception happens in the method calculate ( assuming calculate method is not handling its exception and those are thrown back at the calling method ) In Second case exception will be caught for individual iteration and hence it wont break the loop and will continue for the next iteration. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling  try catch Asked in 1 Companies | ||||
| ||||
Ans. An Exception in java is the occurrence during computation that is anomalous and is not expected. Exception handling is the mechanism which is used to handle such situations. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling Asked in 18 Companies basic   frequent | ||||
| ||||
Ans. 1. Wrap the desired code in try block followed by a catch / finally to catch the exception 2. Declare the throws clause with exceptions that the code is expected to throw as an indication to the calling method to take care of it. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling Asked in 4 Companies | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Store Procedure returns the error code. Moreover we can put the call withing try block and catch SQL Exception. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  stored procedure  exception handling | ||||
| ||||
Ans. No, It should be followed by either catch or finally. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  try  exception handling | ||||
| ||||
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 | ||||