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. Primary Key constraint means that the column(s) should be unique and doesn't allow null. So Primary key constraint implies unique and not null constraint too.
Unique constraint implies not null constraint too as allowing null would violate uniqueness on those columns.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Unique constraint ensures that a columns or combination or columns are always unique in a table and hence doesn't allow null or duplicates to be entered for the column or combination of columns.
Help us improve. Please let us know the company, where you were asked this question :
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 :
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 :
Ans. Null means nothing and hence means it's being assigned something till anything can be assigned to the reference. Null is a common memory location that get's assigned to any object reference till an actual object is assigned.
Empty object may not have a programmer initialized state but still a separate object in memory that has been assigned the placeholders.
Help us improve. Please let us know the company, where you were asked this question :
Ans. whenever a reference is created in Java without assigning the object
like
String str;
It get's assigned to null. So null provides a temporary memory location which any reference can point to till an appropriate object is assigned. Moreover it denotes that nothing has been assigned yet and hence provides a check in many cases.
Help us improve. Please let us know the company, where you were asked this question :
Ans. I like to keep the names in Capital Camel case. Moreover I prefer to keep the names for classes, enums and interfaces such that they are easily distinguishable just by the pattern of their names.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Though it's useful but it's not as useful as overriding member or object methods. We cannot achieve polymorphic behavior with static methods by overriding their definition in derived class.
Help us improve. Please let us know the company, where you were asked this question :
We need methods to access variables in a polymorphic way as overriding only happens with methods and not with variables. Moreover getter provides a way to minimally open the access window for the object and hence provides better encapsulation. To add to those, we can have validation in the getter method before returning elements.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Classes having only static methods in java is called util classes. As they don't have specific object state, they are basically intend to have shared code and state through static elements and methods. They save resources by sharing code.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Likewise classes, methods also provide a way for code reuse and abstraction. Code is reused, clean and easy to understand if classified properly within classes and methods.
Help us improve. Please let us know the company, where you were asked this question :
Ans. I would avoid that. If we need to initialize member elements differently on the basis of some condition, I would prefer having overloaded constructors. I don't see a need to have a loop for initializing member elements unless the count of elements is huge and they all need to be initialized with common value.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Constructor's objective is to initialize member elements. If we don't deviate from that and don't have methods with logic in them, I don't see an issue with constructor's calling other methods assuming the methods are doing nothing but initialization. There are situations wherein we classify the member elements based on their type and hence having different initialization methods for different element types will give a better abstracted way to initialize them.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Java provides a default constructor ( no argument ) if no constructor is provided by the programmer. Java makes a check during pre compilation if there is any constructor provided by the programmer. If any constructor is provided, Java understands that programmer has provided all the mechanism for initialization and construction of the object and may not even intend to create objects by calling a no argument constructor. For example - One may like to have objects created with self defined state otherwise restrict its creation.
We make the constructor private if we want to make a class singleton as we would like to restrict creation of new objects using new operator and default constructor. Similar could be the situation wherein we would like to construct objects in a particular manner only.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Include directive includes the file at translation time (the phase of JSP life cycle where the JSP gets converted into the equivalent servlet) whereas the include action includes the file at runtime.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It doesn't matter how you define that method in implementing class. there will be only one definition provided and that method can be accessed using reference of either of the interfaces.
Help us improve. Please let us know the company, where you were asked this question :