Java Oops
Java Oops
© Copyright by Interviewbit
20. Is it possible that the ‘finally’ block will not be executed? If yes then list the case.
Java Intermediate Interview Questions (.....Continued) Java Intermediate Interview Questions (.....Continued)
39. What makes a HashSet different from a TreeSet? 59. What do you understand by Object Cloning and how do you achieve it in Java?
40. Why is the character array preferred over string for storing confidential 60. How does an exception propagate in the code?
information? 61. How do exceptions affect the program if it doesn't handle them?
41. What do we get in the JDK file? 62. Is it mandatory for a catch block to be followed a er a try block?
42. What are the differences between JVM, JRE and JDK in Java? 63. Will the finally block get executed when the return statement is written at the
43. What are the differences between HashMap and HashTable in Java? end of try block and catch block as shown below?
44. What is the importance of reflection in Java? 64. Can you call a constructor of a class inside the another constructor?
45. What are the different ways of threads usage? 65. Contiguous memory locations are usually used for storing actual values in an
array but not in ArrayList. Explain.
46. What are the different types of Thread Priorities in Java? And what is the default
priority of a thread assigned by JVM? 66. Why does the java array index start with 0?
47. What is the difference between the program and the process? 67. Why is the remove method faster in the linked list than in an array?
48. What is the difference between the ‘throw’ and ‘throws’ keyword in java? 68. How many overloaded add() and addAll() methods are available in the List
interface? Describe the need and uses.
49. What are the differences between constructor and method of a class in Java?
69. How does the size of ArrayList grow dynamically? And also state how it is
50. Identify the output of the below java program and Justify your answer.
implemented internally.
51. Java works as “pass by value” or “pass by reference” phenomenon?
52. What is the ‘IS-A ‘ relationship in OOPs java? Java Advanced Interview Questions
53. Which among String or String Buffer should be preferred when there are lot of 70. Although inheritance is a popular OOPs concept, it is less advantageous than
updates required to be done in the data? composition. Explain.
54. How to not allow serialization of attributes of a class in Java? 71. What is the difference between ‘>>’ and ‘>>>’ operators in java?
55. What happens if the static modifier is not included in the main method 72. What are Composition and Aggregation? State the difference.
signature in Java?
73. How is the creation of a String using new() different from that of a literal?
56. Consider the below program, identify the output, and also state the reason for
74. How is the ‘new’ operator different from the ‘newInstance()’ operator in java?
that.
75. Is exceeding the memory limit possible in a program despite having a garbage
57. Can we make the main() thread a daemon thread?
collector?
58. What happens if there are multiple main methods inside one class in Java?
76. Why is synchronization necessary? Explain with the help of a relevant example.
Let's get Started Go through all the questions to enhance your chances of performing well in the
interviews. The questions will revolve around the basic, core & advanced
fundamentals of Java.
So, let’s dive deep into the plethora of useful Java Interview questions and answers
Do you have what it takes to ace a Java Interview? We are here to help you in for freshers and experienced candidates in depth.
consolidating your knowledge and concepts in Java. Before we begin, let's
understand what Java is all about.
Java Basic Interview Questions
What is Java? 1. Why is Java a platform independent language?
Java is the high-level programming language that was developed by James Gosling in Java language was developed in such a way that it does not depend on any
the year 1982. It is based on the principles of object-oriented programming and can hardware or so ware due to the fact that the compiler compiles the code and then
be used to develop large-scale applications. Learn More. converts it to platform-independent byte code which can be run on multiple systems.
The following article will cover all the popular Core Java interview questions, String The only condition to run that byte code is for the machine to have a runtime
Handling interview questions, java 8 interview questions, java multithreading environment (JRE) installed in it
interview questions, java OOPs interview questions, java exception handling
interview questions, collections interview questions, and some frequently asked java 2. Why is Java not a pure object oriented language?
coding interview questions.
Java supports primitive data types - byte, boolean, char, short, int, float, long, and
double and hence it is not a pure object oriented language.
Java and Java Projects Complete (A-Z) Tutorial | Learn Jav…
Jav…
Main and PrintArray is the method that will be available in the stack area and as well 6. Pointers are used in C/ C++. Why does Java not make use of
as the variables declared that will also be in the stack area. pointers?
And the Object (Integer Array of size 10) we have created, will be available in the Heap
area because that space will be allocated to the program during runtime. Pointers are quite complicated and unsafe to use by beginner programmers. Java
focuses on code simplicity, and the usage of pointers can make it challenging. Pointer
utilization can also cause potential errors. Moreover, security is also compromised if
4. Can java be said to be the complete object-oriented
pointers are used because the users can directly access memory with the help of
programming language? pointers.
Data Encapsulation is an Object-Oriented Programming concept of hiding the JIT stands for Just-In-Time and it is used for improving the performance during
data attributes and their behaviours in a single unit. run time. It does the task of compiling parts of byte code having similar
It helps developers to follow modularity while developing so ware by ensuring functionality at the same time thereby reducing the amount of compilation time
that each object is independent of other objects by having its own methods, for the code to run.
attributes, and functionalities. The compiler is nothing but a translator of source code to machine-executable
It is used for the security of the private properties of an object and hence serves code. But what is special about the JIT compiler? Let us see how it works:
the purpose of data hiding. First, the Java source code (.java) conversion to byte code (.class) occurs
with the help of the javac compiler.
Then, the .class files are loaded at run time by JVM and with the help of an
interpreter, these are converted to machine understandable code.
JIT compiler is a part of JVM. When the JIT compiler is enabled, the JVM
analyzes the method calls in the .class files and compiles them to get more
efficient and native code. It also ensures that the prioritized method calls
are optimized.
Once the above step is done, the JVM executes the optimized code directly
instead of interpreting the code again. This increases the performance and
speed of the execution.
11. Can you tell the difference between equals() method and for (;;)
{
equality operator (==) in Java? // Business logic
// Any break logic
}
Note:
In the cases where the equals method is not overridden in a class, then the class 13. Briefly explain the concept of constructor overloading
uses the default implementation of the equals method that is closest to the
parent class. Constructor overloading is the process of creating multiple constructors in the class
Object class is considered as the parent class of all the java classes. The consisting of the same name with a difference in the constructor parameters.
implementation of the equals method in the Object class uses the == operator to Depending upon the number of parameters and their corresponding types,
compare two objects. This default implementation can be overridden as per the distinguishing of the different types of constructors is done by the compiler.
business logic.
class Main {
public static void main(String args[]) {
System.out.println(" Main Method");
}
public static void main(int[] args){
System.out.println("Overloaded Integer array Main Method");
}
public static void main(char[] args){
Three constructors are defined here but they differ on the basis of parameter type System.out.println("Overloaded Character array Main Method");
and their numbers. }
public static int main(double[] args){
System.out.println("Overloaded Double array Main Method");
14. Define Copy constructor in java. }
public static void main(float args){
System.out.println("Overloaded float Main Method");
Copy Constructor is the constructor used when we want to initialize the value to the }
}
new object from the old object of the same class.
Both the functions have the same name but differ in the number of arguments. The
16. Comment on method overloading and overriding by citing first method calculates the area of the rectangle, whereas the second method
relevant examples. calculates the area of a cuboid.
In Java, method overloading is made possible by introducing different methods in Method overriding is the concept in which two methods having the same method
the same class consisting of the same name. Still, all the functions differ in the signature are present in two different classes in which an inheritance relationship is
number or type of parameters. It takes place inside a class and enhances program present. A particular method implementation (already present in the base class) is
readability. possible for the derived class by using method overriding.
Let’s give a look at this example:
The only difference in the return type of the method does not promote method
overloading. The following example will furnish you with a clear picture of it. class HumanBeing {
public int walk (int distance, int time) {
int speed = distance / time;
class OverloadingHelp { return speed;
public int findarea (int l, int b) { }
int var1; }
var1 = l * b; class Athlete extends HumanBeing {
return var1; public int walk(int distance, int time) {
} int speed = distance / time;
public int findarea (int l, int b, int h) { speed = speed * 2;
int var2; return speed;
var2 = l * b * h; }
return var2; }
}
}
Both class methods have the name walk and the same parameters, distance, and final variable:
time. If the derived class method is called, then the base class method walk gets When a variable is declared as final in Java, the value can’t be modified
overridden by that of the derived class. once it has been assigned.
If any value has not been assigned to that variable, then it can be assigned
17. A single try block and multiple catch blocks can co-exist in a only by the constructor of the class.
Java Program. Explain. final method:
A method declared as final cannot be overridden by its children's classes.
Yes, multiple catch blocks can exist but specific approaches should come prior to the
A constructor cannot be marked as final because whenever a class is
general approach because only the first catch block satisfying the catch condition is
inherited, the constructors are not inherited. Hence, marking it final
executed. The given code illustrates the same:
doesn't make sense. Java throws compilation error saying - modifier final
not allowed here
public class MultipleCatch {
public static void main(String args[]) { final class:
try {
int n = 1000, x = 0; No classes can be inherited from the class declared as final. But that final
int arr[] = new int[n];
for (int i = 0; i <= n; i++) {
class can extend other classes for its usage.
arr[i] = i / x;
}
}
19. Do final, finally and finalize keywords have the same
catch (ArrayIndexOutOfBoundsException exception) {
System.out.println("1st block = ArrayIndexOutOfBoundsException"); function?
}
catch (ArithmeticException exception) {
System.out.println("2nd block = ArithmeticException");
All three keywords have their own utility while programming.
}
catch (Exception exception) { Final: If any restriction is required for classes, variables, or methods, the final
System.out.println("3rd block = Exception"); keyword comes in handy. Inheritance of a final class and overriding of a final method
}
} is restricted by the use of the final keyword. The variable value becomes fixed a er
} incorporating the final keyword. Example:
Here, the second catch block will be executed because of division by 0 (i / x). In case x final int a=100;
was greater than 0 then the first catch block will execute because for loop runs till i = a = 0; // error
n and array index are till n-1.
The second statement will throw an error.
18. Explain the use of final keyword in variable, method and Finally: It is the block present in a program where all the codes written inside it get
class. executed irrespective of handling of exceptions. Example:
In Java, the final keyword is used as defining something as constant /final and
represents the non-access modifier.
Finalize: Prior to the garbage collection of an object, the finalize method is called so
that the clean-up activity is implemented. Example: The above code will generate a compile-time error at Line 7 saying - [error: variable i
might already have been initialized]. It is because variable ‘i’ is the final variable.
public static void main(String[] args) {
And final variables are allowed to be initialized only once, and that was already done
String example = new String("InterviewBit"); on line no 5.
example = null;
System.gc(); // Garbage collector called
}
public void finalize() {
22. When can you use super keyword?
// Finalize called
} The super keyword is used to access hidden fields and overridden methods or
attributes of the parent class.
Following are the cases when this keyword can be used:
20. Is it possible that the ‘finally’ block will not be executed? If
Accessing data members of parent class when the member names of the
yes then list the case. class and its child subclasses are same.
Yes. It is possible that the ‘finally’ block will not be executed. The cases are- To call the default and parameterized constructor of the parent class inside
the child class.
Suppose we use System.exit() in the above statement. Accessing the parent class methods when the child classes have overridden
If there are fatal errors like Stack overflow, Memory access error, etc. them.
The following example demonstrates all 3 cases when a super keyword is used.
21. Identify the output of the java program and state the
reason.
The main method is always static because static members are those methods that
public class Parent{
protected int num = 1;
belong to the classes, not to an individual object. So if the main method will not be
static then for every object, It is available. And that is not acceptable by JVM. JVM
Parent(){
System.out.println("Parent class default constructor."); calls the main method based on the class name itself. Not by creating the object.
}
Because there must be only 1 main method in the java program as the execution
Parent(String x){
System.out.println("Parent class parameterised constructor.");
starts from the main method. So for this reason the main method is static.
}
The main objective of this process is to free up the memory space occupied by the Now by doing this what will happen is the new reference is created with the name
unnecessary and unreachable objects during the Java program execution by deleting obj2 and that will point to the same memory location.
those unreachable objects.
Deep Copy - In a deep copy, we create a new object and copy the old object
This ensures that the memory resource is used efficiently, but it provides no value to the new object. Example -
guarantee that there would be sufficient memory for the program execution.
Rectangle obj3 = new Rectangle();
28. What is a ClassLoader? Obj3.length = obj1.length;
Obj3.breadth = obj1.breadth;
Java Classloader is the program that belongs to JRE (Java Runtime Both these objects will point to the memory location as stated below -
Environment). The task of ClassLoader is to load the required classes and
interfaces to the JVM when required.
Example- To get input from the console, we require the scanner class. And the
Scanner class is loaded by the ClassLoader.
We can see that in the above code, if we change the values of object1, then the After Changing the value of object 1, the object2 will be -
Object2 Length = 5, Object2 Breadth = 3
object2 values also get changed. It is because of the reference.
Now, if we change the code to deep copy, then there will be no effect on object2 if it is Now we see that we need to write the number of codes for this deep copy. So to
of type deep copy. Consider some snippets to be added in the above code. reduce this, In java, there is a method called clone().
The clone() will do this deep copy internally and return a new object. And to do this
we need to write only 1 line of code. That is - Rectangle obj2 = obj1.clone();
class WaterJug{ 33. Which of the below generates a compile-time error? State
private int waterQuantity = 500;
private WaterJug(){} the reason.
private WaterJug object = null;
Storage area: In string, the String pool serves as the storage area. For Availability of methods: Only abstract methods are available in interfaces,
StringBuilder and StringBuffer, heap memory is the storage area. whereas non-abstract methods can be present along with abstract methods in
Mutability: A String is immutable, whereas both the StringBuilder and abstract classes.
StringBuffer are mutable. Variable types: Static and final variables can only be declared in the case of
Efficiency: It is quite slow to work with a String. However, StringBuilder is the interfaces, whereas abstract classes can also have non-static and non-final
fastest in performing operations. The speed of a StringBuffer is more than a variables.
String and less than a StringBuilder. (For example appending a character is Inheritance: Multiple inheritances are facilitated by interfaces, whereas abstract
fastest in StringBuilder and very slow in String because a new memory is classes do not promote multiple inheritances.
required for the new String with appended character.) Data member accessibility: By default, the class data members of interfaces
Thread-safe: In the case of a threaded environment, StringBuilder and are of the public- type. Conversely, the class members for an abstract class can
StringBuffer are used whereas a String is not used. However, StringBuilder is be protected or private also.
suitable for an environment with a single thread, and a StringBuffer is suitable Implementation: With the help of an abstract class, the implementation of an
for multiple threads. interface is easily possible. However, the converse is not true;
Syntax: Abstract class example:
// String
String first = "InterviewBit"; public abstract class Athlete {
String second = new String("InterviewBit"); public abstract void walk();
// StringBuffer }
StringBuffer third = new StringBuffer("InterviewBit");
// StringBuilder
StringBuilder fourth = new StringBuilder("InterviewBit"); Interface example:
abstract final class InterviewBit{ 38. In Java, static as well as private method overriding is
2. public abstract void printMessage();
3. } possible. Comment on the statement.
4. class ScalarAcademy extends InterviewBit{
5. public void printMessage(){
6. System.out.println("Welcome to Scalar Academy By InterviewBit"); The statement in the context is completely False. The static methods have no
7. } relevance with the objects, and these methods are of the class level. In the case of a
8. }
9. class ScalarTopics extends ScalarAcademy{ child class, a static method with a method signature exactly like that of the parent
10.
11.
public void printMessage(){
System.out.println("Welcome to Scalar Topics By Scalar Academy");
class can exist without even throwing any compilation error.
12. }
13. } The phenomenon mentioned here is popularly known as method hiding, and
public class Main{ overriding is certainly not possible. Private method overriding is unimaginable
public static void main(String[] args) {
InterviewBit ib = new ScalarTopics(); because the visibility of the private method is restricted to the parent class only. As a
ib.printMessage(); result, only hiding can be facilitated and not overriding.
}
}
39. What makes a HashSet different from a TreeSet?
The above program will give a compile-time error. The compiler will throw 2 errors in
this. Although both HashSet and TreeSet are not synchronized and ensure that duplicates
are not present, there are certain properties that distinguish a HashSet from a
[Illegal Combination of modifiers: abstract and final] at line 1. TreeSet.
[Cannot inherit from final ‘InterviewBit’] at line 4.
Implementation: For a HashSet, the hash table is utilized for storing the
It is because abstract classes are incomplete classes that need to be inherited for
elements in an unordered manner. However, TreeSet makes use of the red-black
making their concrete classes. And on the other hand, the final keywords in class are
tree to store the elements in a sorted manner.
used for avoiding inheritance. So these combinations are not allowed in java.
Complexity/ Performance: For adding, retrieving, and deleting elements, the
time amortized complexity is O(1) for a HashSet. The time complexity for
37. What is a Comparator in java? performing the same operations is a bit higher for TreeSet and is equal to O(log
Consider the example where we have an ArrayList of employees like( EId, Ename, n). Overall, the performance of HashSet is faster in comparison to TreeSet.
Salary), etc. Now if we want to sort this list of employees based on the names of Methods: hashCode() and equals() are the methods utilized by HashSet for
employees. Then that is not possible to sort using the Collections.sort() method. We making comparisons between the objects. Conversely, compareTo() and
need to provide something to the sort() function depending on what values we have compare() methods are utilized by TreeSet to facilitate object comparisons.
to perform sorting. Then in that case a comparator is used. Objects type: Heterogeneous and null objects can be stored with the help of
HashSet. In the case of a TreeSet, runtime exception occurs while inserting
Comparator is the interface in java that contains the compare method. And by heterogeneous objects or null objects.
overloading the compare method, we can define that on what basis we need to
compare the values. 40. Why is the character array preferred over string for storing
confidential information?
Using reflection has its own cons: Implementing a thread using the method of Runnable interface is more
Speed — Method invocations due to reflection are about three times slower preferred and advantageous as Java does not have support for multiple
than the direct method calls. inheritances of classes.
Type safety — When a method is invoked via its reference wrongly using start() method is used for creating a separate call stack for the thread
reflection, invocation fails at runtime as it is not detected at compile/load execution. Once the call stack is created, JVM calls the run() method for
time. executing the thread in that call stack.
Traceability — Whenever a reflective method fails, it is very difficult to find
the root cause of this failure due to a huge stack trace. One has to deep dive 46. What are the different types of Thread Priorities in Java?
into the invoke() and proxy() method logs to identify the root cause. And what is the default priority of a thread assigned by
Hence, it is advisable to follow solutions that don't involve reflection and use JVM?
this method as a last resort.
There are a total of 3 different types of priority available in Java.
45. What are the different ways of threads usage? MIN_PRIORITY: It has an integer value assigned with 1.
MAX_PRIORITY: It has an integer value assigned with 10.
We can define and implement a thread in java using two ways:
NORM_PRIORITY: It has an integer value assigned with 5.
Extending the Thread class
In Java, Thread with MAX_PRIORITY gets the first chance to execute. But the default
class InterviewBitThreadExample extends Thread{
priority for any thread is NORM_PRIORITY assigned by JVM.
public void run(){
System.out.println("Thread runs...");
} 47. What is the difference between the program and the
public static void main(String args[]){
InterviewBitThreadExample ib = new InterviewBitThreadExample(); process?
ib.start();
}
} A program can be defined as a line of code written in order to accomplish a
particular task. Whereas the process can be defined as the programs which are
Implementing the Runnable interface under execution.
A program doesn't execute directly by the CPU. First, the resources are allocated
class InterviewBitThreadExample implements Runnable{ to the program and when it is ready for execution then it is a process.
public void run(){
}
System.out.println("Thread runs...");
48. What is the difference between the ‘throw’ and ‘throws’
public static void main(String args[]){
Thread ib = new Thread(new InterviewBitThreadExample()); keyword in java?
ib.start();
}
} The ‘throw’ keyword is used to manually throw the exception to the calling
method.
And the ‘throws’ keyword is used in the function definition to inform the calling
method that this method throws the exception. So if you are calling, then you
have to handle the exception.
Example -
Constructor Method
class Main {
public static int testExceptionDivide(int a, int b) throws ArithmeticException{
if(a == 0 || b == 0) Method is used for
Constructor is used for initializing the
throw new ArithmeticException(); exposing the
return a/b; object state.
} object's behavior.
public static void main(String args[]) {
try{
testExceptionDivide(10, 0); Method should
}
catch(ArithmeticException e){ have a return
//Handle the exception type. Even if it
} Constructor has no return type.
} does not return
} anything, return
type is void.
Here in the above snippet, the method testExceptionDivide throws an exception. So
if the main method is calling it then it must have handled the exception. Otherwise, Method has to be
the main method can also throw the exception to JVM. Constructor gets invoked implicitly. invoked on the
And the method testExceptionDivide 'throws’ the exception based on the condition. object explicitly.
49. What are the differences between constructor and method If a method is not
If the constructor is not defined, then a
defined, then the
of a class in Java? default constructor is provided by the
compiler does not
java compiler.
provide it.
Case 1: When the object is pointed to another location: In this case, the changes
50. Identify the output of the below java program and Justify made to that object do not get reflected the original object before it was passed
your answer. to the method as the reference points to another location.
For example:
class Main {
public static void main(String args[]) {
Scaler s = new Scaler(5); class InterviewBitTest{
} int num;
} InterviewBitTest(int x){
class InterviewBit{ num = x;
InterviewBit(){ }
System.out.println(" Welcome to InterviewBit "); InterviewBitTest(){
} num = 0;
} }
class Scaler extends InterviewBit{ }
Scaler(){ class Driver {
System.out.println(" Welcome to Scaler Academy "); public static void main(String[] args)
} {
Scaler(int x){ //create a reference
this(); InterviewBitTest ibTestObj = new InterviewBitTest(20);
super(); //Pass the reference to updateObject Method
System.out.println(" Welcome to Scaler Academy 2"); updateObject(ibTestObj);
} //After the updateObject is executed, check for the value of num in the object.
} System.out.println(ibTestObj.num);
}
public static void updateObject(InterviewBitTest ibObj)
The above code will throw the compilation error. It is because the super() is used to {
// Point the object to new reference
call the parent class constructor. But there is the condition that super() must be the ibObj = new InterviewBitTest();
first statement in the block. Now in this case, if we replace this() with super() then // Update the value
ibObj.num = 50;
also it will throw the compilation error. Because this() also has to be the first }
}
statement in the block. So in conclusion, we can say that we cannot use this() and Output:
super() keywords in the same block. 20
51. Java works as “pass by value” or “pass by reference” Case 2: When object references are not modified: In this case, since we have the
phenomenon? copy of reference the main object pointing to the same memory location, any
changes in the content of the object get reflected in the original object.
Java always works as a “pass by value”. There is nothing called a “pass by reference” For example:
in Java. However, when the object is passed in any method, the address of the value
is passed due to the nature of object handling in Java. When an object is passed, a
copy of the reference is created by Java and that is passed to the method. The
objects point to the same memory location. 2 cases might happen inside the
method:
class InterviewBitTest{
int num;
InterviewBitTest(int x){
num = x;
}
InterviewBitTest(){
num = 0;
}
}
class Driver{
public static void main(String[] args)
{
//create a reference
InterviewBitTest ibTestObj = new InterviewBitTest(20);
//Pass the reference to updateObject Method
updateObject(ibTestObj);
//After the updateObject is executed, check for the value of num in the object.
System.out.println(ibTestObj.num);
} So here ‘IS-A’ Relationship formed. [ SmartTV ‘IS-A’ TV ].
public static void updateObject(InterviewBitTest ibObj)
{
// no changes are made to point the ibObj to new location
// Update the value of num
53. Which among String or String Buffer should be preferred
}
ibObj.num = 50;
when there are lot of updates required to be done in the
}
Output:
data?
50
StringBuffer is mutable and dynamic in nature whereas String is immutable. Every
updation / modification of String creates a new String thereby overloading the string
52. What is the ‘IS-A ‘ relationship in OOPs java? pool with unnecessary objects. Hence, in the cases of a lot of updates, it is always
preferred to use StringBuffer as it will reduce the overhead of the creation of multiple
‘IS-A’ relationship is another name for inheritance. When we inherit the base class String objects in the string pool.
from the derived class, then it forms a relationship between the classes. So that
relationship is termed an ‘IS-A’ Relationship.
54. How to not allow serialization of attributes of a class in
Example - Consider a Television (Typical CRT TV). Now another Smart TV that is Java?
inherited from television class. So we can say that the Smart iv is also a TV. Because
CRT TV things can also be done in the Smart TV. In order to achieve this, the attribute can be declared along with the usage of
transient keyword as shown below:
In java multithreading, the main() threads are always non-daemon threads. And there
public class InterviewBitExample {
is no way we can change the nature of the non-daemon thread to the daemon
private transient String someInfo; thread.
private String name;
private int id;
// :
// Getters setters
58. What happens if there are multiple main methods inside one
}
// : class in Java?
The program can't compile as the compiler says that the method has been already
In the above example, all the fields except someInfo can be serialized. defined inside the class.
55. What happens if the static modifier is not included in the 59. What do you understand by Object Cloning and how do you
main method signature in Java? achieve it in Java?
There wouldn't be any compilation error. But then the program is run, since the JVM
It is the process of creating an exact copy of any object. In order to support this,
cant map the main method signature, the code throws “NoSuchMethodError” error
a java class has to implement the Cloneable interface of java.lang package and
at the runtime.
override the clone() method provided by the Object class the syntax of which is:
56. Consider the below program, identify the output, and also protected Object clone() throws CloneNotSupportedException{
state the reason for that. }
return (Object)super.clone();
public class Main{ In case the Cloneable interface is not implemented and just the method is
public static void main(String[] args) {
System.out.println(" Hello. Main Method. "); overridden, it results in CloneNotSupportedException in Java.
}
public static void main(int[] args) {
System.out.println(" Hello. Main Method2. "); 60. How does an exception propagate in the code?
}
} When an exception occurs, first it searches to locate the matching catch block. In
case, the matching catch block is located, then that block would be executed. Else,
The output of the above program will be Hello. Main Method. This is because JVM the exception propagates through the method call stack and goes into the caller
will always call the main method based on the definition it already has. Doesn't method where the process of matching the catch block is performed. This
matter how many main methods we overload it will only execute one main method propagation happens until the matching catch block is found. If the match is not
based on its declaration in JVM. found, then the program gets terminated in the main method.
63. Will the finally block get executed when the return
statement is written at the end of try block and catch block
as shown below?
finally block will be executed irrespective of the exception or not. The only case
61. How do exceptions affect the program if it doesn't handle where finally block is not executed is when it encounters ‘System.exit()’ method
them? anywhere in try/catch block.
Exceptions are runtime errors. Suppose we are making an android application with
java. And it all works fine but there is an exceptional case when the application tries
64. Can you call a constructor of a class inside the another
to get the file from storage and the file doesn’t exist (This is the case of exception in constructor?
java). And if this case is not handled properly then the application will crash. This will
Yes, the concept can be termed as constructor chaining and can be achieved using
be a bad experience for users. This is the type of error that cannot be controlled by
this() .
the programmer. But programmers can take some steps to avoid this so that the
application won’t crash. The proper action can be taken at this step.
However, the same does not apply to the arrays. Object or primitive type values can
65. Contiguous memory locations are usually used for storing be stored in arrays in contiguous memory locations, hence every element does not
actual values in an array but not in ArrayList. Explain. require any reference to the next element.
In the case of ArrayList, data storing in the form of primitive data types (like int, float,
etc.) is not possible. The data members/objects present in the ArrayList have
references to the objects which are located at various sites in the memory. Thus,
storing of actual objects or non-primitive data types (like Integer, Double, etc.) takes
place in various memory locations.
It is because the 0 index array avoids the extra arithmetic operation to calculate the Now if we apply the same formula here. Then we get - 116 as the starting address of
memory address. the 4th index. Which is wrong. Then we need to apply formula - [Base Address +
Example - Consider the array and assume each element takes 4-byte memory space. ((index-1) * no_of_bytes)].
Then the address will be like this - And for calculating this, an extra arithmetic operation has to be performed. And
consider the case where millions of addresses need to be calculated, this causes
complexity. So to avoid this, ) the index array is supported by java.
67. Why is the remove method faster in the linked list than in an
array?
In the linked list, we only need to adjust the references when we want to delete the
element from either end or the front of the linked list. But in the array, indexes are
used. So to manage proper indexing, we need to adjust the values from the array So
this adjustment of value is costlier than the adjustment of references.
Now if we want to access index 4. Then internally java calculates the address using Example - To Delete from the front of the linked list, internally the references
the formula- adjustments happened like this.
[Base Address + (index * no_of_bytes)]. So according to this. The starting address of
the index 4 will be - [100 + (4*4)] = 116. And exactly that's what the address is
calculated.
Now consider the same with 1 index Array -
The only thing that will change is that the head pointer will point to the head’s next
node. And delete the previous node. That is the constant time operation.
69. How does the size of ArrayList grow dynamically? And also
state how it is implemented internally.
ArrayList is implemented in such a way that it can grow dynamically. We don't need
to specify the size of ArrayList. For adding the values in it, the methodology it uses is -
1. Consider initially that there are 2 elements in the ArrayList. [2, 3].
Then the new value will be inserted into it. [2, 3, 4, null]. And for the next time,
the extra space will be available for the value to be inserted.
2. If we need to add the element into this. Then internally what will happen is-
ArrayList will allocate the new ArrayList of Size (current size + half of the current
size). And add the old elements into the new. Old - [2, 3], New - [2, 3, null, null].
3. This process continues and the time taken to perform all of these is considered as
the amortized constant time.
This is how the ArrayList grows dynamically. And when we delete any entry from the
ArrayList then the following steps are performed -
1. It searches for the element index in the array. Searching takes some time. Typically
it’s O(n) because it needs to search for the element in the entire array.
Multiple-inheritance is not possible in Java. Classes can only extend from one
superclass. In cases where multiple functionalities are required, for example - to
read and write information into the file, the pattern of composition is preferred.
The writer, as well as reader functionalities, can be made use of by considering
them as the private members.
Composition assists in attaining high flexibility and prevents breaking of
encapsulation.
Unit testing is possible with composition and not inheritance. When a developer
wants to test a class composing a different class, then Mock Object can be
2. A er searching the element, it needs to shi the element from the right side to fill created for signifying the composed class to facilitate testing. This technique is
the index. not possible with the help of inheritance as the derived class cannot be tested
without the help of the superclass in inheritance.
The loosely coupled nature of composition is preferable over the tightly coupled
nature of inheritance.
Let’s take an example:
package comparison;
public class Top {
public int start() {
return 0;
}
}
class Bottom extends Top {
public int stop() {
return 0;
So this is how the elements are deleted from the ArrayList internally. Similarly, the }
search operations are also implemented internally as defined in removing elements }
If the new implementation of the Top class is followed, a compile-time error is bound ‘>>>’ Operator : 8 >>> 1 (Shi by one bit) =
to occur in the Bottom class. Incompatible return type is there for the Top.stop() Num1 = 00000000 00000000 00000000 00000100
function. Changes have to be made to either the Top or the Bottom class to ensure Num2 = 01111111 11111111 11111111 11111100
compatibility. However, the composition technique can be utilized to solve the given
problem: 72. What are Composition and Aggregation? State the
class Bottom {
difference.
Top par = new Top();
public int stop() { Composition, and Aggregation help to build (Has - A - Relationship) between classes
par.start();
par.stop();
and objects. But both are not the same in the end. Let’s understand with the help of
return 0; an example.
}
} Consider the University as a class that has some departments in it. So the
university will be the container object. And departments in it will contain
objects. Now in this case, if the container object destroys then the contained
71. What is the difference between ‘>>’ and ‘>>>’ operators in
objects will also get destroyed automatically. So here we can say that there is a
java? strong association between the objects. So this Strong Association is called
These 2 are the bitwise right shi operators. Although both operators look similar. Composition.
But there is a minimal difference between these two right shi operators. Now consider one more example. Suppose we have a class department and
there are several professors' objects there in the department. Now if the
‘>>’ Bitwise Right Shi Operator- This operator shi s each bit to its right department class is destroyed then the professor's object will become free to
position. And this maintains the signed bit. bind with other objects. Because container objects (Department) only hold the
‘>>>’ Bitwise Right Shi Operator with trailing zero- This operator also shi s references of contained objects (Professor’s). So here is the weak association
each bit to its right. But this doesn’t maintain the signed bit. This operator between the objects. And this weak association is called Aggregation.
makes the Most significant bit to 0.
Example- Num1 = 8, Num2 = -8. 73. How is the creation of a String using new() different from
So the binary form of these numbers are - that of a literal?
The checking() function will return true as the same content is referenced by both the
variables.
The ‘newInstance()’ keyword throws an exception that we need to handle. It is Concurrent execution of different processes is made possible by synchronization.
because there are chances that the class definition doesn’t exist, and we get the class When a particular resource is shared between many threads, situations may arise in
name from runtime. So it will throw an exception. which multiple threads require the same shared resource.
Synchronization assists in resolving the issue and the resource is shared by a single
75. Is exceeding the memory limit possible in a program despite thread at a time. Let’s take an example to understand it more clearly. For example,
having a garbage collector? you have a URL and you have to find out the number of requests made to it. Two
simultaneous requests can make the count erratic.
Yes, it is possible for the program to go out of memory in spite of the presence of a
garbage collector. Garbage collection assists in recognizing and eliminating those No synchronization:
objects which are not required in the program anymore, in order to free up the
resources used by them. package anonymous;
public class Counting {
private int increase_counter;
In a program, if an object is unreachable, then the execution of garbage collection public int increase() {
takes place with respect to that object. If the amount of memory required for increase_counter = increase_counter + 1;
return increase_counter;
creating a new object is not sufficient, then memory is released for those objects }
which are no longer in the scope with the help of a garbage collector. The memory }
limit is exceeded for the program when the memory released is not enough for
creating new objects.
Moreover, exhaustion of the heap memory takes place if objects are created in such a
manner that they remain in the scope and consume memory. The developer should
make sure to dereference the object a er its work is accomplished. Although the
garbage collector endeavors its level best to reclaim memory as much as possible,
memory limits can still be exceeded.
Let’s take a look at the following example:
78. What will be the output of the below java program and
define the steps of Execution of the java program with the
help of the below code?
If a thread Thread1 views the count as 10, it will be increased by 1 to 11, then the
thread Thread2 will view the count as 11, it will be increased by 1 to 12. Thus,
consistency in count values takes place.
2. In the next step, it will execute the static block and assign the value in static System.out.println() is used to print the message on the console. System - It is a
variables. class present in java.lang package. Out is the static variable of type PrintStream
class present in the System class. println() is the method present in the PrintStream
First static block it will print and because execution from top to bottom and
class.
original value in j is not assigned. So it will print the default value of 0.
A er executing static block 1. It will execute the static method_1 because it is So if we justify the statement, then we can say that if we want to print anything on
called from the static block 1. the console then we need to call the println() method that was present in
Then it will assign the original value of 5 in the j variable. And executes the PrintStream class. And we can call this using the output object that is present in the
remaining static block. System class.
3. Now it will execute the main method. In which it will create an object for the class
InterviewBit. And then the execution of instances will happen. 80. Can you explain the Java thread lifecycle?
4. Identify the instance variables and blocks from top to bottom. Java thread life cycle is as follows:
int i. New – When the instance of the thread is created and the start() method has not
Instance block 1. been invoked, the thread is considered to be alive and hence in the NEW state.
Instance method_1. Runnable – Once the start() method is invoked, before the run() method is
Like a static variable, the instance variable also has been initialized with the default called by JVM, the thread is said to be in RUNNABLE (ready to run) state. This
value 0 and will be in the state of reading and writing indirectly. state can also be entered from the Waiting or Sleeping state of the thread.
Running – When the run() method has been invoked and the thread starts its
5. It will execute the instance methods and assign the original value to the instance execution, the thread is said to be in a RUNNING state.
variable. Non-Runnable (Blocked/Waiting) – When the thread is not able to run despite
Prints the Instance block 1. And the current value of i is not assigned till now, so the fact of its aliveness, the thread is said to be in a NON-RUNNABLE state.
it will print 0. Ideally, a er some time of its aliveness, the thread should go to a runnable state.
Assign the original value to i. Then print instance block 2. And a er that instance A thread is said to be in a Blocked state if it wants to enter synchronized
method will be called and printed because it is being called in the instance code but it is unable to as another thread is operating in that synchronized
block. block on the same object. The first thread has to wait until the other thread
6. And at the last step, the constructor will be invoked and the lines will be executed exits the synchronized block.
in the constructor. A thread is said to be in a Waiting state if it is waiting for the signal to
execute from another thread, i.e it waits for work until the signal is
This is how the java program gets executed. received.
Terminated – Once the run() method execution is completed, the thread is said
79. Define System.out.println(). to enter the TERMINATED step and is considered to not be alive.
The following flowchart clearly explains the lifecycle of the thread in Java.
The length method returns the number of Unicode units of the String. Let's
import java.util.HashSet;
import java.util.Set; understand what Unicode units are and what is the confusion below.
We know that Java uses UTF-16 for String representation. With this Unicode, we
public class IBDoubleBraceDemo{
public static void main(String[] args){ need to understand the below two Unicode related terms:
Set<String> stringSets = new HashSet<String>()
{ Code Point: This represents an integer denoting a character in the code
{ space.
add("set1");
add("set2"); Code Unit: This is a bit sequence used for encoding the code points. In order
}
add("set3"); to do this, one or more units might be required for representing a code
}; point.
doSomething(stringSets); Under the UTF-16 scheme, the code points were divided logically into 17 planes
} and the first plane was called the Basic Multilingual Plane (BMP). The BMP has
private static void doSomething(Set<String> stringSets){ classic characters - U+0000 to U+FFFF. The rest of the characters- U+10000 to
System.out.println(stringSets);
}
U+10FFFF were termed as the supplementary characters as they were contained
} in the remaining planes.
The code points from the first plane are encoded using one 16-bit code unit
In the above example, we see that the stringSets were initialized by using double The code points from the remaining planes are encoded using two code
braces. units.
The first brace does the task of creating an anonymous inner class that has the Now if a string contained supplementary characters, the length function would count
capability of accessing the parent class’s behavior. In our example, we are that as 2 units and the result of the length() function would not be as per what is
creating the subclass of HashSet so that it can use the add() method of HashSet. expected.
The second braces do the task of initializing the instances.
In other words, if there is 1 supplementary character of 2 units, the length of that
Care should be taken while initializing through this method as the method involves SINGLE character is considered to be TWO - Notice the inaccuracy here? As per the
the creation of anonymous inner classes which can cause problems during the java documentation, it is expected, but as per the real logic, it is inaccurate.
garbage collection or serialization processes and may also result in memory leaks.
88. What is the output of the below code and why?
87. Why is it said that the length() method of String class
doesn't return accurate results? public class InterviewBit{
public static void main(String[] args)
{
System.out.println('b' + 'i' + 't');
}
}
“bit” would have been the result printed if the letters were used in double-quotes (or Third Approach: Island of Isolation Approach: When 2 reference variables pointing to
the string literals). But the question has the character literals (single quotes) being instances of the same class, and these variables refer to only each other and the
used which is why concatenation wouldn't occur. The corresponding ASCII values of objects pointed by these 2 variables don't have any other references, then it is said to
each character would be added and the result of that sum would be printed. have formed an “Island of Isolation” and these 2 objects are eligible for GC.
The ASCII values of ‘b’, ‘i’, ‘t’ are:
public class IBGarbageCollect {
‘b’ = 98 IBGarbageCollect ib;
‘i’ = 105 public static void main(String [] str){
IBGarbageCollect ibgc1 = new IBGarbageCollect();
‘t’ = 116 IBGarbageCollect ibgc2 = new IBGarbageCollect();
ibgc1.ib = ibgc2; //ibgc1 points to ibgc2
98 + 105 + 116 = 319 ibgc2.ib = ibgc1; //ibgc2 points to ibgc1
ibgc1 = null;
Hence 319 would be printed. ibgc2 = null;
/*
* We see that ibgc1 and ibgc2 objects refer
89. What are the possible ways of making object eligible for * to only each other and have no valid
* references- these 2 objects for island of isolcation - eligible for GC
garbage collection (GC) in Java? }
*/
}
First Approach: Set the object references to null once the object creation purpose is
served.
90. In the below Java Program, how many objects are eligible
public class IBGarbageCollect {
public static void main (String [] args){
for garbage collection?
String s1 = "Some String";
// s1 referencing String object - not yet eligible for GC
s1 = null; // now s1 is eligible for GC class Main{
} public static void main(String[] args){
} int[][] num = new int[3][];
num[0] = new int[5];
num[1] = new int[2];
Second Approach: Point the reference variable to another object. Doing this, the num[2] = new int[3];
object which the reference variable was referencing before becomes eligible for GC. num[2] = new int[5];
num[0] = new int[4];
num[1] = new int[3];
public class IBGarbageCollect {
public static void main(String [] args){ num = new int[2][];
String s1 = "To Garbage Collect"; }
String s2 = "Another Object"; }
System.out.println(s1); // s1 is not yet eligible for GC
s1 = s2; // Point s1 to other object pointed by s2
/* Here, the string object having the content "To Garbage Collect" is not referre In the above program, a total of 7 objects will be eligible for garbage collection. Let’s
}
} visually understand what's happening in the code.
In the above figure on line 3, we can see that on each array index we are declaring a
new array so the reference will be of that new array on all the 3 indexes. So the old
array will be pointed to by none. So these three are eligible for garbage collection.
And on line 4, we are creating a new array object on the older reference. So that will
point to a new array and older multidimensional objects will become eligible for
garbage collection.
91. What is the best way to inject dependency? Also, state the
reason.
There is no boundation for using a particular dependency injection. But the
recommended approach is -
Setters are mostly recommended for optional dependencies injection, and
constructor arguments are recommended for mandatory ones. This is because
constructor injection enables the injection of values into immutable fields and
enables reading them more easily.
92. How we can set the spring bean scope. And what supported
scopes does it have?
A scope can be set by an annotation such as the @Scope annotation or the "scope"
attribute in an XML configuration file. Spring Bean supports the following five scopes:
Singleton
Prototype
Request
Session
Global-session
Adapter The Java Garbage Collector (GC) typically removes unused objects when they are no
Bridge longer required, but when they are still referenced, the unused objects cannot be
Filter removed. So this causes the memory leak problem. Example - Consider a linked list
Composite like the structure below -
Decorator
Facade
Flyweight
Proxy
Behavioral patterns:
Interpreter
Template method/ pattern
Chain of responsibility
Command pattern
Iterator pattern
Strategy pattern
Visitor pattern
J2EE patterns: In the above image, there are unused objects that are not referenced. But then also
MVC Pattern Garbage collection will not free it. Because it is referencing some existing referenced
Data Access Object pattern object. So this can be the situation of memory leak.
Front controller pattern Some common causes of Memory leaks are -
Intercepting filter pattern
Transfer object pattern When there are Unbounded caches.
Excessive page swapping is done by the operating system.
Creational patterns:
Improper written custom data structures.
Factory method/Template Inserting into a collection object without first deleting it.
Abstract Factory etc.
Builder
Prototype 95. Assume a thread has a lock on it, calling the sleep() method
Singleton on that thread will release the lock?
94. What is a Memory Leak? Discuss some common causes of it. A thread that has a lock won't be released even a er it calls sleep(). Despite the
thread sleeping for a specified period of time, the lock will not be released.
}
return word; 98. Write a Java program to check if the two strings are
return word.charAt(word.length()- 1) + getReverseWord(word.substring(0, word.len
anagrams.
}
} The main idea is to validate the length of strings and then if found equal, convert the
string to char array and then sort the arrays and check if both are equal.
Idea is to find the sum of n natural numbers using the formula and then finding the
import java.util.Arrays;
import java.util.Scanner; sum of numbers in the given array. Subtracting these two sums results in the number
public class InterviewBit { that is the actual missing number. This results in O(n) time complexity and O(1) space
public static void main(String[] args) {
Scanner s = new Scanner(System.in); complexity.
//Input from two strings
System.out.print("First String: ");
String string1 = s.nextLine(); public class IBMissingNumberProblem {
System.out.print("Second String: ");
String string2 = s.nextLine(); public static void main(String[] args) {
// check for the length
if(string1.length() == string2.length()) { int[] array={4,3,8,7,5,2,6};
// convert strings to char array int missingNumber = findMissingNum(array);
char[] characterArray1 = string1.toCharArray(); System.out.println("Missing Number is "+ missingNumber);
char[] characterArray2 = string2.toCharArray(); }
// sort the arrays
Arrays.sort(characterArray1); public static int findMissingNum(int[] array) {
Arrays.sort(characterArray2); int n=array.length+1;
// check for equality, if found equal then anagram, else not an anagram int sumOfFirstNNums=n*(n+1)/2;
boolean isAnagram = Arrays.equals(characterArray1, characterArray2); int actualSumOfArr=0;
System.out.println("Anagram: "+ isAnagram); for (int i = 0; i < array.length; i++) {
} actualSumOfArr+=array[i];
} }
return sumOfFirstNNums-actualSumOfArr;
}
}
99. Write a Java Program to find the factorial of a given number.
We have created the exception class named with CustomException and called the
public class IBMagicNumber{
base exception constructor with the error message that we want to print. And to
public static void main(String[] args) { avoid handling exceptions in the main method, we have used the throws keyword in
int num = 163;
int sumOfDigits = 0; the method declaration.
while (num > 0 || sumOfDigits > 9)
{
if (num == 0) 103. Write a Java program to reverse a string.
{
num = sumOfDigits;
sumOfDigits = 0;
} class InterviewBit{
sumOfDigits += num % 10; public static void main(String[] args){
num /= 10; //Input String
} String str = "Welcome to InterviewBit";
In the above code, for rotating the matrix to 90 degrees we are first transposing the
mport java.util.Scanner;
public class InterviewBit
matrix so the row becomes the column. And a er that, we are reversing each row in
{ the matrix. So this is how the matrix got rotated.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int no;
System.out.print("Enter size of Array : ");
105. Write a java program to check if any number given as input
no = sc.nextInt();
int[][] a = new int[no][no];
is the sum of 2 prime numbers.
System.out.print("Enter "+ no*no+" Element Array : ");
Example :
for(int i = 0; i<no; i++){
for(int j = 0; j<no; j++){ Input - 18
a[i][j] = sc.nextInt();
}
}
Output -
System.out.print("\nArray Before Rotation\n\n");
for(int i = 0; i<no; i++){ 18 = 13 + 5
for(int j = 0; j<no; j++){ 18 = 11 + 7
System.out.print(a[i][j] + " ");
}
System.out.println(); public class InterviewBit
} {
// Method to Check Prime Number
System.out.println("\n"); private static int check_prime(int num){
//Rotation int flag = 0;
for(int i = 2; i<=num/2; i++){
//Transpose if(num%i == 0){
for(int i = 0; i < no; i++){ flag = 1;
for(int j = i; j < no; j++){ return 1;
int temp = a[i][j]; }
a[i][j] = a[j][i]; }
a[j][i] = temp; if(flag == 0)
} return 0;
} return 1;
}
//Reverse Each row // Method to get print the prime sum
for(int i = 0; i < no; i++){ private static void find(int num){
int l, j; for(int i = 2; i <= num/2; i++){
for(j = 0, l = no -1; j < l; j++){ if(check_prime(i) == 0){
int temp = a[i][j]; if(check_prime(num-i) == 0)
a[i][j] = a[i][l]; System.out.println(num + " = "+ (num-i) + " "+ i);
a[i][l] = temp; }
l--; }
} }
} public static void main(String[] args) {
find(18);
System.out.println("Array After Rotation - \n"); }
}
for(int i = 0; i<no; i++){
for(int j = 0; j<no; j++){
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}
In the above code, for any number n, we find all the 2 pairs of numbers that are
public class Main
added together resulting in n. And each checking number if it is prime. If it is prime {
then we are printing that. //Recursive method for binary search
private static boolean binarySearch(int[] arr, int low, int high, int key){
106. Write a Java program for solving the Tower of Hanoi //Calculating Mid.
int mid = (low + high)/2;
Problem. //Base Case.
if(low > high)
return false;
public class InterviewBit
{ //Checking if the key is found in the middle.
//Recursive Method for Solving the Tower of hanoi. if(arr[mid] == key)
private static void TOH(char source, char auxiliary, char destination, int numOfDis return true;
if (numOfDisk > 0){
TOH(source, destination, auxiliary, numOfDisk-1); //Searching on the left half if a key exists there.
System.out.println("Move 1 disk from "+source+" to "+destination+" using "+ if(key < arr[mid])
TOH(auxiliary, source, destination, numOfDisk-1); return binarySearch(arr, low, mid-1, key);
}
} //Searching on the other half otherwise.
public static void main(String[] args) { return binarySearch(arr, mid+1, high, key);
TOH('A','B','C', 3); }
} public static void main(String[] args) {
}
int[] arr = {2, 5, 9, 13, 17, 21, 30};
if(binarySearch(arr, 0, (arr.length-1), 30))
In the above code we are first moving the n-1 disk from Tower A to Tower B, then System.out.println(" Element Found. ");
else
moving that nth disk from Tower A to Tower C, and finally, the remaining n-1 disk System.out.println(" Element not Found.");
from Tower B to Tower C. And we are doing this recursively for the n-1 disk. }
}
107. Implement Binary Search in Java using recursion. In the above code, we are finding the middle element each time and checking if the
element is in the middle or not. If it is not, then we check on which side from the
middle it exists. And Recursively searching on the particular subarray. So this way we
are reducing the search space by 2 every time. So the search time is very low.
Conclusion
108. Conclusion
Java is one of the simple high-level languages that provides powerful tools and How to Become a Java Developer?
impressive standards required for application development. It was also one of the How much does a Java Developer earn in India?
first languages to provide amazing threading support for tackling concurrency-based Java Projects
problems. The easy-to-use syntax and the built-in features of Java combined with the Java Programming Questions for interview
stability it provides to applications are the main reasons for this language to have Java 8 Interview Questions
ever-growing usage in the so ware community. Java String Interview Questions
Join our community and share your java interview experiences. Spring Interview Questions
Hibernate Interview Questions
Java Collections Interview Questions
Recommended Interview Preparation Resources Array Interview Questions
Design Patterns Interview Questions
Multithreading Interview Questions
Java Tutorial
Java MCQ
Advance Java MCQ
Difference Between C++ and Java
Difference Between C and Java
Difference Between Java and Javascript
Kotlin Vs Java
Java Vs Python
Features of Java 9
Java 8 Features
Java Frameworks
Java Developer Skills
Java IDE
Java 11 Features
JAVA SE Download
Additional Technical Interview Questions
“The session was so well structured and simplified. 3 Operating System Interview React Native Interview Aws Interview Questions
engaging hours of learning, interesting polls and lots
of doubt resolution! The best part was, he saw curious
Abhinav Questions Questions
learners and extended the session for another hour for Koppula Git Interview Questions Java 8 Interview Questions Mongodb Interview
people who wished to stay. Recommend it to all Questions
beginners out there who are clueless about starting Developer,
HLD themselves! This is a must!!” Mckinsey Dbms Interview Questions Spring Boot Interview Power Bi Interview Questions
Questions