Java is a high-level, object-oriented, platform-independent programming language used to build software applications. It was developed by Sun Microsystems in 1995 and is now maintained by Oracle.
Why Java is Popular
Platform Independent
Java follows the rule:
“Write Once, Run Anywhere”
A Java program can run on Windows, Linux, macOS, etc., without changes.
Object-Oriented
Java is based on concepts like:
Class
Object
Inheritance
Polymorphism
Encapsulation
This makes programs reusable, modular, and easy to maintain.
Secure
Java has:
No direct memory access
Bytecode verification
Automatic garbage collection
Robust & Reliable
Strong memory management
Exception handling
Less chances of crashes
JDK vs JVM VS JRE
JDK is a complete kit for Java developers. (JDK = JRE, Javac or Java Compiler, Development & Debugger) JVM is a virtual machine that runs Java programs. Using JVM Executes Java bytecode (.class files), Converts bytecode into machine code, Makes Java platform-independent, Manages memory and garbage collection and JRE provides the environment required to run Java applications. (JRE = JVM + Libraries)
☕ Complete Java Course - Topics Index

📚 Table of Contents
#1 - Introduction to Java
- 1.1 Why you must learn Java
- 1.2 What is a Programming Language
- 1.3 What is an Algorithm
- 1.4 What is Syntax
- 1.5 History of Java
- 1.6 Magic of Byte Code
- 1.7 How Java Changed the Internet
- 1.8 Java Buzzwords
- 1.9 What is Object Oriented Programming
#2 - Java Basics
- 2.1 Installing JDK
- 2.2 First Class using Text Editor
- 2.3 Compiling and Running
- 2.4 Anatomy of a Class
- 2.5 File Extensions
- 2.6 JDK vs JVM vs JRE
- 2.7 Showing Output
- 2.8 Importance of the main method
- 2.9 Installing IDE (Intellij Idea)
- 2.10 Project Structure
#3 - Data Types, Variables & Input
- 3.1 Variables
- 3.2 Data Types
- 3.3 Naming Conventions
- 3.4 Literals
- 3.5 Keywords
- 3.6 Escape Sequences
- 3.7 User Input
- 3.8 Type Conversion and Casting
#4 - Operators, If-else, Number System
- 4.1 Assignment Operator
- 4.2 Arithmetic Operators
- 4.3 Order of Operation
- 4.4 Shorthand Operators
- 4.5 Unary Operators
- 4.6 If-else
- 4.7 Relational Operators
- 4.8 Logical Operators
- 4.9 Operator Precedence
- 4.10 Intro to Number System
- 4.11 Intro to Bitwise Operators
#5 - While Loop, Methods & Arrays
- 5.1 Comments
- 5.2 While Loop
- 5.3 Methods
- 5.4 Return Statement
- 5.5 Arguments
- 5.6 Arrays
- 5.7 2D Arrays
#6 - Classes & Objects
- 6.1 Process vs Object Oriented
- 6.2 Instance Variables and Methods
- 6.3 Declaring and Using Objects
- 6.4 Class vs Object
- 6.5 This & Static Keyword
- 6.6 Constructors & Code Blocks
- 6.7 Stack vs Heap Memory
- 6.8 Primitive vs Reference Types
- 6.9 Variable Scopes
- 6.10 Garbage Collection & Finalize
#7 - Control Statements, Math & String
- 7.1 Ternary Operator
- 7.2 Switch
- 7.3 Loops (Do-while, For, For each)
- 7.4 Using break & continue
- 7.5 Recursion
- 7.6 Random Numbers & Math class
- 7.7 Don't Learn Syntax
- 7.8 toString Method
- 7.9 String class
- 7.10 StringBuffer vs StringBuilder
- 7.11 Final keyword
#8 - Encapsulation & Inheritance
- 8.1 Intro to OOPs Principle
- 8.2 What is Encapsulation
- 8.3 Import & Packages
- 8.4 Access Modifiers
- 8.5 Getter and Setter
- 8.6 What is Inheritance
- 8.7 Types of Inheritance
- 8.8 Object class
- 8.9 Equals and Hash Code
- 8.10 Nested and Inner Classes
#9 - Abstraction & Polymorphism
- 9.1 What is Abstraction
- 9.2 Abstract Keyword
- 9.3 Interfaces
- 9.4 What is Polymorphism
- 9.5 References and Objects
- 9.6 Method / Constructor Overloading
- 9.7 Super Keyword
- 9.8 Method / Constructor Overriding
- 9.9 Final keyword revisited
- 9.10 Pass by Value vs Pass by Reference
#10 - Exception & File Handling
- 10.1 What is an Exception
- 10.2 Try-Catch
- 10.3 Types of Exception
- 10.4 Throw and Throws
- 10.5 Finally Block
- 10.6 Custom Exceptions
- 10.7 FileWriter class
- 10.8 FileReader class
#11 - Collections & Generics
- 11.1 Variable Arguments
- 11.2 Wrapper Classes & Autoboxing
- 11.3 Collections Library
- 11.4 List Interface
- 11.5 Queue Interface
- 11.6 Set Interface
- 11.7 Collections Class
- 11.8 Map Interface
- 11.9 Enums
- 11.10 Generics & Diamond Operators
#12 - Multithreading & Executor Service
- 12.1 Intro to Multi-threading
- 12.2 Creating a Thread
- 12.3 States of a Thread
- 12.4 Thread Priority
- 12.5 Join Method
- 12.6 Synchronize keyword
- 12.7 Thread Communication
- 12.8 Intro to Executor Service
- 12.9 Multiple Threads with Executor
- 12.10 Returning Futures
#13 - Functional Programming
- 13.1 What is Functional Programming
- 13.2 Lambda Expression
- 13.3 What is a Stream
- 13.4 Filtering & Reducing
- 13.5 Functional Interfaces
- 13.6 Method References
- 13.7 Functional vs Structural Programming
- 13.8 Optional Class
- 13.9 Intermediate vs Terminal Operations
- 13.10 Max, Min, Collect to List
- 13.11 Sort, Distinct, Map
📝 Note: - [ ] checkbox hai — GitHub pe tick kar sakte ho jab topic complete ho jaye!
Step By Step
Variables
Java Literals
Literals are fixed values assigned directly to variables in Java. They represent constant data.
1. Integer Literals
Whole numbers without decimal point.
| Type |
Syntax / Example |
Notes |
| Decimal |
int a = 10; |
Normal integer |
| Octal |
int b = 012; |
Starts with 0, decimal 10 |
| Hexadecimal |
int c = 0xA; |
Starts with 0x, decimal 10 |
| Binary |
int d = 0b1010; |
Starts with 0b, decimal 10 |
| Long |
long l = 100000L; |
Use L or l |
| Readable |
int p = 1_000_000; |
_ allowed for readability |
2. Floating-Point Literals
Numbers with decimal point.
| Type |
Syntax / Example |
Notes |
| Float |
float f = 10.5f; |
Use f or F |
| Double |
double d = 20.75; |
Default type for decimals |
| Scientific |
double e = 1.2e3; |
1200 in decimal |
3. Character Literals
Single character enclosed in single quotes.
| Example |
Notes |
'A' |
Single English letter |
'9' |
Digit as character |
'#' |
Symbol |
'\u0041' |
Unicode character (A) |
'\n' |
Escape sequence (new line) |
'\t' |
Escape sequence (tab) |
'\'' |
Single quote character |
4. String Literals
Sequence of characters enclosed in double quotes.
| Example |
Notes |
"Hello" |
Text |
"Sujit Kumar Singh" |
Multiple words |
"Line1\nLine2" |
Escape sequences supported |
5. Boolean Literals
Represents true or false values.
| Example |
Notes |
true |
Boolean true value |
false |
Boolean false value |
6. Null Literal
Represents no object reference.
| Example |
Notes |
String str = null; |
Only for reference types, not primitive |
Notes
- Integer types:
byte, short, int, long
- Floating types:
float, double
- Characters: Single quotes
' '
- Strings: Double quotes
" "
- Boolean:
true or false
- Null: For reference variables only
- Java supports underscore
_ in numeric literals for readability
Data Type
Premitive Data Type
| Data Type |
Description |
Size (Fixed) |
Example |
Type |
| byte |
Very small integer |
1 byte |
byte a = 10; |
Integer (Integral) |
| short |
Small integer |
2 bytes |
short b = 100; |
Integer (Integral) |
| int |
Integer value (whole numbers) |
4 bytes |
int c = 1000; |
Integer (Integral) |
| long |
Large integer |
8 bytes |
long d = 100000L; |
Integer (Integral) |
| float |
Single-precision decimal number |
4 bytes |
float e = 3.14f; |
Floating-Point |
| double |
Double-precision decimal number |
8 bytes |
double f = 3.14159; |
Floating-Point |
| char |
Single Unicode character |
2 bytes |
char g = 'A'; |
Character Type |
| boolean |
True or false |
1 byte* |
boolean h = true; |
Boolean |
Example
int age = 20;
boolean isRealAge = true;
float myMarks = 70.0f;
double myHeight = 5.7;
String name = "Sujit Kumar Singh";
byte level = 3; (Use when Memory very limited)
short year = 2025; (Use when memory need are small but larger than byte)
long population = 140000000L; (Use only when large value needs to be store)
char myChar = 'S'; (It is use in single single quotes with single character)
Non Premitive Data Type
| Data Type |
Description |
Size |
Example |
Type |
| String |
Sequence of characters (String class) |
Depends |
String a = "Hello"; |
Text / Reference |
| Array |
Collection of elements of same data type |
Depends |
int[] b = {1, 2, 3}; |
Collection |
| Class |
Blueprint for creating objects |
Depends |
class Student { } |
User-Defined Type |
| Object |
Parent class of all Java classes |
Depends |
Object obj = new Object(); |
Universal Reference |
| Interface |
Blueprint with abstract methods |
Depends |
interface Shape { } |
Abstract Type |
| Enum |
Set of named constants |
Depends |
enum Day { MON, TUE }; |
Special Class |
Java Literals – Table Reference
Literals are fixed values assigned directly to variables in Java. They represent constant data.
| Literal Type |
Example Syntax |
Notes / Output |
| Integer (Decimal) |
int a = 10; |
Normal integer |
| Integer (Octal) |
int b = 012; |
Starts with 0, decimal 10 |
| Integer (Hexadecimal) |
int c = 0xA; |
Starts with 0x, decimal 10 |
| Integer (Binary) |
int d = 0b1010; |
Starts with 0b, decimal 10 |
| Long |
long l = 10000000000L; |
Use L or l for long values |
| Readable Integer |
int r = 1_000_000; |
_ can be used for readability |
| Float |
float f = 10.5f; |
Use f or F |
| Double |
double d1 = 20.75; |
Default type for decimals |
| Scientific (Double) |
double d2 = 1.2e3; |
1.2 × 10³ = 1200 |
| Char |
char ch = 'A'; |
Single character, uses single quotes |
| Unicode Char |
char ch = '\u0041'; |
Unicode character |
| String |
String name = "Sujit"; |
Sequence of characters |
| Boolean |
boolean isJavaFun = true; |
Only true or false |
| Null |
String str = null; |
Represents no reference |
| Escape in String |
String msg = "Hello\nJava"; |
Supports escape sequences like \n, \t |
🔹 Quick Tips
- Integer types:
byte, short, int, long
- Floating types:
float, double
- Char vs String:
'A' → char, "A" → String
- Boolean literals are only
true or false.
- Null literal can be assigned only to reference types.
Java Escape Sequences – Table Reference
Escape sequences in Java are special characters preceded by a backslash \, used in strings and char literals.
| Escape Sequence |
Meaning / Usage |
Example Code |
Output Example |
\n |
New line |
System.out.println("Hello\nJava"); |
Hello
Java |
\t |
Horizontal tab |
System.out.println("A\tB\tC"); |
A B C |
\\ |
Backslash |
System.out.println("C:\\Users"); |
C:\Users |
\' |
Single quote |
char ch = '\''; |
' |
\" |
Double quote |
System.out.println("He said \"Hi\""); |
He said "Hi" |
\r |
Carriage return (cursor to line start) |
System.out.println("12345\rAB"); |
AB345 |
\b |
Backspace (removes previous char) |
System.out.println("Helloo\b!"); |
Hell! |
\f |
Form feed (page break, mostly printing) |
System.out.println("Hello\fWorld"); |
(depends on printer) |
\uXXXX |
Unicode character |
char ch = '\u0041'; |
A |
🔹 Quick Tips
- Escape sequences work only in char or string literals.
- Always use double backslash
\\ for printing a backslash.
\b and \r may behave differently in console vs files.
- Unicode
\uXXXX can represent any Unicode character.
Print Hello World
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Common Regex Symbols (Java)
Note: Java me regex likhte waqt backslash (\) ko escape karna padta hai.
Isliye \d ko Java string me "\\d" likhte hain.
Character Classes
| Regex |
Java String |
Description |
\d |
\\d |
Digit (0–9) |
\D |
\\D |
Non-digit |
\w |
\\w |
Word character (a–z, A–Z, 0–9, _) |
\W |
\\W |
Non-word character |
\s |
\\s |
Whitespace (space, tab, newline) |
\S |
\\S |
Non-whitespace |
Quantifiers
| Regex |
Description |
* |
0 or more times |
+ |
1 or more times |
? |
0 or 1 time |
{n} |
Exactly n times |
{n,} |
At least n times |
{n,m} |
Between n and m times |
Anchors
| Regex |
Description |
^ |
Start of string |
$ |
End of string |
Character Sets
| Regex |
Description |
[abc] |
Matches a, b, or c |
[a-z] |
Lowercase letters |
[A-Z] |
Uppercase letters |
[0-9] |
Digits |
[^0-9] |
Not a digit |
Groups & Alternation
| Regex |
Description |
(abc) |
Group |
| ` |
` |
Common Patterns
| Pattern |
Description |
\\d+ |
One or more digits |
\\d{10} |
10-digit mobile number |
[a-zA-Z]+ |
Alphabets only |
\\w+@\\w+\\.\\w+ |
Basic email format |
All Types of Operators in Java
Java me operators ka use operations perform karne ke liye hota hai.
1. Arithmetic Operators
| Operator |
Name |
Example |
+ |
Addition |
a + b |
- |
Subtraction |
a - b |
* |
Multiplication |
a * b |
/ |
Division |
a / b |
% |
Modulus |
a % b |
2. Unary Operators
| Operator |
Name |
Example |
+ |
Unary Plus |
+a |
- |
Unary Minus |
-a |
++ |
Increment |
a++, ++a |
-- |
Decrement |
a--, --a |
! |
Logical NOT |
!true |
3. Assignment Operators
| Operator |
Example |
Meaning |
= |
a = 5 |
Assign |
+= |
a += 2 |
a = a + 2 |
-= |
a -= 2 |
a = a - 2 |
*= |
a *= 2 |
a = a * 2 |
/= |
a /= 2 |
a = a / 2 |
%= |
a %= 2 |
a = a % 2 |
4. Relational (Comparison) Operators
| Operator |
Description |
Example |
== |
Equal to |
a == b |
!= |
Not equal to |
a != b |
> |
Greater than |
a > b |
< |
Less than |
a < b |
>= |
Greater than or equal |
a >= b |
<= |
Less than or equal |
a <= b |
5. Logical Operators
| Operator |
Name |
Example |
&& |
Logical AND (&&) |
a > 5 && b < 10 |
| ` |
|
` |
! |
Logical NOT (!) |
!(a > b) |
6. Bitwise Operators
| Operator |
Name |
Example |
& |
AND |
a & b |
| ` |
` |
OR |
^ |
XOR |
a ^ b |
~ |
Complement |
~a |
7. Shift Operators
| Operator |
Name |
Example |
<< |
Left Shift |
a << 1 |
>> |
Right Shift |
a >> 1 |
>>> |
Unsigned Right Shift |
a >>> 1 |
8. Ternary Operator
| Operator |
Description |
Example |
?: |
Conditional |
max = (a > b) ? a : b; |
9. instanceof Operator
| Operator |
Description |
Example |
instanceof |
Object type check |
obj instanceof String |
10. Special Operators
| Operator |
Description |
Example |
. |
Access member |
obj.method() |
[] |
Array access |
arr[0] |
() |
Method call |
method() |
new |
Object creation |
new Scanner() |
Operator Precedence (High → Low)
| Priority |
Operators |
| High |
(), [], . |
|
++, --, ! |
|
*, /, % |
|
+, - |
|
<, >, <=, >= |
|
==, != |
|
&& |
|
` |
| Low |
=, +=, -= |
Operator Precedence Table (High → Low)
| Operator Type |
Category |
Operators |
Associativity |
| Postfix |
Increment / Decrement |
a++, a-- |
Left to Right |
| Unary |
Prefix, Sign, Logical NOT |
++a, --a, +a, -a, !a, ~a |
Right to Left |
| Arithmetic |
Multiplicative |
*, /, % |
Left to Right |
| Arithmetic |
Additive |
+, - |
Left to Right |
| Shift |
Bitwise Shift |
<<, >>, >>> |
Left to Right |
| Relational |
Comparison |
<, >, <=, >=, instanceof |
Left to Right |
| Equality |
Equality Check |
==, != |
Left to Right |
| Bitwise |
AND |
& |
Left to Right |
| Bitwise |
XOR |
^ |
Left to Right |
| Bitwise |
OR |
` |
Left to Right |
| Logical |
Logical AND |
&& |
Left to Right |
| Logical |
Logical OR |
` |
Left to Right |
| Ternary |
Conditional |
?: |
Right to Left |
| Assignment |
Assignment / Shorthand |
=, +=, -=, *=, /=, %= |
Right to Left |
Bitwise Operator
| Operator |
Name |
Description (What it does) |
Example Code |
Binary Operation (Example) |
Output |
|
|
|
& |
Bitwise AND |
Dono bits 1 ho tab result 1 |
int a=5,b=3; a & b; |
0101 & 0011 = 0001 |
1 |
|
|
|
| | |
Bitwise OR |
Koi ek bit bhi 1 ho to result 1 |
`int a=5,b=3; a |
b;` |
`0101 |
0011 = 0111` |
7 |
|
^ |
Bitwise XOR |
Bits different ho tab result 1 |
int a=5,b=3; a ^ b; |
0101 ^ 0011 = 0110 |
6 |
|
|
|
~ |
Bitwise NOT (Complement) |
Bits ko invert karta hai (1 → 0, 0 → 1) |
int a=5; ~a; |
~0101 = 1010 |
-6 |
|
|
|
<< |
Left Shift |
Bits ko left shift karta hai (2ⁿ se multiply) |
int a=5; a << 1; |
0101 << 1 = 1010 |
10 |
|
|
|
>> |
Right Shift |
Bits ko right shift karta hai (2ⁿ se divide) |
int a=10; a >> 1; |
1010 >> 1 = 0101 |
5 |
|
|
|
>>> |
Unsigned Right Shift |
Right shift + sign bit fill with 0 |
int a=-10; a >>> 1; |
Sign bit ignored |
Varies |
|
|
|