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. An interface without any method declaration is called as marker interface. there are 3 in-built interfaces in JVM i.e. serializable, clonable, remote
Help us improve. Please let us know the company, where you were asked this question :
Ans. Factory Pattern deals with creation of objects delegated to a separate factory class whereas Abstract Factory patterns works around a super-factory which creates other factories.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Factory is a creational design pattern whereas Strategy is behavioral design pattern. Factory revolves around the creation of object at runtime whereas Strategy or Policy revolves around the decision at runtime.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Arrays are of fixed size and have to reserve memory prior to use. Hence if we don't know size in advance arrays are not recommended to use.
Arrays can store only homogeneous elements.
Arrays store its values in contentious memory location. Not suitable if the content is too large and needs to be distributed in memory.
There is no underlying data structure for arrays and no ready made method support for arrays, for every requriment we need to code explicitly
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  java   arrays   disadvantages of arrays   arrays memory   arrays vs variables
Q52. Will the static block be executed in the following code ? Why ?
class Test { static { System.out.println("Why I am not executing "); } public static final int param=20; }
public class Demo { public static void main(String[] args) { System.out.println(Test.param); } }
Ans. No the static block won't get executed as the referenced variable in the Test class is final. Compiler replaces the content of the final variable within Demo.main method and hence actually no reference to Test class is made.
Help us improve. Please let us know the company, where you were asked this question :
public static void main(String[] args){
System.out.println("Main Method");
new BuggyBread();
}
}
Instance Initialization Block
Constructor
Static Block
Main Method
Static Block
Instance Initialization Block
Constructor
Main Method
Main Method
Static Block
Instance Initialization Block
Constructor
Static Block
Main Method
Instance Initialization Block
Constructor
Q53. If you are given a choice to implement the code to either Insert a Record or Update if already exist, Which approach will you follow ?
1. Insert into the DB Table. If exception occurs, update the existing record. 2. Check if the record exists and update it if it exists, If not insert a new record.
Ans. In first case, there would be 2 DB calls in worst case and 1 in best case. In 2nd approach there will be always 2 DB calls.
Decision on the approach should depend on the following considerations -
1. How costly is the call to DB ? Are we using indices , hibernate etc
If calls to DB are costly , 1st approach should be the choice.
2. Exception Book keeping load upon exception.
The benefit of saving 1st call in approach 1 should be bigger than the Book keeping for the exception.
3. Probability of the exception in first apparoach.
If the DB Table is almost empty, it makes sense to follow Approach 1 as majority of the 1st calls will pass through without exception.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  database   insert-update   db exceution plan   db strategy   design   architecture   technical lead
Q54. What is the use of @GeneratedValue annotation in Hibernate?
Ans. This annotation is added to the auto increment column with the strategy to increment the column value. Usually this is added to the surrogate primary key column and specified with the Database Sequence.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It's a choice to be made whether to use first approach ( Thread class ) or second approach ( runnable interface ) by the programmer. The second facility has been given for cases where your class is already extending some parent class and hence cannot extend another class ( for Thread ) as Java doesn't allow multiple inheritance.
Help us improve. Please let us know the company, where you were asked this question :
Ans. 1. Method local variables - These are declared and defined within a method ( instance or static methods ) and their scope is limited to the method itself. They are destructed once the execution of method completes. They are stored in stack memory.
2. Instance variables - These are declared as non static variables as part of the class.They are initialized as part of object creation ( constructor ) and are destructed by java's garbage collection mechanism and hence stored in heap.
3. Static variables - These are declared with the static keyword and are part of the class. They are initialized at the time of class loading and are destructed by java's garbage collection mechanism and hence stored in heap.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Such a class still can have member elements which can be inherited and hence facilitate code reuse. Moreover Abstract class can have non final static elements whereas interfaces are only allowed to have static final elements.
Help us improve. Please let us know the company, where you were asked this question :
Ans. final keyword have meaning only to referenced and not the value. It means that the specified reference cannot be dereferenced. It doesn't control the value assigned to the memory that's being referenced. This is the reason that final object references doesn't mean that the object is immutable but means that the reference cannot be changed to point to new object.
In case of primitive types too, when we assign a reference to another, values are passed and not the object reference, and hence a new placeholder is created in memory with the same value. That is why final to that context means that you cannot change the assigned memory and there is no way we can have that memory place have another value.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Only declaring variables as final makes them immutable. Making objects final means that the object handler cannot be used to target some other object but the object is still mutable.
Help us improve. Please let us know the company, where you were asked this question :
Ans. member variable are loaded into heap, so they are initialized with default values when an instance of a class is created. In case of local variables, they are stored in stack until they are being used.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Stands for Java API for XML Processing. This provides a common interface for creating and using SAX, DOM, and XSLT APIs in Java regardless of which vendor’s implementation is actually being used.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  java   java api   xml   xml processing   jaxp   abbreviation   technologies
Ans. Stands for Java API for XML Binding. This standard defines a mechanism for writing out Java objects as XML and for creating Java objects from XML structures.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Comparable interface is used for single sequence sorting i.e.sorting the objects based on single data member where as comparator interface is used to sort the object based on multiple data members.
Help us improve. Please let us know the company, where you were asked this question :