Java Interview Questions
Java Interview Questions
concepts:
1. What is Java?
Component Description
Includes JRE + development tools (compiler, debugger,
JDK (Java Development Kit)
etc.)
JRE (Java Runtime
Includes JVM + libraries to run Java applications
Environment)
JVM (Java Virtual Machine) Converts bytecode into machine-specific code
Example:
int → Integer
double → Double
char → Character
Example:
Example:
try {
int a = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero!");
}
Modifier Scope
public Accessible everywhere
protected Accessible within the same package + subclasses
default Accessible within the same package only
private Accessible within the same class only
Example:
class Animal {
void sound() { System.out.println("Animal makes a sound"); }
}
class Dog extends Animal {
void sound() { System.out.println("Dog barks"); }
}
volatile ensures that a variable's value is always read from main memory, preventing
caching issues in multi-threaded environments.
Example:
Example:
Example:
Example:
class Person {
Person() { System.out.println("Constructor called"); }
}
Example:
Example:
@FunctionalInterface
interface MyInterface {
void sayHello();
}
Example:
Example:
Deadlock occurs when two or more threads are waiting on each other, preventing execution.