When should I use abstract classes and when should I use interfaces?
Correct Answer
Use Interfaces when? - You see that something in your design will change frequently - If various implementations only share method signatures then it is better to use Interfaces - You need some classes to use some methods which you don't want to be included in the class, then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface Use Abstract Class when? - If various implementations are of the same kind and use common behavior or status then abstract class is better to use - When you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass - Abstract classes are an excellent way to create planned inheritance hierarchies They're also a good choice for nonleaf classes in class hierarchies
Correct Answer: Overriding means changing behavior of methods of base class in derive class by overriding the base class methods If class A is a base class with method ?calculate? and class B inherits class A, thus derives method ?calculate? of class A The behavior of ?calculate? in class B can be changed by overriding it
Correct Answer: :: is the scope resolution operator When local variable and global variable are having same name, local variable gets the priority C++ allows flexibility of accessing both the variables through a scope resolution operator
Correct Answer: A JAR file (short for Java Archive) is a ZIP file used to distribute a set of Java classes It is used to store compiled Java classes and associated metadata that can constitute a program
5. In RDBMS, what is the efficient data structure used in the internal storage representation?
B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds to the records that shall be stored in leaf nodes
6. How do you traverse through a collection using its Iterator?
Correct Answer: To use an iterator to traverse through the contents of a collection, follow these steps: - Obtain an iterator to the start of the collection by calling the collections iterator() method - Set up a loop that makes a call to hasNext() Have the loop iterate as long as hasNext() returns true - Within the loop, obtain each element by calling next()
7. How do you decide when to use ArrayList and When to use LinkedList?
Correct Answer: If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList offers the optimal collection If, however, you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList offers the better implementation
Correct Answer: - The Set interface provides methods for accessing the elements of a finite mathematical set - Sets do not allow duplicate elements - Contains no methods other than those inherited from Collection - It adds the restriction that duplicate elements are prohibited - Two Set objects are equal if they contain the same elements
Correct Answer: SimpleTimeZone is a concrete subclass of TimeZone class The TimeZone class represents a time zone, that is to be used with Gregorian calendar The SimpleTimeZone is created by using the base time zone offset from GMT time zone ID and rules, for starting and ending the time of daylight
Correct Answer: Java applications can call code written in C, C++, or assembler This is sometimes done for performance and sometimes to access the underlying host operating system or GUI API using the JNI The steps for doing that are: First write the Java code and compile it Then create a C header file Create C stubs file Write the C code Create shared code library (or DLL) Run application