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. 1. In Setter Injection, partial injection of dependencies can possible, means if we have 3 dependencies like int, string, long, then its not necessary to inject all values if we use setter injection. If you are not inject it will takes default values for those primitives1. In constructor injection, partial injection of dependencies cannot possible, because for calling constructor we must pass all the arguments right, if not so we may get error
2. Setter Injection will overrides the constructor injection value, provided if we write setter and constructor injection for the same property [i already told regarding this, hope you remember ] But, constructor injection cannot overrides the setter injected values
3. If we have more dependencies for example 15 to 20 are there in our bean class then, in this case setter injection is not recommended as we need to write almost 20 setters right, bean length will increase. In this case, Constructor injection is highly recommended, as we can inject all the dependencies with in 3 to 4 lines [i mean, by calling one constructor]
4. Setter injection makes bean class object as mutable [We can change ] .Constructor injection makes bean class object as immutable [We cannot change ]
Help us improve. Please let us know the company, where you were asked this question :
Ans. String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment or hacker over internet.
Once a String constant is created in Java , it stays in string constant pool until garbage collected and hence stays there much longer than what's needed. Any unauthorized access to string Pool pose a threat of exposing these values.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It makes application little heavy as we are importing classes that aren't required.
It creates class name conflicts as similar name classes might be available across different packages. In case of such conflicts, we will have to specify the package name with the class name at the time of it's usage.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It means import all the classes and interfaces within java.util package and make them available to use within the current class or interface. This is shorthand wild card annotation for importing all classes within a particular package. This won't import the classes within the sub packages of java.util.
Help us improve. Please let us know the company, where you were asked this question :
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 :
Ans. Ternary operator , also called conditional operator is used to decide which value to assign to a variable based on a Boolean value evaluation. It is used as
condition ? value1 : value2
For example
int y = (x > 0) ? x:0; // assign x if it's greater than 0, else assign 0
Help us improve. Please let us know the company, where you were asked this question :
Ans. Infinite loop is a programming condition wherein the control goes into an infinite loop because the loop termination condition can never be met. For example -
for(int x=1;x>0;x++){
}
in this loop, with each increment the condition x > 0 will remain true till infinity.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Inner Class is a class that is nested within another class whereas sub class is a class that extends or inherit another class.
Inner class can only be accessed using reference of outer class ( Class name , if inner class is static or object reference, if inner class is non static ) whereas Sub class is accessed directly.
In terms of memory, inner class is stored just like another class having it's own body whereas sub class carries the body of parent class as well as it's own fields in memory.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  inner classes  nested classes  inner class vs sub class  nested class vs sub class Basic
Q1318. Give an example of how Object Oriented Programming Concepts can be implemented.
Ans. You can implement encapsulation in Java by keeping the fields (class variables) private and providing public getter and setter methods to each of them. Java Beans are examples of fully encapsulated classes. Encapsulation in Java: Restricts direct access to data members (fields) of a class.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Manual scaling is the process of scaling instances up and down in a an enviornment manually by observing the scaling trigger whereas Auto scaling is the process wherein a Trigger condition specified as a scaling trigger will trigger scaling up and down of instances.
for example - If an organization has a policy of scaling up if requests / sec / instance exceeds 10000, Operations team will have to manually monitor the metric and they can request scaling up and down as the need arise. Manual scaling offers flexibility as team can scale on the basis of combination of factors and can take decision on flyby requires continuous monitoring.
The same trigger can be fed as triggering policy to the environment and can be taken care by the system. This requires availability of such triggering policy within the environment configuration but as it's automatically handled, requires no supervision.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  Scaling  manual scaling   auto scaling   manual vs auto scaling  production support
Q1320. How can we get count of all keys within Redis ?