Dynamic method dispatch which is also known as runtime polymorphism is a process in which a call to an overridden method is resolved at runtime rather than at compile-time In this process, an overridden method is called through the reference variable of a superclass The determination of the method to be called is based on the object being referred to by the reference variable
Technology problems
Search Results
1. What is the similarity between Dynamic Binding and linking?
Correct Answer: Dynamic binding is orthogonal to dynamic linking Binding refers to the linking of a procedure call to the code to be executed in response to the call Dynamic binding It is associated with polymorphism and inheritance, it(also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time
Correct Answer: Cloning refers to creating duplicate copies of objects in java Shallow Cloning: Shallow cloning is a bitwise copy of an object New object is created which is an exact copy that of the original one In case any objects are referring the fields of these objects, just the references are copied Deep Cloning: In deep cloning, complete duplicate copy of the original copy is created Deep cloning creates not only the primitive values of the original objects but also copies all its sub objects as well Clonable interface is used to perform cloning in java
Correct Answer: Dealing with primitives as objects is easier at times Most of the objects collection store objects and not primitive types Many utility methods are provided by wrapper classes To get these advantages we need to use wrapper classes As they are objects, they can be stored in any of the collection and pass this collection as parameters to the methods Features of the Java wrapper Classes: - Wrapper classes convert numeric strings into numeric values - The way to store primitive data in an object - The valueOf() method is available in all wrapper classes except Character - All wrapper classes have typeValue() method This method returns the value of the object as its primitive type
4. How does thread synchronization occurs inside a monitor?
Correct Answer: A Monitor defines a lock and condition variables for managing concurrent access to shared data The monitor uses the lock to ensure that only a single thread inactive in the monitor code at any time A monitor allows only one thread to lock an object at once
Correct Answer: Autoboxing is the process of converting a primitive type data into its corresponding wrapper class object instance Example: Integer number = new Integer (100); // number is now refers to the object 100 Unboxing is the process of converting a wrapper instance into a primitive type Example: Integer number = new Integer (100); int num = number;// without type casting number would be changed into int type
Correct Answer: When an object is passed by value, this means that a copy of the object is passed Thus, even if changes are made to that object, it doesn?t affect the original value When an object is passed by reference, this means that the actual object is not passed, rather a reference of the object is passed Thus, any changes made by the external method, are also reflected in all places
7. Explain different ways of creating a thread. Which one would you prefer and why ?
Correct Answer: There are three ways that can be used in order for a Thread to be created: A class may extend the Thread class A class may implement the Runnable interface An application can use the Executor framework, in order to create a thread pool The Runnable interface is preferred, as it does not require an object to inherit the Thread class In case your application design requires multiple inheritance, only interfaces can help you Also, the thread pool is very efficient and can be implemented and used very easily
8. What is the difference between processes and threads ?
Correct Answer: - A process is an execution of a program, while a Thread is a single execution sequence within a process - A process can contain multiple threads A Thread is sometimes called a lightweight process
9. What are the basic interfaces of Java Collections Framework ?
Correct Answer: Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collections of objects The most basic interfaces that reside in the Java Collections Framework are: Collection, which represents a group of objects known as its elements Set, which is a collection that cannot contain duplicate elements List, which is an ordered collection and can contain duplicate elements Map, which is an object that maps keys to values and cannot contain duplicate keys
10. What do you know about the big-O notation and can you give some examples with respect to different data structures ?
Correct Answer: The Big-O notation simply describes how well an algorithm scales or performs in the worst case scenario as the number of elements in a data structure increases The Big-O notation can also be used to describe other behavior such as memory consumption Since the collection classes are actually data structures, we usually use the Big-O notation to chose the best implementation to use, based on time, memory and performance Big-O notation can give a good indication about performance for large amounts of data