بنقرة واحدة
java-expert
Core Java patterns, modern Java features (JDK 17+), best practices
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Core Java patterns, modern Java features (JDK 17+), best practices
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Maven and Gradle build tools, dependency management, multi-module projects
JUnit 5 testing patterns with Mockito and AssertJ
Spring Boot 3 patterns for controllers, services, configuration, and validation
Spring Data JPA and Hibernate patterns for entities, repositories, and query performance
Spring Security 6 patterns for authentication, authorization, and OAuth2
Spring Boot testing with @SpringBootTest, MockMvc, and Testcontainers
| name | java-expert |
| description | Core Java patterns, modern Java features (JDK 17+), best practices |
| keywords | ["java","jdk","stream","lambda","record","sealed","pattern matching","virtual threads","collections","generics","concurrency"] |
| filePatterns | ["*.java"] |
| frameworks | ["java","jdk"] |
| tokenCount | 2000 |
| version | 1.0.0 |
Modern Java development patterns for JDK 17+ enterprise applications. Think, don't copy. Adapt patterns to context.
Read ONLY files relevant to the request! Check the content map, find what you need.
| File | Description | When to Read |
|---|---|---|
modern-java.md | Records, sealed classes, pattern matching | New Java 17+ features |
streams.md | Stream API patterns, collectors | Data processing |
concurrency.md | Virtual threads, CompletableFuture | Async operations |
collections.md | Collection patterns, immutability | Data structures |
exceptions.md | Error handling, custom exceptions | Exception design |
testing.md | JUnit 5, Mockito patterns | Unit testing |
// Records for immutable data
public record User(String id, String name, String email) {
// Compact constructor for validation
public User {
Objects.requireNonNull(id, "id cannot be null");
Objects.requireNonNull(email, "email cannot be null");
}
}
// Sealed classes for domain modeling
public sealed interface PaymentMethod
permits CreditCard, BankTransfer, Wallet {
}
public record CreditCard(String number, String cvv) implements PaymentMethod {}
public record BankTransfer(String iban) implements PaymentMethod {}
public record Wallet(String walletId) implements PaymentMethod {}
// Pattern matching
public String processPayment(PaymentMethod method) {
return switch (method) {
case CreditCard cc -> processCreditCard(cc);
case BankTransfer bt -> processBankTransfer(bt);
case Wallet w -> processWallet(w);
};
}
// ✅ GOOD: Clear, readable pipeline
List<UserDto> activeUsers = users.stream()
.filter(User::isActive)
.filter(u -> u.getCreatedAt().isAfter(cutoffDate))
.map(UserDto::fromEntity)
.sorted(Comparator.comparing(UserDto::name))
.toList(); // JDK 16+
// ✅ GOOD: Grouping with downstream collector
Map<Department, List<Employee>> byDept = employees.stream()
.collect(Collectors.groupingBy(
Employee::getDepartment,
Collectors.filtering(
Employee::isActive,
Collectors.toList()
)
));
// ❌ BAD: Side effects in stream
users.stream()
.forEach(u -> u.setProcessed(true)); // Side effect!
// ✅ GOOD: Map and collect for transformations
List<User> processed = users.stream()
.map(u -> u.withProcessed(true)) // Immutable
.toList();
// ✅ GOOD: Virtual threads for I/O-bound tasks
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
List<Future<Result>> futures = tasks.stream()
.map(task -> executor.submit(() -> processTask(task)))
.toList();
List<Result> results = futures.stream()
.map(this::getFutureSafely)
.toList();
}
// ✅ GOOD: Structured concurrency (JDK 21+)
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
Supplier<User> user = scope.fork(() -> fetchUser(userId));
Supplier<List<Order>> orders = scope.fork(() -> fetchOrders(userId));
scope.join().throwIfFailed();
return new UserProfile(user.get(), orders.get());
}
// ✅ GOOD: Use Optional for potentially absent values
public Optional<User> findById(String id) {
return Optional.ofNullable(repository.findById(id));
}
// ✅ GOOD: Optional chain
String city = user.flatMap(User::getAddress)
.map(Address::getCity)
.orElse("Unknown");
// ❌ BAD: Optional.get() without check
String name = findById(id).get(); // Throws if empty!
// ✅ GOOD: Defensive alternatives
String name = findById(id)
.map(User::getName)
.orElseThrow(() -> new UserNotFoundException(id));
Before writing Java code:
| Anti-Pattern | Why Bad | Better Approach |
|---|---|---|
| Getters/Setters everywhere | Breaks encapsulation | Records or builder pattern |
| Null returns | NPE risk | Optional or empty collection |
| Checked exceptions for control flow | Performance, readability | Return types or runtime exceptions |
| Raw types | Type safety | Proper generics |
| Thread.sleep() for timing | Unreliable | ScheduledExecutor or virtual threads |
| Need | Skill |
|---|---|
| Build tools | @[skills/maven-gradle] |
| Unit testing | @[skills/testing-junit] |