General Flashcards
Object Oriented Programming (OOP)
OOP language follow 4 principles: o Encapsulation : We can hide direct access to data by using private key and we can access private data by using getter and setter method.
Abstraction : It is a process of hiding implementation details and showing only functionality to the user. Abstraction lets you focus on what the object does instead of how it does it. o Inheritance : It is used to define the relationship between two classes. When a child class acquires all properties and behaviors of parent class known as inheritance. Child class can reuse all the codes written in parent class. It provides the code reusability. o
Polymorphism : It is an ability of object to behave in multiple form. The most common use of polymorphism is Java, when a parent class reference type of variable is used to refer to a child class object. § E.g.: WebDriver driver = new ChromeDriver(); We use method overloading and overriding to achieve Polymorphism.
What is immutable?
Immutable means that once the constructor for an object has completed execution that instance can’t be altered.
This is useful as it means you can pass references to the object around, without worrying that someone else is going to change its contents. Especially when dealing with concurrency, there are no locking issues with objects that never change.
What is Polymorphism?
Polymorphism is a very important concept in OOP because; o it enables to change the behavior of the applications in the run time based on the object on which the invocation happens. o by Polymorphism; one object can have different forms Two types à Compile Time which is Static and Run Time Polymorphism which is related with child and parent class.
What is Access modifier and what are the different access modifiers? Difference between them
Java provides a number of access modifiers to set access levels for classes, variables, methods, and constructors.
o Visible to the package, the default. No modifiers are needed.
o Visible to the class only (private).
o Visible to the world (public).
o Visible to the package and all subclasses (protected).
Difference between a Constructor and a Method?
Constructor doesn’t have a return type and constructor’s name must be same as the class name. o Constructor is called automatically when a new object is created. Constructor is invoked implicitly. o The Java compiler provides a default constructor if we don’t have any constructor. o Constructors are not inherited by child classes * Method have a return and the method’s name may or not be same as the class name o Method is invoked explicitly. o Method is not provided by compiler in any case. o Methods are inherited by child classes.
Difference between method Overloading and method Overriding?
First and most important difference between overloading and overriding is that, o in case of overloading , method name must be the same, but the parameters must be different; o in case of overriding , method name and parameters must be same Second major difference between method overloading and overriding is that; o We can overload method in the same class but method overriding occurs in two classes that have inheritance relationship. We cannot override static, final and private method in Java, but we can overload static, final and private method in Java. In method overloading , return type can be same or different. In method overriding , return type must be same or covariant type.
Difference between Set, List and Map in Java?
Set, List and Map are 3 important interface of Java collection framework. o List provides ordered and indexed collection which may contain duplication . o Set provides un-ordered collection of unique objects. Set doesn’t allowed duplication . List and Set are both extend collection interface. o Map provides a data structure based on Key Value. Key is always unique, value can be dupl.
What is Array?
An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. You have seen an example of arrays already, in the main method of the “Hello World!” application. This section discusses arrays in greater detail.
* Each item in an array is called an element, and each element is accessed by its numerical index. As shown in the preceding illustration, numbering begins with 0. The 9th element, for example, would therefore be accessed at index 8.
Difference between Arrays and ArrayLis tin Java?
What is thread safe or Synchronized?
Thread safety is very important, and it is the process to make our program safe to use in multi-threaded environment, there are different ways through which we can make our program thread safe.
* Synchronization is the easiest and most widely used tool for thread safety.
* JVM guarantees that synchronized code will be executed by only one thread at a time.
* JAVA keyword synchronized is used to create synchronized code and internally it uses locks on Object or Class to make
sure only one thread is executing the synchronized code.
Difference between Hashtable and HashMap in Java?
There are several differences between HashMap and Hashtable in Java:
* Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as
unsynchronized Objects typically perform better than synchronized ones.
* Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
* For example; one of HashMap’s subclasses is LinkedHashMap, so in the event that you’d want predictable iteration order
(which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn’t be as
easy if you were using Hashtable.
How would you handle Exception in JAVA?
I would use try-catch-finally approach to handle the Exception
* 1- I would put my code that might generate an exception inside a try-catch block. With try-catch block I can rethrow an
exception or try to perform my recovery steps. Also, If needed I can use multi or Union Catch blocks
* 2- I can also use throws keyword. BUT it does mean that anyone that calls my method now needs to handle it too!
* 3- Another way is AutoCloseable: When we place references that are AutoCloseable in the try declaration, then we don’t
need to close the resource ourselves. We can still use a finally block, though, to do any other kind of cleanup we want. try- with
TreeSet vs TreeMap
TreeSet: Can contain only unique values - is sorted in ascending order
* TreeMap: can contain only unique keys. - keys are sorted in ascending order
final vs finalize v sfinally?
final a keyword and used to apply restrictions on class, method and variable.
o final Class
o final Method
o final Variable value
CAN’T be Inherited CAN’T be Overridden CAN’T be changed.
* finally a block and used to place important code, it will be executed whether exception handled or not
* finalize a method and used to perform clean-up processing before Object is Garbage collected.
Difference between RuntimeException and CheckedException in Java?
Exception are divided in two categories Runtime (unchecked) Exception and CheckedException.
* Main difference between RuntimeException and CheckedException is that, it is mandatory to provide try-catch to handle
CheckedException while in case of RuntimeException is not mandatory.
* Some of the most common Exception like NullPointerExceptio, ArrayIndexOutOfBound, ClassNotFoundException,
IOException.
Difference between throw and throws in Java?
throw and throws are two keywords related to Exception feature of Java programming language.
* throw keyword is used to throw an exception explicitly, on the other hand, throws keyword is used to declare an exception
which means it works similar to the try–catch block.
* If we see syntax wise than throw is followed by an instance of Exception class throws is followed by exception class names.
* throw new ArithmeticException (“Arithmetic Exception”); throws ArithmeticException;
Difference between Object and Class?
Class is a blueprint or template which you can create as many objects as you like Object is a member or instance of a class
* Class is declared using class keyword, Object is created through new keyword mainly.
There are many ways to create object in java such as new keyword, newInstance() method, clone() method, factory
method and deserialization. There is only one way to define class in java using class keyword.
* Object is created many times as per requirement. Class is declared once.
* Object is an instance of a class. Class is a blueprint or template from which objects are created.
* Object is a physical entity. Class is a logical entity.
StringBuffer and StringBuilder?
The main difference is StringBuffer is synchronized while StringBuilder is non-synchronized. So, StringBuilder can be called simultaneously. And this makes StringBuilder more efficient.
StringBuffer is synchronized, StringBuilder is non-synchronized StringBuilder is more efficient than StringBuffer
Important String Methods?
JavaCollectionFramework
List, Set, Map
Do you know type casting? What is casting?
Auto-boxing and Unboxing
What is the difference between pass-by-value and pass-by-reference?
What are the advantages of Selenium?
Selenium is open source and free to use without any licensing cost
* It supports multiple languages like Java, Ruby, Python, C#…
* It supports multi-browser testing
* It has a good amount of resources and helping community
* It supports many operating systems like Windows, Mac, Linux …
* Interact with the web application
What are the disadvantages of Selenium?
Selenium supports only web-based applications, does not support windows-based application
* No built-in reporting tool, it needs third party tools for report generation activity
* Cannot work with graphics, captchas, barcodes, shapes
* It does not support file upload facility.
* Hard to master, requires developer level knowledge
* Hard to write good locators
* Hard to synchronize