Java Technical Interview Cheat Sheet
1. What is Java?
Java is a high-level, object-oriented programming language. It is platform-independent due to the
JVM (Java Virtual Machine).
2. Difference between JDK, JRE, JVM
- JDK: Java Development Kit for development.
- JRE: Java Runtime Environment to run Java apps.
- JVM: Java Virtual Machine executes bytecode.
3. Features of Java
- Object-Oriented
- Platform Independent
- Secure
- Robust
- Multithreaded
- High Performance
4. Class vs Object
- Class: Blueprint for objects.
- Object: Instance of a class.
5. Overloading vs Overriding
- Overloading: Same method name, different parameters.
- Overriding: Redefining superclass method in subclass.
6. Final Keyword
- final variable: Value can't be changed.
- final method: Can't be overridden.
- final class: Can't be inherited.
7. Inheritance
Allows child class to inherit methods and fields from a parent class.
Example:
class Dog extends Animal
8. Interface
Interface in Java is used to achieve abstraction and multiple inheritance.
9. Exception Handling
Use try, catch, finally blocks to handle exceptions.
Example: try { int a = 10/0; } catch (Exception e) {}
10. ArrayList vs LinkedList
- ArrayList: Fast random access, slow inserts/deletes.
- LinkedList: Fast inserts/deletes, slow random access.
Code Example: Prime Check
int num = 29; boolean isPrime = true;
for (int i = 2; i <= num/2; i++) {
if (num % i == 0) isPrime = false; }
Code Example: Reverse String
String str = "Kamarta";
for (int i = str.length()-1; i >= 0; i--) {...}
Code Example: Factorial (Recursion)
int fact(int n) {
if(n==0) return 1;
else return n * fact(n-1);