قابل تلاش، قابل پرنٹ Java حوالہ: ٹائپس، سٹرنگز، کلیکشنز، سٹریمز، ریکارڈز، پیٹرن میچنگ، کنکرنسی اور فائل I/O۔ مفت۔

Basics & types

10
var list = new ArrayList<String>();
Local variable type inference
int x = 42; double d = 3.14;
Primitive declarations
long big = 9_000_000_000L;
Digit separators + long literal
char c = 'A'; boolean ok = true;
Char and boolean primitives
final int MAX = 100;
Constant (cannot be reassigned)
int i = (int) 3.99;
Explicit narrowing cast (→ 3)
double d = x;
Implicit widening conversion
int n = Integer.parseInt("42");
String → int
String s = String.valueOf(42);
Number → string
Integer boxed = 42; int y = boxed;
Auto-boxing and unboxing

Strings & text blocks

12
s.length(); s.charAt(0);
Length and character access
s.substring(1, 3)
Slice (end index exclusive)
s.contains("x"); s.startsWith("a");
Search checks
s.replace("a", "b")
Replace all occurrences
s.strip()
Trim whitespace (Unicode-aware)
s.split(",")
Split into a String[]
String.join(", ", parts)
Join with a separator
"ab".repeat(3)
Repeat a string ("ababab")
s.isBlank(); s.isEmpty();
Whitespace-only / zero-length
"%s: %d".formatted(key, count)
Inline printf-style formatting
String html = """\n <p>Hi</p>\n """;
Multi-line text block
new StringBuilder().append(a).append(b)
Efficient string building in loops

Collections

12
List<String> l = List.of("a", "b");
Immutable list factory
Map<String, Integer> m = Map.of("a", 1);
Immutable map factory
Set<Integer> s = Set.of(1, 2, 3);
Immutable set factory
new ArrayList<>(List.of("a", "b"))
Mutable copy of a list
List.copyOf(list)
Immutable defensive copy
map.getOrDefault(key, 0)
Read with a fallback value
map.computeIfAbsent(k, x -> new ArrayList<>())
Lazily create grouped values
map.merge(key, 1, Integer::sum)
Increment a counter map
list.removeIf(s -> s.isBlank())
Bulk remove matching items
list.sort(Comparator.naturalOrder())
Sort a list in place
for (var e : map.entrySet())
Iterate map entries
list.forEach(System.out::println)
Iterate with a method reference

Streams & lambdas

12
list.stream().map(String::toUpperCase).toList()
Transform every element
.filter(n -> n > 0)
Keep matching elements
.sorted(Comparator.comparing(User::name))
Sort by a key extractor
.distinct().limit(10).skip(5)
Dedupe and paginate a stream
.collect(Collectors.groupingBy(User::city))
Group into Map<K, List<V>>
.collect(Collectors.joining(", "))
Join strings with a separator
.collect(Collectors.toMap(User::id, u -> u))
Build a map from a stream
.flatMap(List::stream)
Flatten nested collections
.mapToInt(Order::total).sum()
Numeric stream aggregation
.reduce(0, Integer::sum)
Fold to a single value
.anyMatch(s -> s.isBlank())
anyMatch / allMatch / noneMatch
IntStream.range(0, 10)
Stream of ints 0..9

Records & sealed classes

9
record Point(int x, int y) {}
Immutable data carrier
var p = new Point(1, 2); p.x();
Construct + generated accessors
equals(), hashCode(), toString()
Generated for free on records
record Range(int lo, int hi) { Range { if (lo > hi) throw new IllegalArgumentException(); } }
Compact constructor validation
record Point(...) implements Shape {}
Records can implement interfaces
static Point origin() { return new Point(0, 0); }
Static factory inside a record
sealed interface Shape permits Circle, Square {}
Restrict allowed subtypes
final class Circle implements Shape {}
Permitted type must be final...
non-sealed class Square implements Shape {}
...or sealed / non-sealed

Pattern matching & switch

8
if (obj instanceof String s) use(s);
instanceof pattern binds a var
int n = switch (day) { case MON -> 1; default -> 0; };
Switch as an expression
case MON, TUE -> "early week";
Multiple labels per arm
case X -> { ...; yield value; }
Block arm returns via yield
case String s when s.length() > 2 ->
Guarded pattern (when clause)
case Point(int x, int y) -> x + y;
Record pattern deconstruction
case null, default -> "none";
Handle null inside the switch
switch (shape) { case Circle c -> ... }
Exhaustive over sealed types

OOP essentials

11
interface Greeter { default String hi() { return "hi"; } }
Interface with default method
class Impl implements A, B {}
Implement multiple interfaces
class Admin extends User {}
Single-class inheritance
@Override public String toString()
Mark overridden methods
super.method(); super(args);
Call parent method / constructor
class Box<T> { T value; }
Generic class
<T extends Comparable<T>> T max(...)
Bounded type parameter
List<? extends Number> nums
Covariant wildcard
enum Status { ACTIVE, DONE }
Enum type (can hold methods)
abstract class Base { abstract void run(); }
Abstract class + method
public static User of(String n) { ... }
Static factory method idiom

Optional

10
Optional.of(v); Optional.empty();
Create (of throws on null)
Optional.ofNullable(maybeNull)
Wrap a possibly-null value
opt.isPresent(); opt.isEmpty();
Presence checks
opt.orElse(defaultValue)
Fallback value
opt.orElseGet(() -> compute())
Lazy fallback (only if empty)
opt.orElseThrow()
Get or throw NoSuchElement
opt.map(User::name).filter(n -> !n.isBlank())
Chain transformations safely
opt.ifPresent(v -> use(v))
Run only when present
opt.ifPresentOrElse(use, this::warn)
Branch on both cases
opt.get()
Avoid: prefer orElseThrow()

Exceptions & try-with-resources

9
try { ... } catch (IOException e) { ... }
Catch a checked exception
catch (IOException | SQLException e)
Multi-catch in one block
finally { cleanup(); }
Always runs (even on throw)
try (var in = Files.newBufferedReader(p)) { ... }
Auto-close resources
throw new IllegalArgumentException("bad id");
Throw with a message
class AppException extends RuntimeException {}
Custom unchecked exception
RuntimeException vs Exception
Unchecked vs checked (declared)
e.getMessage(); e.getCause();
Inspect an exception
Objects.requireNonNull(x, "x is required")
Fail fast on null arguments

Concurrency

12
Thread.startVirtualThread(() -> work());
Cheap virtual thread (21+)
Executors.newVirtualThreadPerTaskExecutor()
One virtual thread per task
var pool = Executors.newFixedThreadPool(4);
Bounded platform thread pool
Future<T> f = pool.submit(task); f.get();
Submit and await a result
CompletableFuture.supplyAsync(() -> fetch())
Async computation
.thenApply(r -> parse(r))
Transform the async result
.thenCombine(other, (a, b) -> a + b)
Join two futures
.exceptionally(e -> fallback)
Recover from async failure
CompletableFuture.allOf(f1, f2).join();
Wait for all to finish
new AtomicInteger().incrementAndGet()
Lock-free counter
new ConcurrentHashMap<K, V>()
Thread-safe map
synchronized (lock) { ... }
Mutual exclusion block

I/O & files (java.nio)

12
Path p = Path.of("data", "file.txt");
Build a platform-safe path
String s = Files.readString(p);
Read a whole file as text
Files.writeString(p, text);
Write text (creates/truncates)
List<String> lines = Files.readAllLines(p);
Read all lines
try (var st = Files.lines(p)) { ... }
Stream lines lazily
Files.exists(p); Files.size(p);
Existence and size checks
Files.createDirectories(dir);
mkdir -p equivalent
Files.copy(src, dst); Files.move(src, dst);
Copy / move files
Files.deleteIfExists(p);
Delete without throwing
try (var files = Files.list(dir)) { ... }
List directory entries
Files.walk(dir)
Recursive directory stream
Files.createTempFile("up-", ".tmp")
Temporary file

Build & CLI

12
javac Main.java && java Main
Compile then run
java Main.java
Run a source file directly
java -jar app.jar
Run an executable jar
java -Xmx512m -jar app.jar
Cap the max heap size
jshell
Interactive Java REPL
mvn clean package
Maven: build the artifact
mvn test
Maven: run the test suite
mvn dependency:tree
Maven: inspect dependencies
./gradlew build
Gradle: full build via wrapper
./gradlew test --tests "UserTest"
Gradle: run selected tests
jar tf app.jar
List a jar's contents
java --version
Show the JDK version

کوئی اندراج “:q” سے میل نہیں کھاتا۔


Java چیٹ شیٹ کے بارے میں

یہ Java چیٹ شیٹ جدید Java کو ایک قابل تلاش صفحے میں سمیٹتی ہے: بنیادی باتیں اور ٹائپس، سٹرنگز اور ٹیکسٹ بلاکس، کلیکشنز، سٹریمز اور لیمبڈاز، ریکارڈز اور سیلڈ کلاسز، پیٹرن میچنگ اور سوئچ، OOP کی ضروری باتیں، Optional، استثنائی صورتیں اور try-with-resources، کنکرنسی، java.nio کے ساتھ فائل I/O، اور بلڈ اور CLI کمانڈز۔

یہ ان بنیادی چیزوں کا بھی احاطہ کرتی ہے جو آپ روز لکھتے ہیں (List، HashMap، for-each لوپ، try-with-resources بلاک) اور ان نئی زبانی خصوصیات کا بھی جنہوں نے Java کے پڑھنے کا انداز بدل دیا، جن میں ریکارڈز، سیلڈ ٹائپس، پیٹرن میچنگ کے ساتھ سوئچ ایکسپریشنز اور ٹیکسٹ بلاکس شامل ہیں۔

شیٹ مفت اور کلائنٹ سائیڈ ہے: سرچ باکس سے قطاروں کو لائیو فلٹر کریں، چپکے رہنے والی فہرست مضامین سے حصوں کے درمیان کودیں، ایک کلک سے کوئی بھی اسنیپٹ کاپی کریں اور اپنے کی بورڈ کے پاس حوالے کے لیے صفحہ پرنٹ کریں۔

Java چیٹ شیٹ استعمال کرنے کا طریقہ

  1. حصوں پر نظر ڈالیں، Basics & types اور Collections سے لے کر Concurrency سے ہوتے ہوئے Build & CLI تک۔
  2. stream، record یا Optional جیسا کوئی کلیدی لفظ تلاش کریں تاکہ ہر قطار لائیو فلٹر ہو جائے۔
  3. جب آپ کو جدید سنٹیکس چاہیے ہو تو Pattern matching & switch یا Streams & lambdas پر جائیں۔
  4. Java کوڈ کو اپنی کلپ بورڈ پر کاپی کرنے کے لیے کسی اسنیپٹ یا اس کے کاپی آئیکن پر کلک کریں۔
  5. آف لائن Java حوالے کے لیے شیٹ پرنٹ کریں۔

اکثر پوچھے جانے والے سوالات

بارہ حصے: بنیادی باتیں اور ٹائپس، سٹرنگز اور ٹیکسٹ بلاکس، کلیکشنز، سٹریمز اور لیمبڈاز، ریکارڈز اور سیلڈ کلاسز، پیٹرن میچنگ اور سوئچ، OOP کی ضروری باتیں، Optional، استثنائی صورتیں اور try-with-resources، کنکرنسی، java.nio فائل I/O، اور بلڈ اور CLI کمانڈز۔

جی ہاں۔ ریکارڈز، سیلڈ کلاسز، ٹیکسٹ بلاکس، var، بہتر سوئچ ایکسپریشنز اور پیٹرن میچنگ ہر ایک کو روایتی سنٹیکس کے ساتھ اپنی الگ قطاریں ملتی ہیں۔

یہ اسی کے گرد بنایا گیا ہے جو آپ واقعی لکھتے ہیں: List، Set، Map اور Deque کی تخلیق اور تکرار، پھر map، filter، collect، groupingBy، reduce اور عام collectors۔

جی ہاں۔ کسی بھی اسنیپٹ یا ہوور پر ظاہر ہونے والے کاپی آئیکن پر کلک کریں اور وہ مختصر تصدیق کے ساتھ آپ کی کلپ بورڈ پر پہنچ جاتا ہے۔

جی ہاں، مکمل طور پر مفت: قابل تلاش، قابل پرنٹ اور بغیر سائن اپ کے آپ کے براؤزر میں رینڈر ہوتا ہے۔

شیئر کریں

مقبول تلاشیں
java چیٹ شیٹ java سنٹیکس حوالہ java کلیکشنز چیٹ شیٹ java سٹریمز مثالیں java ریکارڈز اور سیلڈ کلاسز java switch پیٹرن میچنگ java کنکرنسی کی بنیادی باتیں
مدد چاہیے؟
اس ٹول میں کوئی مسئلہ ملا؟ ہماری ٹیم کو بتائیں۔
مسئلہ رپورٹ کریں

اس مفت ٹول کو اپنی ویب سائٹ پر شامل کریں: نیچے دیا گیا کوڈ کاپی اور پیسٹ کریں۔