Java (Notes)
1. Introduction to Java:
• Java is a high-level, class-based, object-oriented programming language designed to
have as few implementation dependencies as possible.
• Developed by Sun Microsystems in 1991 and now owned by Oracle Corporation.
• Platform Independence: Java uses the "write once, run anywhere" philosophy, making
it platform-independent via the Java Virtual Machine (JVM).
2. Key Concepts in Java:
• Classes and Objects: Java is object-oriented, meaning everything is an object. A class
is a blueprint for objects, and an object is an instance of a class.
• Inheritance: Enables one class to inherit the properties and methods of another class.
Allows for code reusability.
• Polymorphism: The ability of a single function or operator to operate on different types
of objects. Achieved through method overloading and overriding.
• Encapsulation: Hides the internal state of an object and only exposes necessary
methods. Achieved using private variables and public getter/setter methods.
• Abstraction: Hides complex implementation details from the user. Can be achieved
using abstract classes and interfaces.
3. Java Syntax:
• Java programs consist of classes and methods.
• Every Java program begins with the main() method, which is the entry point of the
program.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
4. Exception Handling:
• Java provides a robust exception-handling mechanism, allowing developers to handle
runtime errors and maintain program flow.
• Commonly used keywords: try, catch, throw, throws, finally.
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: " + e.getMessage());
} finally {
System.out.println("Finally block executed.");
5. Java Features:
• Garbage Collection: Automatic memory management ensures that objects not in use
are removed to free memory space.
• Multithreading: Java provides built-in support for multithreading, allowing concurrent
execution of two or more parts of a program.
• Security: Java includes a range of security features such as bytecode verification and
secure class loaders.