Java Programming Language Cheatsheet
Java Programming Language - Beginner Cheat Sheet
(Basics → OOP → Advanced → Professional)
1. What Is Java?
Java is a high-level, object-oriented programming language mainly used for backend systems, APIs, enterprise apps, and Android.
It follows Write Once, Run Anywhere because Java runs on JVM.
2. Basic Program Structure
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
-
classdefines your program. -
main()is where execution starts.
3. Variables
Variables store data in memory.
int age = 25;
String name = "Sumit";
boolean active = true;
Each variable has a type + name + value.
4. Constants
Use final to prevent value changes.
final int MAX = 100;
Constants improve safety and readability.
5. Data Types
Primitive (store direct values)
int, double, char, boolean
Non-Primitive (store object references)
String, Array, Class
Primitive = faster.
Non-primitive = more powerful.
6. Operators
Used to perform calculations and comparisons.
Arithmetic
+ - * / %
Comparison
== != > <
Logical
&& || !
7. Conditional Statements
if / else
if(age > 18){}
else{}
Used to make decisions based on conditions.
switch
switch(day){
case 1: break;
default:
}
Used when checking many fixed values.
8. Loops
Loops repeat code automatically.
for
for(int i=0;i<5;i++){}
while
while(condition){}
do while
do{} while(condition);
9. Arrays
Arrays store multiple values of same type.
int[] nums = {1,2,3};
Access using index: nums[0].
10. Methods
Methods are reusable blocks of code.
static int add(int a,int b){
return a+b;
}
They improve modularity and clarity.
OOP (Core of Java)
11. Class
A class is a blueprint for objects.
class Car{}
12. Object
Object is an instance of class.
Car c = new Car();
13. Constructor
Runs automatically when object is created.
Car(){ }
Used to initialize data.
14. Inheritance
Child class inherits parent properties.
class B extends A{}
Promotes code reuse.
15. Polymorphism
Same method behaves differently.
Overloading
Same method name, different parameters.
Overriding
Child modifies parent method.
16. Encapsulation
Hiding data using private variables.
private int age;
Access via getters/setters.
17. Abstraction
Showing only important details.
Abstract Class
abstract class Shape{}
Interface
interface Animal{}
18. Access Modifiers
public – everywhere
private – same class
protected – same package + child
default – same package
Controls visibility.
19. Packages
Used to organize project structure.
package com.app.service;
20. Exception Handling
Handles runtime errors safely.
try{}
catch(Exception e){}
finally{}
Prevents program crashes.
21. Custom Exception
Create your own error types.
class MyException extends Exception{}
22. Wrapper Classes
Convert primitive to object.
Integer, Double, Boolean
Needed for collections.
23. String Methods
Used to manipulate text.
length(), split(), equals(), substring()
Collections Framework
24. List
Ordered collection with duplicates.
List<String> list = new ArrayList<>();
25. Set
No duplicate values.
Set<Integer> set = new HashSet<>();
26. Map
Key-value pairs.
Map<String,Integer> map = new HashMap<>();
27. Queue
FIFO structure.
Queue<Integer> q = new LinkedList<>();
28. Generics
Allows reusable type-safe code.
class Box<T>{}
29. Lambda Expression
Short function syntax.
(a,b) -> a+b
Used with streams.
30. Streams API
Processes collections functionally.
list.stream().filter().forEach();
Reduces boilerplate loops.
31. Functional Interfaces
Single-method interfaces.
Predicate, Consumer, Supplier
Multithreading
32. Thread
Runs tasks in parallel.
class A extends Thread{}
33. Runnable
Preferred threading method.
class A implements Runnable{}
34. Synchronization
Prevents data conflicts.
synchronized(this){}
File Handling
35. Reading Files
FileReader fr = new FileReader("a.txt");
36. Writing Files
FileWriter fw = new FileWriter("a.txt");
37. Serialization
Converts object into byte stream.
implements Serializable
Database (JDBC)
38. Connection
Connect Java to database.
DriverManager.getConnection()
39. PreparedStatement
Executes SQL safely.
JVM Internals (Interview Critical)
40. JVM Memory
Stack – methods Heap – objects Metaspace – classes
41. Garbage Collection
Automatically deletes unused objects.
Young Gen Old Gen Minor GC Major GC
SOLID Principles
Used for clean architecture.
S – Single Responsibility O – Open Closed L – Liskov I – Interface Segregation D – Dependency Inversion
Design Patterns
Creational
Singleton, Factory, Builder
Structural
Adapter, Facade, Decorator
Behavioral
Observer, Strategy, Command
Professional Java
42. Build Tools
Maven Gradle
Automate dependency management.
43. Spring Boot (Real Projects)
Controllers Services Repositories REST APIs JWT Auth Validation Swagger Pagination
44. Testing
JUnit Mockito
Ensures code reliability.
45. Deployment
Jar Docker CI/CD Cloud
Moves code to production.
46. Advanced Topics
Microservices Kafka Redis ElasticSearch Kubernetes
Used in enterprise systems.