0% found this document useful (0 votes)
53 views7 pages

Selenium Capgemini

The document provides a comprehensive overview of Java programming concepts, including differences between C++ and Java, class loaders, wrapper classes, and memory management. It also covers object-oriented programming principles, various data types, Selenium WebDriver usage, exception handling, and access modifiers. Additionally, it explains method overloading and overriding, as well as the differences between various Java operators and input/output methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views7 pages

Selenium Capgemini

The document provides a comprehensive overview of Java programming concepts, including differences between C++ and Java, class loaders, wrapper classes, and memory management. It also covers object-oriented programming principles, various data types, Selenium WebDriver usage, exception handling, and access modifiers. Additionally, it explains method overloading and overriding, as well as the differences between various Java operators and input/output methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1. What are the differences between C++ and Java?

A) C++ is not platform-independent; the principle behind C++ programming is “write once,
compile anywhere.” Java is a Platform Independent language. Unlike many programming languages
javac compiler compiles the program to form a bytecode or .class file.

2. What is a ClassLoader?

A) A classloader in Java is a subsystem of Java Virtual Machine, dedicated to loading class files
when a program is executed; ClassLoader is the first to load the executable file.

3. Define Wrapper Classes in Java.

A) In Java, when you declare primitive datatypes, then Wrapper classes are responsible for
converting them into objects(Reference types).

4. Can you implement pointers in a Java Program?

A) Java Virtual Machine takes care of memory management implicitly. Java's primary motto was
to keep programming simple. So, accessing memory directly through pointers is not a
recommended action. Hence, pointers are eliminated in Java.

5. Do final, finally and finalize keywords have the same function?


A) Final: If any restriction is required for classes, variables, or methods, the final keyword comes
in handy.
Finally: It is the block present in a program where all the codes written inside it get executed
irrespective of handling of exceptions.
Finalize: Prior to the garbage collection of an object, the finalize method is called so that the
clean-up activity is implemented.
6. When can you use super keyword?
A) The super keyword is used to access hidden fields and overridden methods or attributes of
the parent class.

7. What is the main objective of garbage collection?


A) The main objective of this process is to free up the memory space occupied by the
unnecessary and unreachable objects during the Java program execution by deleting those
unreachable objects.
8. What is the difference between getWindowhandles() and getwindowhandle()?
getwindowhandles(): It is used to get the address of all the open browser and its return type is
Set <String>
getwindowhandle(): It is used to get the address of the current browser where the control is
and return type is string.

9. Explain using Webdriver how you can perform double click?


You can perform double click by using
 Syntax: Actions act = new Actions (driver);
 act.doubleClick(webelement);
10. What are Memory storages available with JVM?
A)
 Class (method)
 Heap
 Stack
 Program counter register
 Native method stack

11. Difference between JVM, JRE, and JDK.


A) JVM: JVM also known as Java Virtual Machine is a part of JRE. JVM is a type of interpreter
responsible for converting bytecode into machine-readable code.

JRE: JRE stands for Java Runtime Environment, it is an installation package that provides an
environment to run the Java program or application on any machine.

JDK: JDK stands for Java Development Kit which provides the environment to develop and
execute Java programs.

12. What is Java String Pool?


A) Java String Pool is a place in heap memory where all the strings defined in the program are
stored.

13. What are Assert and Verify commands in Selenium?


 Assert: An assertion is used to compare the actual result of an application with the
expected result.
 Verify: There won’t be any halt in the test execution even though the verify condition is
true or false.

14. Explain different data types in Java.


A)
1. Primitive Data Type
2. Non-Primitive Data Type or Object Data type
Primitive data types:
 Boolean
 Byte
 Char
 Short
 Int
 Long
 Float
 Double
Non – primitive data types:
 Strings
 Arrays
 Class
 Object
 Interface

15. What are the basic steps to create a Selenium WebDriver test case?
The basic steps to create a Selenium WebDriver test case include:
 Launching a web browser
 Navigating to a web page
 Interacting with web elements
 Performing actions on web elements
 Verifying expected results

16. What is the difference between System.out, System.err, and System.in?


A) System.out – It is a PrintStream that is used for writing characters or can be said it can
output the data we want to write on the Command Line Interface console/terminal.
System.err – It is used to display error messages.
System.in – It is an InputStream used to read input from the terminal Window. We can’t use
the System.in directly so we use Scanner class for taking input with the system.in.

17. How many ways you can take input from the console?
A) There are two methods to take input from the console in Java mentioned below:
1. Using Command line argument
2. Using Buffered Reader Class
3. Using Console Class
4. Using Scanner Class

18. Difference in the use of print, println, and printf.


A) print, println, and printf all are used for printing the elements but print prints all the
elements and the cursor remains in the same line. println shifts the cursor to next line. And
with printf we can use format identifiers too.
19. How many types of operators are available in Java?
All types of operators in Java are mentioned below:
1. Arithmetic Operators
2. Unary Operators
3. Assignment Operator
4. Relational Operators
5. Logical Operators
6. Ternary Operator
7. Bitwise Operators
8. Shift Operators
9. instance of operator

20. Explain the difference between >> and >>> operators.


A) Operators like >> and >>> seem to be the same but act a bit differently. >> operator shifts
the sign bits and the >>> operator is used in shifting out the zero-filled bits.

21. What is the difference between int array[] and int[] array?
A) Both int array[] and int[] array are used to declare an array of integers in java. The only
difference between them is on their syntax no functionality difference is present between
them.

22. What are the main concepts of OOPs in Java?


A) The main concepts of OOPs in Java are mentioned below:
 Object - Any entity that has state and behavior is known as an object.
 Class - Collection of objects is called class
 Inheritance - When one object acquires all the properties and behaviors of a parent
object, it is known as inheritance. It provides code reusability. It is used to achieve
runtime polymorphism.
 Polymorphism - If one task is performed in different ways, it is known as polymorphism.
 Abstraction - Hiding internal details and showing functionality is known as abstraction.
 Encapsulation - Binding (or wrapping) code and data together into a single unit are
known as encapsulation.

23. What are the types of waits supported by WebDriver?

A) Implicit wait - Implicit wait commands Selenium to wait for a certain amount of time before
throwing a “No such element” exception.

Example: driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);


Explicit wait - Explicit wait is used to tell the Web Driver to wait for certain conditions before
throwing an "ElementNotVisibleException" exception.

Example: WebDriverWait wait = new WebDriverWait(WebDriver Reference, TimeOut);

24. What is method overloading and method overriding?


A) Method overloading: If a class has multiple methods having same name but different in
parameters, it is known as Method Overloading.
If we have to perform only one operation, having same name of the methods increases the
readability of the program.

Method overidding: If subclass (child class) has the same method as declared in the parent
class, it is known as method overriding in Java.
In other words, If a subclass provides the specific implementation of the method that has been
declared by one of its parent class, it is known as method overriding.

25. What are access modifiers?


A) There are four types of Java access modifiers:
1. Private: The access level of a private modifier is only within the class. It cannot be
accessed from outside the class.
2. Default: The access level of a default modifier is only within the package. It cannot be
accessed from outside the package. If you do not specify any access level, it will be the
default.
3. Protected: The access level of a protected modifier is within the package and outside
the package through child class. If you do not make the child class, it cannot be accessed
from outside the package.
4. Public: The access level of a public modifier is everywhere. It can be accessed from
within the class, outside the class, within the package and outside the package.
26. How will you find an element using Selenium?
In Selenium every object or control in a web page is referred as an elements, there are different
ways to find an element in a web page they are
 ID
 Name
 Tag
 Attribute
 CSS
 Linktext
 PartialLink Text
 Xpath etc
27. When do we use findElement() and findElements()?
findElement() is used to access any single element on the web page. It returns the object of the
first matching element of the specified locator.

General syntax:

WebElement element = driver.findElement(By.id(example));

findElements() is used to find all the elements in the current web page matching the specified
locator value. All the matching elements would be fetched and stored in the list of Web
elements.

General syntax:

List <WebElement> elementList = driver.findElements(By.id(example));

28. Types of Java Exceptions?


A) There are mainly two types of exceptions: checked and unchecked. An error is considered as
the unchecked exception. However, according to Oracle, there are three types of exceptions
namely:
1. Checked Exception - The classes that directly inherit the Throwable class except
RuntimeException and Error are known as checked exceptions.
2. Unchecked Exception - The classes that inherit the RuntimeException are known as
unchecked exceptions. For example, ArithmeticException, NullPointerException,
ArrayIndexOutOfBoundsException, etc.
3. Error - Error is irrecoverable. Some example of errors are OutOfMemoryError,
VirtualMachineError, AssertionError etc.
29. Difference between throw and throws in Java?
A) Throw: Java throw keyword is used throw an exception explicitly in the code, inside the
function or the block of code.
Throws: Java throws keyword is used in the method signature to declare an exception which
might be thrown by the function while the execution of the code.

30. Write a java program to reverse a string?


1. A) public class Reverse
2. {
3. public static void main(String[] args) {
4. String string = "Dream big";
5. String reversedStr = "";
6.
7. for(int i = string.length()-1; i >= 0; i--){
8. reversedStr = reversedStr + string.charAt(i);
9. }
10.
11. System.out.println("Original string: " + string);
12. System.out.println("Reverse of given string: " + reversedStr);
13. }

You might also like