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. 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
Q1119. 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
Q1122. How can we get count of all keys within Redis ?
Ans. It's a configuration for auto scaling environment that specify the attributes / conditions for scaling instances up and down. For example - We may like environment to scale up when the number of requests / sec increases a particular threshold and scale down when it decreases below a threshold.
Help us improve. Please let us know the company, where you were asked this question :
Ans. A shard is a uniquely identified group of data records in a stream or we can say that Shard is a partition in Kinesis stream. A shard supports a fixed bandwidth i.e fixed number of messages per second. The total capacity of the stream is the sum of the capacities of its shards. If the data rate changes, we can allocate / deallocate more shards to accommodate that.
Help us improve. Please let us know the company, where you were asked this question :
Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features
1. Inheritance for Code Reuse
2. Abstraction for modularity, maintenance and agility
3. Encapsulation for security and protection
4. Polymorphism for flexibility and interfacing
Help us improve. Please let us know the company, where you were asked this question :
Ans. The operator instanceOf is used to verify if the specified object is the instance of specified class or interface.
Syntax if(x instanceOf ABC)
where x is an object reference and ABC could be a class name or interface name. The above statement will be true if x holds an object that is an instance of ABC or any of the child class of ABC or if x holds an object that implements ABC.
instanceOf operator is used to verify in case of downcasting. For ex -
DerivedClass extends BaseClass
x is the reference of BaseClass but holds DerivedClass object ( Polymorphism )
There is an operation that is defined in Derived Class, let's say derivedClassMethod()
We cannot call derivedClassMethod() directly using x as x is reference of BaseClass and not DerivedClass and hence can only access methods that are defined in BaseClass and overridden in derived class.
Though we can cast it to DerivedClass as following
((DerivedClass)x).derivedClassMethod();
But it may throw ClassCastException in case x doesn't hold an instance of DerivedClass at that point.
So before casting it to DerivedClass we may like to make sure that it is an instance of DerivedClass and hence won't throw ClassCastException.
Ans. Encapsulation is a feature of OOP's that binds the data and it's associated methods together as a single unit and facilitate protection and data hiding by providing minimal interface to outside. For example - member variables are declared private and are accessed through public methods. Moreover we have private methods that can only be used internally and hence providing minimal interface to outside class through use of public methods.
Ans. We can copy the elements to a Set and then find the difference of count between ArrayList and Set. As Set don't allow duplicates , they will be removed in the set.
Help us improve. Please let us know the company, where you were asked this question :
Ans. ArrayLists aren't synchronized and hence doesn't allow synchronized access. As multiple threads can access an arraylist in parallel, it may result in an inconsistent state.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It means that only 1 thread can access have access to Vector at a time and no parallel access is allowed whereas Array List allows parallel access by multiple threads.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Java Programs are collection of objects that communicates with each other to get a task accomplished. To add to those objects, there are common spaces ( static i.e common for objects belonging to a class ) that are used too.
We can visualize objects as departments of an organization in real world. Just like Task gets initiated in one department and then files are moved across different departments to get work done. In a similar fashion, a task is initiated in one object ( having main method ) and then information ( through POJOs / DTOs ) is moved across objects to accomplish a task.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  objects  Java Programs are collection of objects  real life example of object communication
Ans. By encapsulating it within another class and declaring it private. In such a case, it will only be accessible through parent class or parent class object.
Help us improve. Please let us know the company, where you were asked this question :