Java Important Notes Detailed
Java Important Notes Detailed
1. Simple: Java has a clean and easy-to-understand syntax similar to C++, without complex
features like pointers.
3. Platform Independent: Java code is compiled into bytecode which runs on any system
having JVM (Java Virtual Machine).
4. Secure: Java provides a secure environment through features like bytecode verification,
sandboxing, and lack of pointer access.
5. Robust: Java handles errors through exception handling and has features like garbage
collection to manage memory.
7. Architecture Neutral: Java code behaves the same on any architecture due to the JVM.
9. Dynamic: Java supports dynamic loading of classes at runtime and interfaces with native
code libraries.
Class vs Object
Class: A class is a blueprint or template used to create objects. It defines properties (fields)
and behaviors (methods).
Example:
Features of OOP
1. Encapsulation: Wrapping data and code into a single unit (class).
2. Inheritance: Mechanism by which one class inherits the properties of another. Promotes
code reusability.
4. Abstraction: Hiding internal details and showing only the necessary features of an object.
Use nested loops to iterate through rows and columns and add corresponding elements.
Packages
A package is a namespace for organizing classes and interfaces.
- User-defined package:
- Can contain only abstract methods (default and static from Java 8).
Abstract Class:
- Throwable
|- Exception
Multi-Catch Example
Allows catching multiple exceptions in one block:
Thread Priorities
Each thread has a priority:
- MIN_PRIORITY = 1
- NORM_PRIORITY = 5 (default)
- MAX_PRIORITY = 10
Thread Synchronization
Used to prevent conflicts when multiple threads access shared resources.
Use 'synchronized' keyword to allow only one thread to execute a block of code at a time.
Inter-Thread Communication
Helps threads coordinate using: