Other useful Links:
- Manual Testing Interview Questions (01-40)
- Manual Testing Interview Questions (41-80)
- Selenium With Java Interview Questions - (01-35)
- Selenium With Java Interview Questions - (36-70)
- Java Programs for QA Automation Interview (01-15)
- Java Programs for QA Automation Interview (16-30)
- TestNG Interview Questions for QA (01-20)
- TestNG Interview Questions for QA (21-40)
- Maven Interview Questions for QA Automation Interview (01-15)
- Maven Interview Questions for QA Automation Interview (16-30)
- Most Frequently Asked API Testing Interview Questions (01-20)
- Most Frequently Asked API Testing Interview Questions (21-40)
- Final variable is a variable that is declared as final and is not initialized.
- yes, public static final void main(String[] args){}
- No. Because methods of interfaces are abstract by default and we can't use static and abstract together.
- No, because the main() method is also a static method.
- Yes. But -
- If a superclass doesn't declare an exception, a subclass overridden method cannot declare checked exceptions, but can only declare checked exceptions.
- If superclass declares an exception, then subclass cannot declare parent exception of exception declared by superclass.
57. Can we declare the interface as final?
- No. You cannot declare an interface as final because the interface must be implemented by some class to provide its definition.
- Therefore, there is no sense to make it final. However if you try to do so it will throw a compile time error.
- No, we can override member functions but not data members.
- Abstract classes are those that are declared abstract.
- It requires extension and implementation of its method..
- It cannot be instantiated.
- It can have abstract, non-abstract, static methods and constructors.
- It can also have a final method which will force subclass not to change the body of the method.
- No. If there is no abstract method in a class, the class must be abstract.
- No. We can't override the final method since we need to override the abstract method to provide its implementation.
- String literal
- String s1 = “welcome”;
- New keyword
- String s1 = new String(“welcome”);
64. How many objects are created?
String s1 = “India”;
String s2 = “India”;
String s3 = “India”;
- Only one
65. How many objects are created?
- Two - one in string constant pool and other in non-pool (Heap memory).
- String in Java is immutable, which ensures that the string value does not change. String literals are frequently exchanged among several clients.
- If the value of the string changes (from “ABC” to “abc”), it will affect all reference variables and cause severe discrepancies.
- Hence, strings are immutable in Java. Making a string immutable improves the application's security, caching, synchronisation, and performance.
- It's used to make that two objects specified by business logic have the same contents.
- The Object class provides a public boolean equals(Object o) function.
- It is a binary operator in Java.
- It examines if both objects are pointing to the same memory location by comparing addresses (or references).
- Default implementation uses a double equal operator == to compare two objects.
- By Nulling
- s1=null;
- By assigning it to another reference.
- s1=s2;
- By anonymous object.
- New A();
69. String vs StringBuffer
- By making the class and all its members final.
- Until the garbage is cleared, string stays in the string pool. If we store the password into the string then it stays in memory over long periods of time and anyone having access to the memory dump can extract the password as clear text.
- On the other hand, using char array allows us to set it to blank whenever we are done with the password. It avoids the security threats and enables us to save memory.
73. What is garbage collection?
- Garbage collection is the process of reclaiming the unused runtime objects. It is performed for memory management.
- In other words, we can say that garbage collection is a process of removing unused objects from memory to free up space and make this space available for JVM.
74. What is the System.gc() method?
- The System.gc() method is used to invoke a garbage collector. The System and Runtime classes both have this method.
- If an exception is handled, the execution flow will not be interrupted.
- Using the catch declaration, we can pinpoint the issue.
- When a try block surrounds a potentially dangerous code. A catch block catches an exception that occurs in the try block.
- Try can be followed by catch or finally or both. However, any one of the blocks is required.
- This is followed by a try block. Exceptions are caught here.
- finally is followed either by try block or catch block.
- This block gets executed regardless of an exception. So generally clean up codes are provided in this block.
78. Explain ‘throws’ keyword in java?
- The ‘throws’ is used to declare an exception. It notifies the programmer that an exception is possible.
- Exception handling is mainly used to handle checked exceptions. Throws keyword is required only for checked exceptions and usage of throws keyword for unchecked exceptions is meaningless.
- By the help of throws keyword provide information to the caller method about the exception.
80. final vs finally vs finalize
81. How many .class files will be created?
class Test{
class Test1{ // code}
static class Test2{ // code}
void run(){
Helper t = new Helper(){
Int helpMethod(){
return 5;
}
};
}
}
- This will produce class files
- Test.class
- Test $Test1.class
- Test $Test2.class
- Test $1.class (for the implementation of the Helper interface)
82. What is the meaning of Collections in Java?
- Collection is a framework for storing objects and manipulating the design in order to store them.
- Collections are used to perform the following operations:
- Searching
- Sorting
- Manipulation
- Insertion
- Deletion
- A group of objects is known as collections. All the classes and interfaces for collecting are available in the Java util package.
83. What are all the Classes and Interfaces that are available in the collections?
Interfaces:
- Collection
- List
- Set
- Map
- Sorted Set
- Sorted Map
- Queue
- Array List
- Vector
- Linked List
- Hash set
- LinkedHashSet
- Tree Set
- Hash Map
- TreeMap
- LinkedHashMap
- Priority Queue
88. HashMap vs HashSet
89. HashSet vs TreeSet
90. Array vs ArrayList
91. How to initialize a map with key as a string and value as integer?
HashMap<String, Integer> map = new HashMap<String,Integer>();
92. How to add and remove elements from HashMap?
- Add Elements:
- map.put(“Piyush”,10);
- map.put(“Rahul”,20);
- map.put(“Ujwal”,30);
- map.put(“Shubham”,40);
- Remove Elements:
- map.remove(“Shubham”,40);
93. How to iterate through HashMap?
for(Map.Entry<String,Integer> e:map.entrySet()){
System.out.println(“key”+e.getKey()+ ” value”+e.getValue());
}
94. Does HashMap maintain insertion order?
- No. TreeMap and LinkedHashMap maintain insertion order.
- forEach() method in iterable interface
- Lambda expressions and functional interfaces
- Static and default methods in interfaces
- Java time API
- Stream API for bulk data operations on collections
- Concurrency API improvements
- Collection API improvements
- Java IO improvements
- Core API improvements
Contact:
Email: piyushagrawal.automation@gmail.com
Follow on LinkedIn: Piyush Agrawal - LinkedIn
Follow on YouTube: Piyush Agrawal - Youtube
No comments:
Post a Comment