//
Browse / Java Programming Cheatsheet
Java Programming Cheatsheet
A comprehensive cheat sheet covering essential Java syntax, data structures, and commonly used libraries, designed to boost your coding efficiency.
Java Basics
Basic Syntax
|
|
Single-line comment. |
|
|
Multi-line comment. |
|
|
Basic class definition. |
|
|
Main method - entry point of execution. |
|
|
Prints text to the console. |
|
|
Integer variable declaration and initialization. |
Data Types
|
|
Integer (4 bytes). |
|
|
Double-precision floating-point number (8 bytes). |
|
|
Boolean (true/false). |
|
|
Sequence of characters. |
|
|
Single character. |
|
|
Single-precision floating-point number (4 bytes). |
Operators
|
|
Arithmetic operators (addition, subtraction, multiplication, division, modulus). |
|
|
Comparison operators (equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to). |
|
|
Logical operators (and, or, not). |
|
|
Assignment operator. |
|
|
Compound assignment operators. |
|
|
Increment and decrement operators. |
Control Flow
Conditional Statements
|
if statement:
|
|
if-else statement:
|
|
if-else if-else statement:
|
|
switch statement:
|
Looping Statements
|
for loop:
|
|
while loop:
|
|
do-while loop:
|
|
enhanced for loop (for-each loop):
|
Branching Statements
|
|
Terminates the loop or switch statement. |
|
|
Skips the current iteration and proceeds to the next iteration of the loop. |
|
|
Exits from the current method. |
Object-Oriented Programming
Classes and Objects
|
Class Definition:
|
|
Object Creation:
|
Inheritance
|
Basic Inheritance:
|
|
Using Inheritance:
|
Polymorphism
|
Method Overriding:
|
|
Using Polymorphism:
|
Encapsulation
|
Example of Encapsulation:
|
|
Using Encapsulation:
|
Collections Framework
Lists
|
ArrayList:
|
|
LinkedList:
|
Sets
|
HashSet:
|
|
TreeSet:
|
Maps
|
HashMap:
|
|
TreeMap:
|