Java Review Notes
Basics
- JVM (Java Virtual Machine): Executes Java bytecode
- JDK (Java Development Kit): Contains tools for developing Java applications
- JRE (Java Runtime Environment): Provides libraries and JVM for running Java applications
Data Types
- Primitive Types:
int
, double
, char
, boolean
, float
, long
, short
, byte
- Reference Types: Objects, Arrays, Strings, etc
Variables
- Local: Declared inside methods or blocks
- Instance: Belong to instances of a class
- Static: Belong to the class itself
Control Flow
- Conditionals:
if
, else if
, else
, switch
- Loops:
for
, while
, do-while
- Break/Continue: Control loop execution
Object-Oriented Programming
- Class: Blueprint for objects
- Object: Instance of a class
- Inheritance:
class SubClass extends SuperClass
- Polymorphism: Method overriding and overloading
- Encapsulation: Use private fields with public getters/setters
- Abstraction: Abstract classes and interface
Access Modifiers
public
: Accessible everywhere
protected
: Accessible in the same package or subclasses
default
: Accessible within the same package
private
: Accessible only within the class
Key Concepts
- Constructors: Special methods to initialize objects
this
Keyword: Refers to the current object
super
Keyword: Refers to the parent class
- Static Methods/Variables: Belong to the class, not instances
- Final Keyword: Used to declare constants, prevent inheritance, or prevent method overriding
Collections
- List:
ArrayList
, LinkedList
- Set:
HashSet
, TreeSet
- Map:
HashMap
, TreeMap
Exception Handling
- Try-Catch: Handle exceptions
- Finally: Code that always executes
- Throws: Declare exceptions
- Throw: Manually throw exceptions
- Scanner: For user input
- BufferedReader: For efficient reading
- File: For handling files
Miscellaneous
toString()
: Converts objects to strings
equals()
: Compares object content
hashCode()
: Returns hash code
- Lambda Expressions: Concise way to express instances of single-method interfaces
- Streams: Process sequences of elements with functional-style operations