To crack a SDET interview , you are required to know one programming language thoroughly. In this post I will go through some common questions asked in SDET interview with respect to JAVA.
1.What is the difference between Abstract and Interface in Java?
Abstract class and interface both are used to achieve abstraction where we can declare the abstract methods. Abstract class and interface both can’t be instantiated.
In its most common form, an interface is a group of related methods with empty bodies.
Other common differences are:
|Default Method Implementation||It can have default method implementation||Interfaces provide pure abstraction & can not have implementation at all|
|Variables||It may contain non-final variables.||Variables declared in an interface are by default final|
|Keyword Used||An abstract class can be extended using the keyword “extends||The interface should be implemented using keyword ïmplements|
|Access Modifiers||Can have public, protected, private and default modifier||Interface methods are by default public. you can not use any other access modifier with it|
|Speed of Implementation||It is faster than the interface||An Interface is somewhat slower & require extra indirection|
|Normal Class||It can extend only one abstract class||Can implement multiple interfaces|
|Constructors||An abstract class can have constructors||An interface can not have constructors|
|Multiple Inheritance||An abstract class can extend another class and can implement multiple Java interfaces||The interface can extend another Java interface only|
2.What is the difference between Method overloading and Method Overriding?
Following are the key differences between method overloading and overriding in Java.
|Method Overloading||Method Overriding|
|It is used to increase the readability of the program||Provides a specific implementation of the method already in the parent class|
|It is performed within the same class||It involves multiple classes|
|Parameters must be different in case of overloading||Parameters must be same in case of overriding|
|Is an example of compile-time polymorphism||It is an example of runtime polymorphism|
|Return type can be different but you must change the parameters as well.||Return type must be same in overriding|
|Static methods can be overloaded||Overriding does not involve static methods.|
3. What is different methods in SET and LIST in Java?
|Set – Methods||List – Methods|
|add() – It is to add objects to a collection.||void add(int index, Object obj) – It adds the object ‘obj’ at the specified ‘index‘ of the invoking list and it makes sure that no element is overwritten by shifting the previous elements.|
|clear() – It is to remove objects from a collection.||boolean addAll(int index, Collection c) – It adds the entire collection ‘c’ to the invoking list and at the ‘index’ specified. It also ensures that no elements are overwritten. We can also check the correctness of its operation by examining the return value. It returns ‘true’ if the change is successful otherwise, it returns a value ‘false’.|
|contains() – It is to check whether the Set contains a certain object in it. It returns a value ‘true’ if the object is present in the Set.||Object get(int index) – It returns the element or object at the specified ‘index’.|
|isEmpty() – It is to determine whether the collection helps in as no elements in it. It returns a value ‘true’ if there is no element.||int lastIndexOf(Object obj) – It works similar to the reverse of the indexOf() Method. It returns the last occurrence of the specified Object ‘obj’ and a value ‘1’ is returned if there of no such object in the list. Therefore, it can also be used as contains() Method of the Set Interface.|
|remove() – It is to remove an element from a collection by specifying it as a parameter to the method.||ListIterator listIterator() – It returns an iterator to the starting index of the List.|
|size() – It is to count the number of objects or elements that a collection has.||ListIterator listIterator(int index) – It helps in iterating through the invoking List starting at the specified ‘index’.|
|NA||Object remove(int index) – It deletes the object at the specified ‘index’ and returns the deleted element as result. It also decrements the resultant list indices to reflect the deletion.|
|NA||Object set(int index, Object obj) – It is to assign the Object ‘obj’ to the invoking list at the specified ‘index’.|
|NA||List subList(int start, int end) – It is to include the objects from the index ‘start’ to the index ‘end’ in the list that has invoked the Method.|
4. What is the difference between String buffer and String Builder?
|Thread Safe||Not used in a threaded environment||Used in a multi-threaded environment||Used in a single-threaded environment|
|Performance||Slow||Slower than StringBuilder but faster than String||Faster than StringBuffer|
|Syntax||String var =“QATechTools”;|
String var=new String(“ QATechTools”);
|StringBuffer var = new StringBuffer(“QATechTools”);||StringBuilder var = new StringBuilder(“QATechTools”);|
5. What is the difference between HashTable and HashMap in java?
|Synchronization||Non-synchronized meaning that it is not thread-safe and cannot be shared between many threads without a proper synchronization code.||Synchronized and can be shared with many threads|
|Null keys||Allows only one null key and multiple null values||Does not allow null key or its value|
|Legacy System||This is a part of Java Collections||Hashtable is a legacy class was not part of the initial Java Collections|
|Iterator||Iterator is fail-fast and it throws a concurrentModificationException if any other thread tries to modify the map||The enumerator is not fail-fast|
|Inheriting class||Inherits AbstractMap class||Inherits Dictionary class|
6. What is the difference between Array and ArrayList?
|Must include System namespace to use array.||Must include System.Collections namespace to use ArraList.|
|Array Declaration & Initialization:||ArrayList Declaration & Initialization:|
|Array stores a fixed number of elements. The size of an Array must be specified at the time of initialization.||ArrayList grows automatically and you don’t need to specify the size.|
|Array is strongly typed. This means that an array can store only specific type of items\elements.||ArrayList can store any type of items\elements.|
|No need to cast elements of an array while retrieving because it is strongly typed and stores a specific type of items only.||The items of ArrayList need to be cast to an appropriate data type while retrieving. So, boxing and unboxing happens.|
|Performs faster than ArrayList because it is strongly typed.||Performs slows because of boxing and unboxing.|
|Use static helper class Array to perform different tasks on the array.||ArrayList itself includes various utility methods for various tasks.|
7. What is the difference between Static and Final ?
|Applicable||Static keyword is applicable to nested static class, variables, methods and block.||Final keyword is applicable to class, methods and variables.|
|Initialization||It is not compulsory to initialize the static variable at the time of its declaration.||It is compulsory to initialize the final variable at the time of its declaration.|
|Modification||The static variable can be reinitialized.||The final variable can not be reinitialized.|
|Methods||Static methods can only access the static members of the class, and can only be called by other static methods.||Final methods can not be inherited.|
|Class||Static class’s object can not be created, and it only contains static members only.||A final class can not be inherited by any class.|
|Block||Static block is used to initialize the static variables.||Final keyword supports no such block.|
8. What is the difference between Extends and Implements?
|Implementation||A class can inherit another class, or an interface can inherit other interfaces using a keyword extends||A class can implement an interface using keyword implements|
|Method||The subclass that extends a superclass may or may not override all the methods in a superclass||The class implementing an interface has to implement all the methods of that interface.|
|Class||A class can extend only one superclass.||A class can implement any number of an interface at the same time|
|Interface||An interface can extend any number of interfaces||An interface can never implement any other interface|