Contents
- 1 Core Java Interview Questions
- 1.1 What is the difference between binary files and library files?
- 1.2 What the difference between path and classpath environment variables?
- 1.3 What is hotspot profiler in java?
- 1.4 Are true, false and null keywords or not?
- 1.5 What is the use of underscore (_) and dollar($) in naming conventions in java?
- 1.6 What is implicit casting?
- 1.7 What is explicit casting?
- 1.8 What is the difference between array and variable arguments (var args)?
- 1.9 Can we use variable argument as first parameter of method?
- 1.10 What is the difference between length field and length ()?
- 1.11 What is the difference between parseBoolean(-) and nextBoolean(-)?
- 1.12 Is bellow code valid or not?
- 1.13 Can we able print array object values directly by using System.out.println(-) statement?
- 1.14 Do we have anonymous arrays in java?
- 1.15 How many ways can we call same class static data?
- 1.16 How many ways can able to call other class non-static data?
- 1.17 How many can we communicate with other class static data?
- 1.18 Can we write static block within the method?
Core Java Interview Questions
-
What is the difference between binary files and library files?
Answer: Binary files are useful for compilation, execution, and de-compilation, creating documentation and etc whereas library files are useful for developing new applications.
-
What the difference between path and classpath environment variables?
Answer: Path is used to find out binary files location by command prompt, whereas classpath is used by compiler and JVM to find out location of library files
-
What is hotspot profiler in java?
Answer: It is one special component in JVM, which is useful for recognize whether the statements are single time executable statement or looping statement. If the statement is single time executable statement then handover to interpreter otherwise the handover to JIT compiler.
-
Are true, false and null keywords or not?
Answer: True, false and null are not keywords, these are literals.
-
What is the use of underscore (_) and dollar($) in naming conventions in java?
Answer: Underscore is useful for providing readability and dollar is useful for representing the inner classes.
-
What is implicit casting?
Answer: The process of converting lower range data type variable value to higher range data type variable value is called implicit casting
——-> Learn Core Java Online Course
-
What is explicit casting?
Answer:The process of converting higher range data type variable value to lower range data type variable value with the support of cast operator is called explicit casting.
-
What is the difference between array and variable arguments (var args)?
Answer: While working with arrays we should send multiple values in the array format, where as variable arguments can allows multiple values in array format as well as individual value format.
class A{
void m1(int [] a){
for(int a1: a){
System.out.println(a1);
}
}
}
class B{
void m2(int…a){
for(int a1: a){
System.out.println(a1);
}
}
}
public class Test{
public static void main(String[] args) {
A obj = new A();
int[] c = {11,22,33};
obj.m1(c);
B obj1 = new B();
obj1.m2(11,22,33);
obj1.m2(c);
}
}
——-> Learn Core Java Online Course
-
Can we use variable argument as first parameter of method?
Answer: No.
-
What is the difference between length field and length ()?
Answer: T o find out the array size we are using “length” filed where as length () is useful for finding number characters which are present in String object (size of the string).
-
What is the difference between parseBoolean(-) and nextBoolean(-)?
Answer: parseBoolean(-) always returns false other true value where as nextBoolean(-) will allows only true or false, if we are sending other Boolean value it will send java.util.InputMismatchException.
-
Is bellow code valid or not?
Answer:
public class Test{
public static void main(String[] args) {
long l = 2147483648;
}
}
No.
We should write like this
long l = 2147483648L;
-
Can we able print array object values directly by using System.out.println(-) statement?
Answer: No. Except char[], remaining array object values we can’t print .
-
Do we have anonymous arrays in java?
Answer: No.
public class Test{
public static void main(String[] args) {
new int[]{11,22,33};
}
}
Above code will give error like not a statement.
——-> Learn Core Java Online Course
-
How many ways can we call same class static data?
Answer: We have three ways to communicating with same class static data.
- By directly.
- By using class name.
- By using object
- By using referenced object
- By using unreferenced object.
- What is the difference between referenced object and unreferenced object?
A memory which contains name is called referenced memory. We can able to communicating with that memory multiple times, where as the memory which doesn’t contain name is called unreferenced or anonymous memory. We can communicate with that memory only one time.
-
How many ways can able to call other class non-static data?
Answer: Only one way, we can able communicating with other class non-static data that is object.
- By using Referenced object
- By using unreferenced object.
-
How many can we communicate with other class static data?
Answer: We can communicate with other class static by two ways.
- By using class name
- By using object
- By using referenced object.
- By using unreferenced object.
- Can we non-static/instance block within the method?
Yes. Like bellow
void m1(){
{
//logic for non-static block
}
}
public class Test{
public static void main(String[] args) {
{
System.out.println(“non static block”);
}
}
}
-
Can we write static block within the method?
Answer: No. Compiler will give error.
public class Test{
public static void main(String[] args) {
static{
}
}
}
Compiletime Error: Illegal start of expression.
Click Read 80 more Core Java Interview Questions and Answers
Learn Core Java Online Course