Download as pdf
Download as pdf
You are on page 1of 9
Java for Testers - Interview Questions and Answers Part-4 41) What Is the use of static keyword In Main()? ‘Since main() method is the entry point of any Java application, hence making the main() ‘method as static is mandatory for launching the Java application. Since the main method is stati, Java virtual Machine can callil without creating any instance of a class which contains the main method 2) Can a class without main() gets compilation successful? The main method is only used when the Java Virtual Machine is executing your code. Code cannot ho executed without a main method but it can stil be compiled 3) Can we create private access specifier inside interface? We cannot declare class/interface with private or protected access specifies, 4) ls there any way to deallocate memory in JAVA? We should dereference the object, then memory willbe deallocated automaticaly during garbage collection 5) Write a program for removing white spaces in a String? 6) What is Object “The Object class is the parent class of all he classes in java by default Every class in Java is directly or indirectly derived from the Object class 7) Write a Java program for pascle triangle? void printFascal (23° 9) © andera-w serce us printPascal (a) £8) What are the differences between interface and inheritance? — Inheritance is an OOP concept to danve new classes from the existing classes. Interface is ‘a mechanism in OOP to implement abstraction and multiple inheritance. ~ Inheritance provides code reusabilty. Interfaces provide abstraction and multiple inhortance. 9) If we close the driver in try block then,FINALLY will execute or not? Java finally block is always executed whether exception is handled or not, 10) What is difference between method overloading and constructor overloading with example? If we want to have different ways of initializing an object using diferent number of parameters, then we must do constructor overloading and we do method overloading when |we want diferent definitions of a method based on different parameters. 14) What is the difference between normal class and final class? Final class cannot be inherited by any other class but normal class can be inherited by other classes 12) Adapter design in Java? Adapter design pattem is one of the structural design pattern and its used so thet two unrelated interfaces can work together. The object that joins these unrelated interface is callod an Adapter. 13) Write a Java program for sorting of numbers? 14) Write a Java program for searching a letter in string? 15) Write a Jas program for sorting an array? poise vets metn(sesioat) azz) syaten, cur printf ("Modified azz(] + #3", Rezaya. coscrins (ae) 16) What is a good approach to throw an exception? By using throws keyword. void main(2ecing(] ar95) ee(Moaitied are] + 42", arzave 17) Find how many duplicate values in Array List? 18) String [| str=(“abe”,"etg”,"tgh”}; convert array to string? Arrays toString (str) 19) Explain the features of JAVA? ‘Most important features are: = Simple = Object-Onentad ~ Portable — Platform independent ~ Secured = Robust — Architecture neutral = Interpreted = High Performance — Multithreaded — Distributed = Dyramic 20) How do u say JAVA is platform independent? Platform independent language means once compiled you can execute the program on any platform (0S) Java is platform independent. Because the Java compiler converts the source code to bytecode, which s Intermidiate Language. Bytocode can be executed on any platform (0S) using JVM( Java Virtual Machine) 21) Is JVM platform independent? Yes. Java i platform independent 22) What Is the difference between a Class and Object? — Objects an instance of @ class. Class is @ blueprint or template fom which objects are created. = Objects a real word Monty. Class is a group of similar objects, — Object allocates memory when itis crested. Class doesn't allocated memory when itis created. 23) Write a Java program to check whether an year is leap year or not? pubtie clave teapvear 24) Where to use Hashtable in real time? Hashtable should be used in mulithreading applications as itis thread safe and synchronized 26) What is the difference between Volatile & Transient in Java? — transient keyword is usad along with instance vanables to exclude them from serialization process = fa field is transient its value wil not be persisted. On the other hand volatile Keyword can also be used in variables to indicate compiler and JVM thal always read its value from main memory ~ transient keyword can not be used along with static keyword but volatile can be used along with static — transient variables are inialized with default value during de-seriaization and there assignment or restoration of value has to be handled by application code

You might also like