What is the difference between final, finally, and finalize?
final
: Prevents inheritance or modification
finally
: Ensures a block is executed after try-catch
finalize()
: Called by the garbage collector before object destruction
What are the types of memory in Java?
- Heap: Stores objects
- Stack: Stores local variables and function calls
- Method Area: Stores class structures
- PC Register: Stores the current execution address
- Native Stack: For native methods
How does Java achieve platform independence?
By compiling source code into bytecode that runs on the JVM. Each platform has its own JVM implementation, allowing the same bytecode to run anywhere.