Core Java Quick Notes
1. Features of Java
1. Simple: Easy syntax, no pointers.
2. Object-Oriented: Follows OOP principles.
3. Platform Independent: Bytecode runs on any JVM.
4. Secure: No direct memory access, built-in security.
5. Robust: Strong memory management and exception handling.
6. High Performance: JIT Compiler speeds up execution.
7. Multithreaded: Supports multiple threads.
8. Distributed: Build network-based applications.
9. Dynamic: Class loading at runtime.
10. Portable: Bytecode can run on different platforms.
Core Java Quick Notes
2. Inheritance & Types
Inheritance allows a class to acquire properties of another.
Types:
- Single
- Multilevel
- Hierarchical
- Multiple (via Interface)
- Hybrid (via Interface)
Example:
class Animal { void eat(){} }
class Dog extends Animal { void bark(){} }
Core Java Quick Notes
3. OOP Concepts
OOP = Object-Oriented Programming
Concepts:
- Class: Blueprint for object.
- Object: Instance of a class.
- Inheritance: Acquiring features of another class.
- Polymorphism: One task, many forms.
- Abstraction: Hiding details.
- Encapsulation: Wrapping data + code in one unit.
Core Java Quick Notes
4. Constructor Types
Constructor: Special method to initialize object.
Types:
- Default Constructor
- Parameterized Constructor
- Copy Constructor (Manual)
Example:
Student() {}
Student(int id, String name) {}
Core Java Quick Notes
5. Interface in Java
Interface: Fully abstract class with only method declarations.
Why Use:
- Achieve multiple inheritance.
- Abstraction.
Syntax:
interface A { void show(); }
class B implements A { public void show(){} }
Core Java Quick Notes
6. Package in Java
Package: Group of related classes.
Create: package mypack;
Use: import mypack.MyClass;
Helps in organizing code.
Core Java Quick Notes
7. Access Modifiers
Control visibility of class members.
| Modifier | Same Class | Same Package | Subclass | Other |
|------------|------------|--------------|----------|-------|
| private | Yes | No | No | No |
| default | Yes | Yes | No | No |
| protected | Yes | Yes | Yes | No |
| public | Yes | Yes | Yes | Yes |
Core Java Quick Notes
8. Control Flow Statements
Used to control flow of execution.
- Conditional: if, if-else, switch
- Looping: for, while, do-while
- Jump: break, continue, return
Core Java Quick Notes
9. Short Notes
Encapsulation: Data hiding using classes.
Polymorphism:
- Compile-time: Overloading
- Run-time: Overriding
Abstract Class: Has abstract + non-abstract methods.
Class & Object:
- Class = Blueprint
- Object = Instance
JDK: Java Development Kit (JRE + Dev tools)
JRE: Java Runtime Environment (JVM + Libs)
JVM: Runs bytecode
Core Java Quick Notes
10. Overloading vs Overriding
Overloading:
- Same class
- Different parameters
Overriding:
- Parent-child
- Same method signature
Example:
void show(int a) {} // overloading
void show(String a) {} // overloading
class A { void show(){} }
class B extends A { void show(){} } // overriding
Core Java Quick Notes
11. Operators & Data Types
Operators:
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <
- Logical: &&, ||, !
- Assignment: =, +=, -=
- Bitwise: &, |, ^
Data Types:
- Primitive: int, float, boolean, char, etc.
- Non-Primitive: String, Arrays, Objects
Variables: Used to store data. Must be declared with data type.