LOADING CLOSE

FlipGrid Videos – Java and Test Automation Interview Questions & Answers

FlipGrid Videos – Java and Test Automation Interview Questions & Answers

Question-02: What is Agile?

Agile is a set of methodologies that helps teams to think more effectively, to work more efficiently and make better decisions. Agile is also a mindset, because only when a team has the right mindset, they can create a big difference. The foundation of Agile, the Agile Manifesto, is created in 2001 by seventeen individuals working on software development and hence it was initially for Agile Software Development then it is used in other sectors and industries.

Agile has many methodologies such as Scrum, Kanban, Lean, Extreme Programming, Scrumban, Scaled Agile, and Disciplined Agile etc…

The most common Agile methodology is Scrum. Agile Manifesto has 4 simple core values and 12 main principles. First of all 4 core values are;

1st one Agile values Individuals and Interactions more than Processes and tools

2nd one Agile values Working Software more than Comprehensive documentation

3rd one Agile values Customer Collaboration more than Contract negotiation

4th one Agile values Responding to Change more than Following a plan

Agile has 12 main principles these are;

1. Deliver valuable software early and continuously is the highest priority. Product backlog is listed based on the value of items and there are timeboxed sprints and at the end of each sprint working software should be ready

2. Welcoming change for customer’s advantage. Agile can easily respond to change

3. Deliver working software frequently. As I mentioned, there are timeboxed sprints which take 2 weeks to 4 weeks

4. Attach importance to face to face conversation to convey information efficiently and effectively. Daily Standup Meetings are arranged to talk about the progress of team members. (3 questions)

5. Business people and developers should work together. At the end of each sprint there is review meeting to talk about the product

6. Motivate people, support and trust them. There is a Scrum Master role for this.

7. Working software is the primary measure of progress.

8. Agile promotes sustainable development. All parties should maintain a constant pace.

9. Continuous attention to technical excellence and good design.

10. Simplicity, the art of maximizing the amount of work not done, is essential.

11. Self-organizing teams put forward best requirement, design and architecture. Teams themselves plan their works in a sprint. 12. Teams should think about how to become more efficient and adjust themselves periodically. At the end of each sprint a sprint retrospective meeting is held to evaluate the last sprint.

***

Question-03:  JVM, JRE, and JDK

JVM stands for Java Virtual Machine. JRE stands for Java Runtime Environment. JDK stands for java Development Kit.

First of all, JVM enables the Java executable code to run platform independently. It means, as long as JVM is installed, Java compiled code can run on any machine. JVM cannot be installed separately. It comes with either JRE or JDK. JRE covers JVM and it physically exists (such as libraries in the computer). JDK covers JRE, development tools and Java compiler.

JVM does not physically exist as it is a virtual machine. In cannot be separately installed or downloaded. It comes with JRE or JDK. It is a part of JRE, then in order to install JVM, we need to install JRE or JDK.

Secondly, JRE contains JVM and a set of Java libraries. In order to run Java code and java applications on your computer, we need to install JRE at least. It physically exists in the computer as files and classes.

Lastly, JDK is used for development purposes. It contains JVM, JRE, Java compiler and a set of development tools. It is used for development purposes. It converts the source code into machine language. It also exists in the computer as files and classes. In order to develop Java applications, JDK should be installed in the computer.

In order to run Java applications in the computer, JRE is enough. However, in order to develop Java applications in the computer, JDK is necessary.

Java is a platform independent programming language, however JVM, JRE and JDK are platform dependent.  We need to install proper versions of these according to the operating system that you run.

***

Question-04: Variable & Data Types

In Java, variable is a piece of memory that contains a value in it. This value is a data type in Java. There are primitive and non-primitive data types. Primitive data types are divided into four groups. These are: integer, floating point, character and Boolean. Also, non-primitive data types are divided into four groups, these are: Interfaces, classes, strings and arrays.

Integer primitive data type is divided into four sub-groups, these are: byte, short, int, and long. Byte has a capacity of 1 byte, short has a capacity of 2 bytes, int has a capacity of 4 bytes, and long has a capacity of 8 bytes. These four represent whole numbers.

Floating point primitive data type is divided into two groups: These are float and double. Float has a capacity of 4 bytes and double has a capacity of 8 bytes. These two represents decimal point numbers.

Character primitive data type has a capacity of 2 bytes. It represents ASCII table characters.

Boolean primitive data type has a capacity of only 1 bit. This can be either True or False.

Non-primitive data types are divided into four groups. These are: Interfaces, classes, strings and arrays. String is a kind of character array. And arrays store a certain primitive data type. Arrays can be one-dimensional, two-dimensional or more.

Lastly, variables can be declared and initialized. When we declare a variable, we define it, and when we initialize it, we assign a certain value in it. Casting between primitive data types is possible. This casting can be either implicit or explicit.

***

Question 05- Swapping two numbers in Java with two different methods.

***

Question 06-What is Method Overloading?

Method overloading means in the same class there are multiple methods that have same name but have different signatures. Method overloading increases code reusability and code readability. Method overloading can be realized in three ways.

  1. Same method names with different number of parameters.
  2. Same method names with different type of parameters.
  3. Same method names with different order of parameters.

If there are multiple methods with same name but different return types or different access modifiers, this situation cannot be considered method overloading. In other words, this situation is not important in terms of method overloading. Constructors and static methods can also be overloaded.

Here the important point is method overloading can only be performed within the same class. Also main method can be overloaded. As we know main method can have parameters. In method overloading if there is no exact type matching, one data type can be promoted to another data type. If there is exact type matching, then there will be no type promotion. If there is no exact type matching but there are multiple methods that are eligible for type promotion, then compiler error occurs.

***

Question 7-Array vs ArrayList?

Array is a part of core Java programming and has special syntax. ArrayList is a part of collection framework and implements List interface.

There are seven differences between Array and ArrayList:

  1. While creating Array, it is mandatory to specify size; however ArrayList can be created without specifying size.
  2. Array is static, it has fixed length and we cannot change its size after they are declared. However ArrayList is dynamic and after its creation it is resizable.
  3. Array can contain both primitive and non-primitive data types (for example, string). However ArrayList can only contain objects and it cannot contain primitives. There are wrapper classes that autoboxes primitives to transform them into objects.
  4.  To learn the size of an Array, we use length attribute, however to learn the length of an ArrayList we use size() method.
  5. Array does not have ready to use methods to manipulate its elements, whereas ArrayList has a bunch of methods (add, get, set, remove, clear) to manipulate its elements.
  6. Arrays can be multidimensional, whereas ArrayLists are single dimensional.
  7. Arrays are faster than ArrayLists due to its fix size.

***

Question 08-What is String in JAVA? Strings, Immutability of Strings, and String Pool

In Java, string is a non-primitive data type that contains a sequence of characters.

Strings are immutable in Java. That is once they are created their content cannot be changed. However we may think that we can declare a string object and initialize it by setting a value to it. Then we may set another value to it. However the variable that we assign value is not the string object itself, it is just a reference to the actual string object in the memory.

When we assign a new value to that variable, we actually create a new string object and our variable starts to point that new string object, it does not point our previous string object anymore. Consequently, the string objects themselves in memory does not change. It is called immutability.

On the other hand, if we create a new string with a new keyword, then Java will create a separate object.

As I mentioned, the place where the string objects located is called “String Pool” in Java. String pool is a special memory region where strings are stored by JVM. As strings are immutable in Java, JVM optimizes memory allocation for strings by only storing one copy for each string in the pool.

***

Question-9: What are the differences between method and constructor?

There are nine basic differences between constructor and method in Java.

  1. Constructor is used to create and initialize an object. Method is used to execute certain statements.
  2. Constructor is called implicitly by Java compiler if we do not have any, however method cannot be called implicitly.
  3. A constructor is invoked when a new keyword is used to create an object. A method is invoked when it is called.
  4. Constructor does not have any return type, a method has a return type or it returns void.
  5. A constructor must have a same name with its class; a method can have any name including its class name.
  6. A constructor cannot be inherited by a subclass; a method can be inherited by a subclass unless it is private.
  7. Java has special keywords, super and this, to call a constructor explicitly. However a method does not have such a keyword. It can only be called with its own name.
  8. Constructor initializes an object that does not exist, however method does an operation on an object that is already created.
  9. Constructor is called once, however method can be called many times.

***

Question-10: What’s inheritance? Can a super class have more than one subclass?

In Java inheritance is a mechanism where a child class acquires properties and behaviors of a parent class. Inheritance is an important concept in object oriented programming. It increases code reusability and decreases redundancy.

By means of inheritance you can create a new class that is built on an existing class. When you inherit a class you can reuse its methods and variables. Also you can add new methods and variables to the existing ones.

Inheritance represents is a relationship and also known as parent/child, superclass/subclass and base class/derived class relationship. Extends keyword is used to inherit from a parent class.

Java supports single inheritance, multilevel inheritance and hierarchical inheritance. It does not support multiple inheritance. However, multiple inheritance can only be achieved through interfaces by using implements keyword.

All public and protected methods and variables can be inherited.

All default methods and variables can be inherited if they are in the same package.

Private methods and variables cannot be inherited.

Constructors cannot be inherited by a child class but they can be invoked from the child class. They can be invoked either implicitly or by using super keyword.

By means of inheritance you may override instance methods of a parent class or you may hide static methods of a parent class. Only,

If they have same signature.

If access modifier of child class method is more visible.

If return type of child class method is same or covariant type.

Super keyword is used to access methods and variables of parent class if their names same with child class methods and variables.

***

Question 11- How to test a vending machine?

I will start by examining the requirements documentations and check what the expected results are and what are the actual results. First I will check preconditions to start to the testing and see whether the machine is plugged and working and there is at least one item in the vending machine.

I will do functional testing and check both positive and negative scenarios.

I will do smoke test and check whether the number buttons work. Also I will check the LCD message screen and also product output section of the machine whether it is accessible. Also coin insertion and return mechanisms.

I will also check both positive and negative scenarios.

When I insert more money than the actual price of the product, does the machine returns excess amount?

When I insert money equals to the actual price of the product, what happens?

When I insert less money than the actual price of the product, does the machine requests extra money or returns the money if I do not insert more?

I will do some non-functional testing for instance:

I will check what happens when I kick the machine or shake the machine.

I will do some compatibility test and try to insert other currencies and check whether the machine recognizes the coin.

Also I will check whether the machine accepts credit card, contactless payment or banknote.

***

Question-12: What are the different types of locators in Selenium? Which one is preferable to use?

In Selenium there are eight locators. These are id, name, classname, tagname, linktext, partial link text, css and xpath.

  1. Id: It is fastest one and it is unique. However it might be dynamic. That means, when a page refreshes, or some actions happen in a page it can change.
  2. Name: It is not unique. That means there might be more than one element with the same name attribute value.
  3. Class name: It is not unique and also if there is a space in class attribute value we cannot use it.
  4. Tag name: There are several html tags such as div, input, button, select etc. We can use tag name in order to locate web elements. However if there are multiple elements with same tag, selenium only chooses the first one.
  5. Link text: We use link text in order to locate links in a page. However here we must use the full link text in order to locate it.
  6. Partial link text: It is also used to locate links in a page. It enables us to use a part of a link text in order to locate it.
  7. Css: It can use html tags and attributes together under some pre-defined rules. Css has methods such as contains, starts with and ends with. However Css has some disadvantages. For instance,
    – Css cannot locate elements by using text.
    – Css cannot locate elements by using index if they are under different parents.
    – Css cannot go from child element to parent element.
  8. Xpath: Xpath can use html attributes and tags under some predefined rules. It is powerful. Like css, Xpath also some methods such as text, contains, starts with and ends with. However we cannot use ends with under chrome browser. There are two types of xpath: Absolute xpath and Relative xpath.
    Absolute xpath: A bit long and difficult to read. It is a bit fragile.
    Relative xpath: It is a bit short and easy to read. It is not fragile. It is written according to the selected web element.

***

Question-13: What is abstraction, abstract methods, abstract classes and interfaces?

In Java, abstraction is the process of hiding implementation details and showing only functionality to the user. It lets the user to focus on what the object does, instead of how it does. Abstraction helps organizing code, reusing code, and less duplicate code. In Java abstraction is achieved through abstract classes and interfaces.

We use abstract classes in order to create a foundation for a subclass. However we use interfaces in order to add a feature to a class by providing abstract methods.

When we want to use abstract class we use extend keyword. When we want to use interface, we use implement keyword. The first concrete class that extends an abstract class must provide an implementation for all inherited abstract methods. If a class both extends a class and implements an interface, then extend should come first and then implement keyword should come.

We use abstract keyword in order to create abstract methods. Abstract methods does not have method body, they only have signatures. Abstract methods can only be defined in abstract classes. Abstract method must not provide a method body/implementation in the abstract class it is declared. Abstract methods cannot be declared as private or final. Implementing an abstract method in a concrete subclass follows the same rules for overriding a method. Namely, a child class can define abstract methods with same or less restrictive visibility, whereas a class implementing an interface must define all interface methods as public.

In test automation, base page or test base is an example of abstract classes and webdriver is an example of interfaces. We can use this interface and initialize any browser by implementing this interface.

There are several differences between abstract classes and interfaces:

Both abstract classes and interfaces cannot be instantiated. Namely we cannot create an object from an abstract class or interface.

Abstract keyword is optional while declaring an interface.

Abstract classes may have both abstract methods and non-abstract (concrete) methods; however interfaces may only have abstract methods.

Abstract classes may have constructors inside them; however interfaces cannot have constructors inside them.

Abstract class can extend only one abstract class and can implement multiple interfaces; however interfaces can only extend multiple interfaces as they support multiple inheritance. Interfaces cannot extend an abstract class.

A standard concrete class can extend only one abstract class and can implement multiple interfaces.

Abstract class can use all access modifiers with variables and methods, however interfaces can only use public access modifier.

Abstract classes are faster than interfaces.

Abstract classes cannot be marked as private or final.

When an abstract class extends another abstract class, it inherits all of its abstract methods.

Abstract class can provide the implementation of the interface; an interface cannot provide implementation of the abstract class.

***

Question-14: What’s Polymorphism? What’s downcasting?

Polymorphism is the ability of a variable to take multiple forms.

For instance you may use a mobile phone as a camera, as a calculator or as an mp3 player.

In Java, polymorphism is the ability of using objects in many forms. It is one of the most important object oriented programming concepts.

In polymorphism, there is a reference type and there is an object type. Reference type is parent class or interface, object type is child.

Reference type can be parent or interface, object type can be any extending/implementing child class and reference type decides what is accessible.

In Java the most common use of polymorphism is when a parent class reference type is used to refer to a child class object type.

There are two types of polymorphism in Java. “Compile time polymorphism” and “Run time polymorphism”.

Compile time polymorphism is achieved through “method overloading”. Since, at compile time Java knows which method to call by checking method signatures. Compile time polymorphism is static.

Run time polymorphism is achieved through “method overriding”. Here JVM determines the proper method to call at run time, not at compile time. Run time polymorphism is dynamic.

Here in polymorphism, there happens typecasting. There are two types of typecasting: Upcasting and Downcasting. Between the parent class and child class, typecasting happens. In order to do typecasting there should be a relationship between classes.

Downcasting cannot be done implicit. It can only be done explicitly. It is typecasting of a parent class to a child class. Aim of downcasting is to be able to call the methods of object type.

Webdriver is the sample of polymorphism in test automation framework.

Leave a Reply