Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

224 Commits

Repository files navigation

Java

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

JavaStatus

📚 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.

TypeSyntax / ExampleNotes
Decimalint a = 10;Normal integer
Octalint b = 012;Starts with 0, decimal 10
Hexadecimalint c = 0xA;Starts with 0x, decimal 10
Binaryint d = 0b1010;Starts with 0b, decimal 10
Longlong l = 100000L;Use L or l
Readableint p = 1_000_000;_ allowed for readability

2. Floating-Point Literals

Numbers with decimal point.

TypeSyntax / ExampleNotes
Floatfloat f = 10.5f;Use f or F
Doubledouble d = 20.75;Default type for decimals
Scientificdouble e = 1.2e3;1200 in decimal

3. Character Literals

Single character enclosed in single quotes.

ExampleNotes
'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.

ExampleNotes
"Hello"Text
"Sujit Kumar Singh"Multiple words
"Line1\nLine2"Escape sequences supported

5. Boolean Literals

Represents true or false values.

ExampleNotes
trueBoolean true value
falseBoolean false value

6. Null Literal

Represents no object reference.

ExampleNotes
String str = null;Only for reference types, not primitive

Notes

  1. Integer types: byte, short, int, long
  2. Floating types: float, double
  3. Characters: Single quotes ' '
  4. Strings: Double quotes " "
  5. Boolean: true or false
  6. Null: For reference variables only
  7. Java supports underscore _ in numeric literals for readability

Data Type

Premitive Data Type

Data TypeDescriptionSize (Fixed)ExampleType
byteVery small integer1 bytebyte a = 10;Integer (Integral)
shortSmall integer2 bytesshort b = 100;Integer (Integral)
intInteger value (whole numbers)4 bytesint c = 1000;Integer (Integral)
longLarge integer8 byteslong d = 100000L;Integer (Integral)
floatSingle-precision decimal number4 bytesfloat e = 3.14f;Floating-Point
doubleDouble-precision decimal number8 bytesdouble f = 3.14159;Floating-Point
charSingle Unicode character2 byteschar g = 'A';Character Type
booleanTrue or false1 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 TypeDescriptionSizeExampleType
StringSequence of characters (String class)DependsString a = "Hello";Text / Reference
ArrayCollection of elements of same data typeDependsint[] b = {1, 2, 3};Collection
ClassBlueprint for creating objectsDependsclass Student { }User-Defined Type
ObjectParent class of all Java classesDependsObject obj = new Object();Universal Reference
InterfaceBlueprint with abstract methodsDependsinterface Shape { }Abstract Type
EnumSet of named constantsDependsenum Day { MON, TUE };Special Class

Java Literals – Table Reference

Literals are fixed values assigned directly to variables in Java. They represent constant data.

Literal TypeExample SyntaxNotes / 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
Longlong l = 10000000000L;Use L or l for long values
Readable Integerint r = 1_000_000;_ can be used for readability
Floatfloat f = 10.5f;Use f or F
Doubledouble d1 = 20.75;Default type for decimals
Scientific (Double)double d2 = 1.2e3;1.2 × 10³ = 1200
Charchar ch = 'A';Single character, uses single quotes
Unicode Charchar ch = '\u0041';Unicode character
StringString name = "Sujit";Sequence of characters
Booleanboolean isJavaFun = true;Only true or false
NullString str = null;Represents no reference
Escape in StringString msg = "Hello\nJava";Supports escape sequences like \n, \t

🔹 Quick Tips

  1. Integer types: byte, short, int, long
  2. Floating types: float, double
  3. Char vs String: 'A' → char, "A" → String
  4. Boolean literals are only true or false.
  5. 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 SequenceMeaning / UsageExample CodeOutput Example
\nNew lineSystem.out.println("Hello\nJava");Hello
Java
\tHorizontal tabSystem.out.println("A\tB\tC");A B C
\\BackslashSystem.out.println("C:\\Users");C:\Users
\'Single quotechar ch = '\'';'
\"Double quoteSystem.out.println("He said \"Hi\"");He said "Hi"
\rCarriage return (cursor to line start)System.out.println("12345\rAB");AB345
\bBackspace (removes previous char)System.out.println("Helloo\b!");Hell!
\fForm feed (page break, mostly printing)System.out.println("Hello\fWorld");(depends on printer)
\uXXXXUnicode characterchar ch = '\u0041';A

🔹 Quick Tips

  1. Escape sequences work only in char or string literals.
  2. Always use double backslash \\ for printing a backslash.
  3. \b and \r may behave differently in console vs files.
  4. Unicode \uXXXX can represent any Unicode character.

Print Hello World

publicclassHelloWorld {
publicstaticvoidmain(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

RegexJava StringDescription
\d\\dDigit (0–9)
\D\\DNon-digit
\w\\wWord character (a–z, A–Z, 0–9, _)
\W\\WNon-word character
\s\\sWhitespace (space, tab, newline)
\S\\SNon-whitespace

Quantifiers

RegexDescription
*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

RegexDescription
^Start of string
$End of string

Character Sets

RegexDescription
[abc]Matches a, b, or c
[a-z]Lowercase letters
[A-Z]Uppercase letters
[0-9]Digits
[^0-9]Not a digit

Groups & Alternation

RegexDescription
(abc)Group
``

Common Patterns

PatternDescription
\\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

OperatorNameExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Modulusa % b

2. Unary Operators

OperatorNameExample
+Unary Plus+a
-Unary Minus-a
++Incrementa++, ++a
--Decrementa--, --a
!Logical NOT!true

3. Assignment Operators

OperatorExampleMeaning
=a = 5Assign
+=a += 2a = a + 2
-=a -= 2a = a - 2
*=a *= 2a = a * 2
/=a /= 2a = a / 2
%=a %= 2a = a % 2

4. Relational (Comparison) Operators

OperatorDescriptionExample
==Equal toa == b
!=Not equal toa != b
>Greater thana > b
<Less thana < b
>=Greater than or equala >= b
<=Less than or equala <= b

5. Logical Operators

OperatorNameExample
&&Logical AND (&&)a > 5 && b < 10
``
!Logical NOT (!)!(a > b)

6. Bitwise Operators

OperatorNameExample
&ANDa & b
``OR
^XORa ^ b
~Complement~a

7. Shift Operators

OperatorNameExample
<<Left Shifta << 1
>>Right Shifta >> 1
>>>Unsigned Right Shifta >>> 1

8. Ternary Operator

OperatorDescriptionExample
?:Conditionalmax = (a > b) ? a : b;

9. instanceof Operator

OperatorDescriptionExample
instanceofObject type checkobj instanceof String

10. Special Operators

OperatorDescriptionExample
.Access memberobj.method()
[]Array accessarr[0]
()Method callmethod()
newObject creationnew Scanner()

Operator Precedence (High → Low)

PriorityOperators
High(), [], .
++, --, !
*, /, %
+, -
<, >, <=, >=
==, !=
&&
`
Low=, +=, -=

Operator Precedence Table (High → Low)

Operator TypeCategoryOperatorsAssociativity
PostfixIncrement / Decrementa++, a--Left to Right
UnaryPrefix, Sign, Logical NOT++a, --a, +a, -a, !a, ~aRight to Left
ArithmeticMultiplicative*, /, %Left to Right
ArithmeticAdditive+, -Left to Right
ShiftBitwise Shift<<, >>, >>>Left to Right
RelationalComparison<, >, <=, >=, instanceofLeft to Right
EqualityEquality Check==, !=Left to Right
BitwiseAND&Left to Right
BitwiseXOR^Left to Right
BitwiseOR`Left to Right
LogicalLogical AND&&Left to Right
LogicalLogical OR`Left to Right
TernaryConditional?:Right to Left
AssignmentAssignment / Shorthand=, +=, -=, *=, /=, %=Right to Left

Bitwise Operator

OperatorNameDescription (What it does)Example CodeBinary Operation (Example)Output
&Bitwise ANDDono bits 1 ho tab result 1int a=5,b=3; a & b;0101 & 0011 = 00011
|Bitwise ORKoi ek bit bhi 1 ho to result 1`int a=5,b=3; ab;``01010011 = 0111`7
^Bitwise XORBits different ho tab result 1int a=5,b=3; a ^ b;0101 ^ 0011 = 01106
~Bitwise NOT (Complement)Bits ko invert karta hai (1 → 0, 0 → 1)int a=5; ~a;~0101 = 1010-6
<<Left ShiftBits ko left shift karta hai (2ⁿ se multiply)int a=5; a << 1;0101 << 1 = 101010
>>Right ShiftBits ko right shift karta hai (2ⁿ se divide)int a=10; a >> 1;1010 >> 1 = 01015
>>>Unsigned Right ShiftRight shift + sign bit fill with 0int a=-10; a >>> 1;Sign bit ignoredVaries

About

Java is a popular & high-level, object-oriented programming language. It is intended to let programmers write once, run anywhere (WORA). Java is used to develop mobile apps, web apps, desktop apps, games and much more.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages