1.
java - 1995
JDK → Develop
JRE → Run
JVM → Execute
JDK > JRE > JVM
JDK contains JRE
JRE contains JVM
2. Variables
int, double, char, String, Boolean
Stack Memory:
Local variables
Method calls
Primitive data
Heap Memory:
Objects
Arrays
Strings
3. Data type:
A data type tells Java:
What kind of value a variable can store.
1) Primitive Data Types
byte 1 byte byte a = 10;
short 2 bytes short s = 200;
int 4 bytes int age = 21;
long 8 bytes long num = 9876543210L;
float 4 bytes float f = 10.5f;
double 8 bytes double d = 10.5;
char 2 bytes char grade = 'A';
Boolean 1 bit Boolean flag = true;
2) Non-Primitive Data Types
String
Array
Class
Object
| Feature | Primitive | Non-Primitive |
| ------- | --------- | ------------- |
| Stores | Value | Address |
| Memory | Stack | Heap |
| Size | Fixed | Not fixed |
| Example | int, char | String, Array |
4. Operators:
1) Arithmetic Operators
2) Relational Operators
3) Logical Operators
4) Assignment Operators
5) Increment/Decrement Operators
5. Conditional statement:
if, else-if, switch
6. Looping Statements:
for, while, do-while
7. Methods:
1) No return, No parameter
2) No return, With parameter
3) Return, No parameter
4) Return, With parameter
8. Method Overloading vs Method Overriding
| Feature | Method Overloading | Method Overriding |
| ------------ | ------------------------ | --------------------------- |
| Class | Same class | Parent & Child class |
| Inheritance | ❌ Not required | ✅ Required |
| Parameters | Must be different | Must be same |
| Return type | Can change (with params) | Must be same (or covariant) |
| Polymorphism | Compile-time | Runtime |
| Binding | Static binding | Dynamic binding |
| @Override | ❌ Not used | ✅ Recommended |
Method Overloading:
-> Method Overloading means having multiple methods with the same name but
different parameter lists within the same class.
-> Happens at compile time
-> Also called Compile-Time Polymorphism
-> Return type alone cannot change
-> Inheritance is not required
Method Overriding:
->Method Overriding means redefining a parent class method in the child
class with the same method signature.
-> Happens at runtime
-> Also called Runtime Polymorphism
-> Requires inheritance
-> Method signature must be exactly same
-> Access modifier cannot be more restrictive
" Method overloading is compile-time polymorphism where methods differ by
parameters,
while method overriding is runtime polymorphism where child classes redefine
parent methods "
Parameter → variable in method definition
Argument → value passed while calling
Class → Blueprint/template -> Student structure
Object → Real instance of class -> Actual student
Constructors:
-> A constructor is a special method used to initialize objects.
Same name as class
No return type
Runs automatically
this Keyword:
-> The this keyword in Java refers to the current object in a method
or constructor.
super Keyword:
-> the super keyword is used to refer to the parent class of a
subclass.
Access Modifiers:
| Modifier | Access |
| --------- | ----------------------- |
| public | Everywhere |
| private | Inside class |
| protected | Same package + subclass |
| default | Same package |
-> non-access modifiers are final, static, and abstract.
Encapsulation:
-> Encapsulation is to make sure that "sensitive" data is hidden from
users
-> Binding data + methods into one unit
Inheritance:
-> One class acquires properties of another class
Polymorphism:
-> One method behaves differently in different situations.
Abstraction:
-> Hiding implementation and showing only functionality.
-> Abstract class: is a restricted class that cannot be used to create
objects (to access it, it must be inherited from another class).
-> Abstract method: can only be used in an abstract class, and it
does not have a body. The body is provided by the subclass
Interface:
-> Interface is a blueprint of a class containing only abstract
methods.
----------------------------------------------------------------------------
-> Package is a collection of classes.
-> Enum is Used to store fixed constants.
-> Inner Class is Class inside another class.
Java Exceptions:
-> An exception is an event that interrupts the normal flow of a
program.
| Keyword | Use |
| ------- | ----------------- |
| try | risky code |
| catch | handle error |
| finally | always runs |
| throw | create exception |
| throws | declare exception |
Multiple Exceptions:
-> Handling different types of exceptions using multiple catch blocks.
Difference between Error & Exception?
| Error | Exception |
| --------------- | -------------- |
| Serious problem | Can be handled |
| JVM level | Program level |
Java File Handling:
-> File handling in Java is used to create, read, write, and delete
files using classes from [Link] package.