0% found this document useful (0 votes)
6 views20 pages

Java Senior Study Guide

Uploaded by

itsnotberke
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

Java Senior Study Guide

Uploaded by

itsnotberke
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ Java Senior Developer

Kapsaml■ Çal■■ma Rehberi

Design Patterns · Concurrency · Spring Framework · JVM Internals · Generics · Reflection ·


HQL

Yaz■l■m Mühendisleri ■çin — Derinlemesine & Nedenleriyle

■Ç■NDEK■LER

1 Design Patterns
Creational, Structural, Behavioral

2 Java Concurrency & Threads


Thread safety, Locks, Executor framework

3 Spring Framework
IoC, DI, Annotations, AOP
4 JVM Internals & Garbage Collection
Memory model, GC algorithms, TLAB

5 Java Generics
Type parameters, Wildcards, Bounds

6 Java Reflection
Runtime introspection, Method invocation

7 Hibernate & HQL


ORM, Entity mapping, Query language

8 Cryptography in Java
AES, RSA, DSA — ne zaman ne kullan■l■r

9 Spring Boot Microservices


Load balancing, Gateway, Service discovery
1 · Design Patterns
Design Pattern'ler, yaz■l■m tasar■m■nda tekrarlayan problemlere yönelik kan■tlanm■■ çözüm
■ablonlar■d■r. GoF (Gang of Four) kitab■nda 23 temel pattern üç kategoride toplanm■■t■r: Creational,
Structural, Behavioral.

1.1 Singleton Pattern — "Tek Nesne"


Problem: Bir s■n■ftan uygulama genelinde yaln■zca tek bir instance olmas■n■ garantilemek. Örne■in:
veritaban■ ba■lant■s■, configuration manager, logger.

Zorunlu 3 kural:

• private static instance alan■ — d■■ar■dan do■rudan eri■im engellenir


• private constructor — new ile d■■ar■dan nesne olu■turmak engellenir
• public static getInstance() — tek kontrollü giri■ noktas■
// Thread-safe Singleton (Lazy Initialization)
public class Singleton {
private static volatile Singleton instance; // volatile: visibility garantisi
private Singleton() {} // private constructor

public static synchronized Singleton getInstance() {


if (instance == null) {
instance = new Singleton();
}
return instance;
}
}

// En iyi alternatif: Enum Singleton (thread-safe, serile■tirme güvenli)


public enum DatabaseConnection {
INSTANCE;
public void connect() { /* ... */ }
}

■ synchronized olmadan: iki thread ayn■ anda null kontrolü yapabilir ve iki farkl■ nesne olu■turur → Singleton
bozulur.
✓ Enum Singleton en güvenli yöntemdir. Reflection sald■r■s■na ve serile■tirmeye kar■■ korumal■d■r.

1.2 Builder Pattern — "Ad■m Ad■m ■n■a"


Problem: Çok say■da parametreli nesneler olu■tururken constructor hell'den kaç■nmak. Parametre
s■ras■n■ kar■■t■rmak imkâns■z hale gelir.
public class HttpRequest {
private final String url;
private final String method;
private final int timeout;
private final Map<String, String> headers;

private HttpRequest(Builder builder) { // private constructor


[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
}

public static class Builder {


private String url;
private String method = "GET"; // default value
private int timeout = 30;
private Map<String, String> headers = new HashMap<>();

public Builder url(String url) { [Link] = url; return this; }


public Builder method(String method) { [Link] = method; return this; }
public Builder timeout(int t) { [Link] = t; return this; }
public Builder header(String k, String v){ [Link](k,v); return this; }
public HttpRequest build() { return new HttpRequest(this); }
}
}

// Kullan■m — fluent API


HttpRequest req = new [Link]()
.url("[Link]
.method("POST")
.timeout(60)
.header("Authorization", "Bearer token")
.build();

1.3 Factory Method Pattern — "Nesne Üretimi Soyutlama"


Problem: Hangi s■n■f■n instantiate edilece■ini ça■■ran koddan gizlemek. Open/Closed prensibini sa■lar —
yeni tipler eklerken mevcut kod de■i■mez.
public interface Animal {
void speak();
}
public class Dog implements Animal { public void speak() { [Link]("Woof"); } }
public class Cat implements Animal { public void speak() { [Link]("Meow"); } }

// Factory
public class AnimalFactory {
public static Animal create(String type) {
return switch ([Link]()) {
case "dog" -> new Dog();
case "cat" -> new Cat();
default -> throw new IllegalArgumentException("Unknown: " + type);
};
}
}
// Kullan■m
Animal a = [Link]("dog");
[Link](); // Woof

1.4 Observer Pattern — "Olay Yay■nc■s■"


Problem: Bir nesnedeki de■i■ikli■i birden fazla ba■■ml■ nesneye bildirmek. Event-driven mimarilerin temelini
olu■turur (Spring Events, GUI toolkit'ler, Reactive streams).
public interface Observer {
void update(String event, Object data);
}

public class EventBus {


private final Map<String, List<Observer>> listeners = new HashMap<>();

public void subscribe(String event, Observer observer) {


[Link](event, k -> new ArrayList<>()).add(observer);
}

public void publish(String event, Object data) {


[Link](event, [Link]())
.forEach(obs -> [Link](event, data));
}
}
2 · Java Concurrency & Threads
Java'n■n multithreading modeli JVM üzerine kuruludur. Her thread, OS-level bir thread'e map edilir. Java
Memory Model (JMM) hangi ko■ulda bir thread'in ba■ka thread'in yazd■klar■n■ görece■ini tan■mlar.

2.1 Thread Safety Problemleri


Race Condition: ■ki thread ayn■ kayna■a e■ zamanl■ eri■irken verinin tutars■z kalmas■.
// UNSAFE: counter++ atomik de■ildir!
// JVM bunu 3 ad■ma böler: READ → MODIFY → WRITE
public class Counter {
private int count = 0;
public void increment() { count++; } // thread-safe DE■■L
}

// SAFE: AtomicInteger
public class SafeCounter {
private final AtomicInteger count = new AtomicInteger(0);
public void increment() { [Link](); } // CAS (Compare-And-Swap)
}

2.2 synchronized ve Locks

Thread-S
Yöntem Kapsam Ne zaman kullan
afe

synchronized(this) Instance ✓ Basit senaryolar

synchronized(lock) Özel nesne ✓ Daha ince kontrol

synchronized method Tüm metod ✓ Tüm metod kritik

ReentrantLock Manuel ✓ tryLock, timeout, fairness

ReadWriteLock Okuma/Yazma ✓ Okuma yo■un

StampedLock Optimistik ✓ Java 8+, yüksek perf

// ReentrantLock — en güvenli explicit lock kullan■m■


public class DatabaseWriter {
private final ReentrantLock lock = new ReentrantLock();

public void writeToDatabase(String data) {


[Link](); // Kilidi al — ba■ka thread buraya giremez
try {
// Kritik bölge: sadece 1 thread ayn■ anda çal■■■r
performWrite(data);
} finally {
[Link](); // MUTLAKA finally'de — exception olsa bile serbest b■rak
}
}

// tryLock: kilidi alamazsa beklemek yerine false döner


public boolean tryWrite(String data) {
if ([Link]()) {
try {
performWrite(data);
return true;
} finally {
[Link]();
}
}
return false; // Kilit ba■ka thread'deydi, yazma atland■
}
}

■ [Link]() ça■r■s■n■ finally blo■una koymak zorunludur. Aksi hâlde exception sonras■ deadlock olu■ur.

2.3 Executor Framework & ScheduledThreadPoolExecutor


Thread'leri do■rudan olu■turmak (new Thread()) production kodunda anti-pattern'dir. Executor Framework
thread havuzu yönetimini soyutlar.

Factory Metod Tür Ne zaman

[Link](n) Sabit havuz CPU-bound görevler

[Link]() Esnek havuz I/O-bound, k■sa görevler

[Link]() Tek thread S■ral■ i■lem garantisi

[Link](n) Zamanlanm■■ Periyodik/gecikmeli görevler

// scheduleAtFixedRate vs scheduleWithFixedDelay — FARK ÖNEML■


ScheduledExecutorService executor = [Link](3);

// scheduleAtFixedRate: görev her 100s'de B■R BA■LAR (period sabit)


// Görev 120s sürerse: 0s → 120s → 200s → 300s (çak■■ma ya■anabilir)
[Link](
new EmailTask(), // Runnable
30, // initialDelay: ilk çal■■madan önceki bekleme
100, // period: iki ba■lang■ç aras■ndaki süre
[Link]
);

// scheduleWithFixedDelay: bir görev B■TT■KTEN SONRA delay kadar bekler


// Görev 120s sürerse: 0s → 120s → (120+100=)220s → ...
[Link](
new EmailTask(),
30, // initialDelay
100, // delay: biti■ ile sonraki ba■lang■ç aras■
[Link]
);

// Executor'■ kapatmak
[Link](); // Kuyruktaki görevleri bitir, yeni kabul etme
[Link](); // Hemen durdur (interrupt gönder)

✓ ■■ yükü sorusu: "30 sn sonra ba■la, her 100 sn tekrar et" → scheduleAtFixedRate. "Görev bittikten 100 sn sonra
tekrar et" → scheduleWithFixedDelay.

2.4 volatile ve Java Memory Model


// volatile: de■i■kenin her zaman main memory'den okunup yaz■lmas■n■ garantiler
// Visibility problem'ini çözer ama atomikli■i SA■LAMAZ
public class Flag {
private volatile boolean running = true;

public void stop() {


running = false; // Tüm thread'ler bu de■i■ikli■i görür
}

public void run() {


while (running) { // volatile olmasa thread kendi cache'ini okur
doWork();
}
}
}

2.5 TLAB — Thread Local Allocation Buffers


JVM'in eden space'i thread'ler aras■nda payla■■ml■d■r. Her nesne olu■turmada global lock almak
performans■ ciddi ■ekilde dü■ürür. TLAB, her thread'e eden space'in küçük bir bölümünü ay■r■r; thread bu
alanda lock almadan nesne olu■turur.

Durum Aç■klama

TLAB dolmadan Thread kendi TLAB'■ndan lock'suz allocate eder (çok h■zl■)

TLAB dolunca Yeni TLAB talep eder → minor GC tetiklenebilir

Büyük nesneler Do■rudan old gen'e (TLAB bypass) ya da humongous region'a


3 · Spring Framework
Spring'in çekirde■i IoC (Inversion of Control) ve DI (Dependency Injection)'d■r. Nesneler kendi
ba■■ml■l■klar■n■ olu■turmaz; Spring Container olu■turup enjekte eder. Bu yakla■■m loose coupling,
testability ve configurability sa■lar.

3.1 Dependency Injection Türleri

Tür Annotation Avantaj / Dezavantaj

Constructor Injection @Autowired (opsiyonel) Best practice. final alan destekler, immutable, test edilebilir

Setter Injection @Autowired Opsiyonel ba■■ml■l■klar için uygun

Field Injection @Autowired K■sa ama test edilemez, final desteklemez — KAÇIN

@Service
public class UserService {
// Constructor injection — EN ■Y■ PRATIK
private final String hostUrl; // final: immutability
private final UserRepository repo;

// @Value: [Link]'ten de■er enjekte et


// @Autowired: Spring bean'ini enjekte et
public UserService(@Value("${[Link]}") String hostUrl,
@Autowired UserRepository repo) {
[Link] = hostUrl;
[Link] = repo;
}
}

// [Link]
// [Link]=[Link]

// [Link] alternatifi
// api:
// url: [Link]

■ @Value ile String enjeksiyonunda @Autowired gereksizdir — @Value yeterlidir. Setter injection ile final alan
kullan■lamaz.

3.2 Spring Bean Scopes

Scope Tan■m Kullan■m

singleton (default) ApplicationContext'te tek instance


Stateless servisler

prototype Her istekte yeni instance Stateful nesneler

request HTTP request ba■■na Web uygulamalar■

session HTTP session ba■■na Kullan■c■ oturumu

application ServletContext ba■■na Uygulama geneli


3.3 Temel Spring Annotation'lar■
// Stereotype annotations — Spring'e bean oldu■unu söyler
@Component // Genel amaçl■ bean
@Service // ■■ mant■■■ katman■ (semantik fark yok, okunabilirlik için)
@Repository // Veri eri■im katman■ + exception translation
@Controller // MVC web katman■
@RestController // @Controller + @ResponseBody

// Configuration
@Configuration // Java-based bean tan■m■
@Bean // @Configuration içinde metod — return de■eri bean olur
@ComponentScan("[Link]") // Belirtilen paketi tara

// Injection & Properties


@Autowired // Ba■■ml■l■k enjeksiyonu
@Value("${[Link]}") // Property enjeksiyonu
@Qualifier("beanName") // Ayn■ tipte birden fazla bean varsa hangisi?

// Lifecycle
@PostConstruct // Bean olu■turulup inject edildikten sonra çal■■■r
@PreDestroy // Context kapanmadan önce çal■■■r
4 · JVM Internals & Garbage Collection

4.1 JVM Memory Yap■s■

GC'ye tabi
Alan ■çerik
mi?

Heap – Young Gen (Eden + S0/S1) Yeni nesneler Evet – Minor GC

Heap – Old Gen (Tenured) Uzun ömürlü nesneler Evet – Major GC

Metaspace (Java 8+) Class metadata Evet (varsay■lan limitsiz)

Stack Her thread'in call stack'i, local de■i■kenler Hay■r

Program Counter Çal■■t■r■lan bytecode adresi Hay■r

Native Method Stack JNI metod ça■r■lar■ Hay■r

4.2 GC Algoritmalar■

Stop-the-Worl
Collector Kullan■m Durumu
d

Serial GC Evet – uzun Küçük uygulamalar, tek çekirdek

Parallel GC (default <Java9)


Evet – paralel Throughput odakl■ batch i■lemler

CMS (deprecated) K■smen Dü■ük latency (eski uygulamalar)

G1 GC (default Java9+) K■smen Büyük heap, dengeli throughput/latency

ZGC (Java 15+) Çok k■sa (<1ms) Ultra-low latency, büyük heap

Shenandoah Çok k■sa OpenJDK, concurrent compaction

4.3 Stop-the-World ve TLAB


Stop-the-World (STW): GC çal■■■rken tüm uygulama thread'leri durdurulur. Bu latency spike'lara neden olur.
TLAB (Thread Local Allocation Buffer), her thread'e eden space'in küçük bir bölümünü özel olarak tahsis ederek
global lock ihtiyac■n■ ortadan kald■r■r ve minor GC s■kl■■■n■ azalt■r.
✓ K■sa ömürlü çok say■da nesne olu■turan multithreaded uygulamalarda TLAB boyutunu art■rmak (-XX:TLABSize)
GC bask■s■n■ azalt■r.
5 · Java Generics
Generics, compile-time type safety sa■lar. Runtime'da type erasure ile silinir — JVM bytecode seviyesinde
generics yoktur, Object'e dönü■türülür.

5.1 Type Parameter Kurallar■

Notasyon Anlam■

<T> Herhangi bir tip (convention: T=Type, E=Element, K=Key, V=Value)

<T extends Number> T, Number'dan türemi■ olmak zorunda (upper bound)

<T super Integer> T, Integer'in üst s■n■f■ olmak zorunda (lower bound)

<?> Wildcard: bilinmeyen tip (read-only)

<? extends Number> Bounded wildcard: Number alt s■n■flar■ (producer)

<? super Integer> Bounded wildcard: Integer üst s■n■flar■ (consumer)

// Generic class örne■i — Pair<T, S>


public class Pair<T, S> {
private T first;
private S second;

public Pair(T first, S second) {


[Link] = first;
[Link] = second;
}
public T getFirst() { return first; }
public S getSecond() { return second; }
}

// Numerik toplama için bound gerekli


// T ve S'nin Number oldu■unu garantilemeden .doubleValue() ça■r■lamaz
public static <T extends Number, S extends Number>
double sum(Pair<T, S> pair) {
return [Link]().doubleValue() + [Link]().doubleValue();
}

// Kullan■m
Pair<Integer, Double> p = new Pair<>(5, 3.14);
double result = sum(p); // 8.14

5.2 PECS Prensibi


PECS: Producer Extends, Consumer Super. Bir collection'dan okuyacaksan■z (producer) extends,
yazacaksan■z (consumer) super kullan■n.
// Extends: listeden okuma (Number ve alt s■n■flar)
public double sumList(List<? extends Number> list) {
return [Link]().mapToDouble(Number::doubleValue).sum();
}
// Super: listeye yazma (Integer ve üstleri)
public void addIntegers(List<? super Integer> list) {
[Link](1);
[Link](2);
}
6 · Java Reflection
Reflection, runtime'da s■n■f yap■s■n■ (field, method, constructor, annotation) incelemeye ve manipüle
etmeye olanak tan■r. Spring, Hibernate gibi framework'lerin temeli Reflection'd■r.

6.1 getMethod vs getDeclaredMethod

Metod Kapsam setAccessible gerekli mi?

getMethod("name") Sadece public metodlar (miras dahil) Genellikle hay■r

getDeclaredMethod("name") Tüm eri■im seviyeleri (bu s■n■f) private için evet

getMethods() Tüm public metodlar (dizi) Hay■r

getDeclaredMethods() Bu s■n■ftaki tüm metodlar private için evet

// Reflection ile method invocation


public class Person {
private String firstName;
private String lastName;

public Person(String firstName, String lastName) {


[Link] = firstName;
[Link] = lastName;
}
public void displayFullName() {
[Link]("Full Name: " + firstName + " " + lastName);
}
}

// ✓ Do■ru kullan■m (public method)


Person bob = new Person("Bob", "Smith");
Method method = [Link]("displayFullName"); // public, setAccessible gerekmez
[Link](true); // iyi pratik olarak yine de eklenebilir
[Link](bob); // "Full Name: Bob Smith"

// Private field'a eri■im


Field field = [Link]("firstName");
[Link](true); // private'■ aç
String value = (String) [Link](bob); // "Bob"
[Link](bob, "Robert"); // de■er de■i■tir

■ Reflection performans aç■s■ndan pahal■d■r. Production'da hot path'lerde kullanmaktan kaç■n■n. Framework
kodunda (ba■lang■ç zaman■) uygundur.
7 · Hibernate & HQL
Hibernate bir ORM (Object-Relational Mapping) framework'üdür. Java nesnelerini veritaban■ tablolar■na
e■ler. HQL (Hibernate Query Language), SQL'e benzer ama veritaban■ tablolar■na de■il Java entity
s■n■flar■na yöneliktir.

7.1 Entity Mapping Annotationlar■


@Entity // Bu s■n■f bir DB tablosunu temsil eder
@Table(name = "books") // DB'deki tablo ad■ (opsiyonel, varsay■lan = class ad■)
public class Book {
@Id // Primary key
@GeneratedValue(strategy = [Link]) // Auto increment
@Column(name = "id") // DB kolon ad■ (opsiyonel)
private int id;

@Column(name = "title", nullable = false, length = 200)


private String title;

@Column(name = "price")
private double price;

// Getters & Setters...


}

7.2 SQL vs HQL — Kritik Fark

Özellik SQL HQL

Referans eder Veritaban■ tablolar■ Java entity s■n■flar■

Tablo ad■ books (DB ad■) Book (Java class ad■)

Alan ad■ price (kolon ad■) [Link] (Java field ad■)

SELECT all SELECT * SELECT b (entity döner)

Alias Opsiyonel Genellikle kullan■l■r

DB ba■■ms■zl■k Hay■r Evet (Hibernate dialect)

-- SQL (veritaban■na özgü)


SELECT id, title, author, price FROM books WHERE price > 10;

-- HQL (Java s■n■flar■na yönelik)


SELECT b FROM Book b WHERE [Link] > 10

-- Book = Java class ad■ (DB tablo ad■ "books" DE■■L)


-- b = alias
-- [Link] = Java field ad■ (DB kolon ad■ "price" de■il — burada ayn■ ama farkl■ olabilir)

// Hibernate Session ile çal■■t■rma


Session session = [Link]();
List<Book> books = [Link](
"SELECT b FROM Book b WHERE [Link] > :minPrice", [Link])
.setParameter("minPrice", 10.0)
.getResultList();
8 · Java'da Kriptografi
Algoritm Güvenli Kanal
Tür Anahtar Kullan■m
a Gereki

AES Simetrik Tek anahtar Veri ■ifreleme (h■z) Evet

RSA Asimetrik Public + Private Anahtar de■i■imi, imza Hay■r

DSA Asimetrik Public + Private Sadece dijital imza Hay■r

SHA-256 Hash Yok Bütünlük do■rulama N/A

8.1 RSA — Public Key Infrastructure


RSA asimetrik ■ifrelemedir. ■ki anahtar çifti vard■r: Public Key (herkese payla■■l■r) ve Private Key (asla
payla■■lmaz). Gönderen public key ile ■ifreler, al■c■ private key ile çözer.
// RSA ile ■ifreleme/de■ifreleme
import [Link].*;
import [Link];

// Anahtar çifti olu■tur


KeyPairGenerator keyGen = [Link]("RSA");
[Link](2048); // 2048 bit — güvenli minimum
KeyPair pair = [Link]();

PublicKey publicKey = [Link](); // Payla■■labilir


PrivateKey privateKey = [Link](); // G■ZL■ KALACAK

// ■ifreleme — public key ile


Cipher cipher = [Link]("RSA");
[Link](Cipher.ENCRYPT_MODE, publicKey);
byte[] encrypted = [Link]("Gizli mesaj".getBytes());

// De■ifreleme — SADECE private key ile


[Link](Cipher.DECRYPT_MODE, privateKey);
byte[] decrypted = [Link](encrypted);
[Link](new String(decrypted)); // "Gizli mesaj"

// AES — simetrik (ayn■ anahtar ■ifreler ve çözer)


// Güvenli anahtar payla■■m■ için önce RSA kullan■l■r,
// sonra AES anahtar■ RSA ile ■ifrelenip iletilir (hybrid encryption)

■ DSA dijital imza içindir, ■ifreleme yapamaz. AES için anahtar payla■■m■ sorunu vard■r — güvenli kanal gerektirir.
9 · Spring Boot Microservices & Load
Balancing
Microservices mimarisinde her servis ba■■ms■z deploy edilir. Yük dengeleme ve servis ke■fi için Spring
Cloud ekosistemi kullan■l■r.

9.1 Load Balancing Stratejileri

Bile■en Katman Aç■klama

Netflix Ribbon Client-side ■stemci hangi instance'a gidece■ine kendisi karar verir

Spring Cloud Gateway API Gateway Gelen istekleri route eder, cross-cutting concerns

Eureka Service Registry Servisler kendini kaydeder, di■erleri IP'yi buradan ö■renir

Kubernetes (k8s) Infrastructure Pod scaling, rolling update, service discovery

Nginx / HAProxy Network LB L4/L7 load balancing, upstream round-robin

9.2 Spring Cloud Gateway Konfigürasyonu


# [Link] — Spring Cloud Gateway route tan■m■
spring:
cloud:
gateway:
routes:
- id: user-service
uri: lb://USER-SERVICE # lb:// → Ribbon/LoadBalancer kullan
predicates:
- Path=/api/users/**
filters:
- StripPrefix=1
- name: CircuitBreaker
args:
name: userServiceCB
fallbackUri: forward:/fallback/users

# Eureka client
eureka:
client:
serviceUrl:
defaultZone: [Link]

// @LoadBalanced ile RestTemplate — client-side load balancing


@Configuration
public class AppConfig {
@Bean
@LoadBalanced // Eureka'dan servis ad■n■ IP'ye çevirir + load balance
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
@Service
public class UserClient {
@Autowired
private RestTemplate restTemplate;

public User getUser(String userId) {


// "USER-SERVICE" → Eureka'dan IP listesi al■n■r, Ribbon seçer
return [Link](
"[Link] + userId,
[Link]
);
}
}

9.3 Microservices Deseni: Circuit Breaker


Bir servis devre d■■■ysa tüm sistem çökmemeli. Circuit Breaker (Resilience4j/Hystrix), ba■lant■
denemelerini belirli bir e■i■in üzerinde ba■ar■s■z olunca keser ve fallback yan■t döner.
@Service
public class PaymentService {

@CircuitBreaker(name = "paymentCB", fallbackMethod = "paymentFallback")


@Retry(name = "paymentRetry")
public PaymentResult processPayment(Order order) {
return [Link](order);
}

// Circuit aç■ksa bu metod ça■r■l■r


public PaymentResult paymentFallback(Order order, Exception ex) {
return [Link]("Ödeme servisi geçici olarak kullan■lam■yor.");
}
}
H■zl■ Referans — Exam Cheat Sheet
Konu Anahtar Nokta Yayg■n Tuzak

Singleton private constructor + private static instance + synchronizedsynchronized


getInstance()yoksa thread-unsafe

Builder inner static Builder class, fluent API, final alanlar Constructor overloading ile kar■■t■rma

Factory Nesne üretimini soyutla, OCP sa■la new ile do■rudan olu■turma — coupling artar

Observer Publisher/Subscriber, event-driven Memory leak: unsubscribe unutmak

synchronized lock al, kritik bölge, lock b■rak finally'de unlock yazmamak → deadlock

ReentrantLock lock() + try/finally + unlock() tryLock: s■ral■ i■lem garantisi VERMEZ

scheduleAtFixedRate Ba■lang■ç zamanlar■ sabit aral■kl■ scheduleWithFixedDelay ile kar■■t■rma

volatile Visibility garantisi, atomiklik YOK count++ için volatile yetmez, Atomic gerek

TLAB Thread ba■■na eden bölgesi, lock-free alloc Büyük nesneler do■rudan old gen'e gider

@Value Properties'ten inject, constructor ile final Setter ile final alan kullan■lamaz

@Autowired Bean inject, field injection kötü pratik @Value ile String inject edilemez

HQL Java class ad■ kullan■l■r, entity döner Tablo ad■ yazmak (SQL ile kar■■t■rma)

getMethod() Sadece public metodlar getDeclaredMethod: tüm eri■im + setAccessible gerekir

RSA Asimetrik, public key payla■, private gizli DSA imza içindir, ■ifreleme yapamaz

Generics T extends Number


.doubleValue() ça■■rmak için gerekli Raw type kullan■m■ compile hatas■na neden olur

Bu rehber Java Senior Developer Assessment'lar■nda ç■kan gerçek sorular baz al■narak haz■rlanm■■t■r. Her
konsept "neden" sorusuyla birlikte aç■klanm■■t■r. ■yi çal■■malar!

You might also like