Basic Java Interview Questions For Selenium

Following are the list of basic Java interview questions can be asked in selenium interview. Interviewer can ask to check your understanding of java as a programming language.
Question: – What is JRE and why it is required?
Answer: – Java Runtime Environment (JRE) is a runtime component of java software can be used to run any java application which can comprises JVM, classes and supporting libraries.          Question: – What is JVM?
Answer: – Java Virtual Machine (JVM) translates and executes java byte code

Question: – What is Byte Code?
Answer: – Java compiler generates byte code for all the Java code and converts into class files.

Question: – What is JDK?
Answer: – Java Development Kit (JDK) is a superset of the JRE and includes compilers and debuggers tools with JRE required for developing Java applications.

Question: – Differentiate between the Path and Classpath?
Answer: – Path = defines the location where the system can look up for the executables (.exe) files.
Classpath = specifies the location of the Java class files.

Question: – Differentiate between a constructor and method?
Answer: – Constructor = Gets automatically invoked to create an object
Method = Gets called explicitly

Question: – Is it permissible for a constructor to have a different name than its class name in Java?
Answer: – No. Name of constructor is always same with its class name

Question: – Differentiate between an argument and a parameter?
Answer: – In methods definition, we pass variables which we can refer as parameters. And when we call these methods and pass values for the variables then they are phrased as arguments.

Question: – What will happen if you declare the main method as private?
Answer: – Program will get compiled correctly but will throw the error “Main method not public.” at runtime.

Question: – Difference between pass by reference and pass by value in Java?
Answer: – Pass by reference = Passing the address itself rather than passing the value.
Pass by value = Giving a copy of the value.

Question: – Can you compile a Java class successfully without having the main method?
Answer: – Yes, we can compile, but it won’t run

Question: – Is Java program will compile/run if we use <static public void> instead of <public static void>?
Answer: – Yes, the program will compile and run as usual.

Question: – What is meaning of public static void main (String args [])?
Answer: – Public- main ():- Entry point method which the JVM calls when a program is run. It is mandatory to get accessible from the Java environment.
Static- JVM must be capable of calling this method without creating an instance of the class.
Void- main ():- Doesn’t return anything so its return type must be void.
Argument string represents the argument type passed from the console, and the ‘args’ is an array of strings specified at the command line.

Question: – Does java support multiple inheritance?
Answer: – No

Question: – Can we declare class as a protective?
Answer: – No

Question: – What is package?
Answer: – It is collection of related classes and interfaces

Question: – Can class be defined inside an interface?
Answer: – Yes

Question: – Can interface extend another interface?
Answer: – Yes

Question: – Can interface defined inside a class?
Answer: – Yes

Question: – What is encapsulation?
Answer: – Wrapping code and data together into a single unit is called as encapsulation. All data members are private in fully encapsulated class.

Question: – Can we overload main method?
Answer: – Yes. It always runs first main method only

Question: – What are the naming conventions?
Answer: – Class name = should start with upper case letter
Interface name = should start with upper case letter
Method name = should start with lower case letter
Variable name = should start with lower case letter
Package name = should start with lower case letter
Constant name = should start with upper case letter
CamelCase = if name combined with two words then second name start with upper letter

Question: – What is instance variable?
Answer: – A variable which created inside the class but outside the method is known as instance variable. At compile time instance variable doesn’t get memory but gets memory at run time

Question: – What is new keyword?
Answer: – The new keyword is used to allocate memory at the time of run time

Leave a Reply