Java Interview Questions
Java Interview Questions
JIT stands for Just-In-Time and it is used for improving the performance during run
time. It does the task of compiling parts of byte code having similar functionality at
the same time thereby reducing the amount of compilation time for the code to run.
The compiler is nothing but a translator of source code to machine-executable code.
But what is special about the JIT compiler? Let us see how it works:
o First, the Java source code (.java) conversion to byte code (.class) occurs with
the help of the javac compiler.
o 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.
o 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.
o 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.
class Student3{
int id;
String name;
Output:
0 null
0 null
Is constructor inherited?
No, The constructor is not inherited.
o The static method can not use non-static data member or call the non-static
method directly.
o this and super cannot be used in static context as they are non-static.
What is aggregation?
Aggregation can be defined as the relationship between two classes where the
aggregate class contains a reference to the class it owns. Aggregation is best
described as a has-a relationship.
Class Variable: Class Variable variable can be declared anywhere at the class level
using the keyword static. These variables can only have one value when applied to
various objects. These variables can be shared by all class members since they are
not connected to any specific object of the class.
System.out.println(reverse(str));
}
return out.toString();
}
Write a Java program to print a Fibonacci sequence using recursion.
public class PrintFibonacci {
a = b;
b = c;
c = a + b;
}
}
The following example code shows one way to remove spaces from a string using
with the Character.isWhitespace() method:
return output.toString();
}