java
यह क्या करती है
यह गाइड बताती है कि Java में ज़्यादा कारगर और आधुनिक code कैसे लिखें। इसमें नई language features इस्तेमाल करने के उदाहरण दिए गए हैं, ताकि आपका code साफ़ और समझने में आसान बने।
कब इस्तेमाल करें
- ✓जब Java में code लिखने के नए तरीके सीखने हों।
- ✓जब मौजूदा Java code को देखना या सुधारना हो।
- ✓जब Java की modern features इस्तेमाल करनी हों।
Skill का लिंक
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/java/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं Java में list के items filter और transform करने के लिए Streams का इस्तेमाल कैसे कर सकता हूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
AI आपके code की तुलना Java की best practice examples से करता है। वह Streams, Optional और Records जैसी features सुझाता है, जिनसे आम काम आसान होते हैं और गलतियाँ कम होती हैं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Java: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for java.
Table of Contents
- Streams & Collections
- Optional
- Records & Data Classes
- Switch Expressions
- Concurrency
- Error Handling
- Anti-patterns specific to Java
1. Streams & Collections {#streams}
// ❌ Imperative accumulation
List<String> result = new ArrayList<>();
for (Item item : items) {
if (item.isActive()) result.add(item.getName().toUpperCase());
}
// ✅
List<String> result = items.stream()
.filter(Item::isActive)
.map(item -> item.getName().toUpperCase())
.toList(); // Java 16+; use .collect(Collectors.toList()) before
// ❌ Manual grouping
Map<String, List<Item>> grouped = new HashMap<>();
for (Item item : items) {
grouped.computeIfAbsent(item.getCategory(), k -> new ArrayList<>()).add(item);
}
// ✅
Map<String, List<Item>> grouped = items.stream()
.collect(Collectors.groupingBy(Item::getCategory));
// ❌ Manual sum
int total = 0;
for (Order o : orders) total += o.getAmount();
// ✅
int total = orders.stream().mapToInt(Order::getAmount).sum();
Prefer method references (Item::isActive) over equivalent lambdas (item -> item.isActive()).
2. Optional {#optional}
// ❌ Null check chain
String city = null;
if (user != null && user.getAddress() != null) {
city = user.getAddress().getCity();
}
// ✅
String city = Optional.ofNullable(user)
.map(User::getAddress)
.map(Address::getCity)
.orElse(null);
// ❌ Optional.get() without isPresent()
String name = optional.get(); // throws if empty
// ✅
String name = optional.orElse("default");
// or: optional.orElseThrow(() -> new IllegalStateException("name required"));
// ❌ Optional as a field or parameter (anti-pattern)
class User { private Optional<String> nickname; }
// ✅ — Optional is for return types only
class User { private String nickname; } // nullable field
public Optional<String> getNickname() { return Optional.ofNullable(nickname); }
3. Records & Data Classes {#records}
// ❌ Manual POJO
class Point {
private final int x, y;
public Point(int x, int y) { this.x = x; this.y = y; }
public int getX() { return x; }
public int getY() { return y; }
// + equals, hashCode, toString...
}
// ✅ (Java 16+)
record Point(int x, int y) {}
// ❌ Builder pattern for a 2-field object
User user = new User.Builder().name("Alice").age(30).build();
// ✅ — use record or constructor directly for small objects
record User(String name, int age) {}
var user = new User("Alice", 30);
Use record for any immutable data carrier. Keep builders only for objects with many optional fields.
4. Switch Expressions {#switch}
// ❌ Switch statement with fall-through and break
String label;
switch (status) {
case ACTIVE: label = "Active"; break;
case INACTIVE: label = "Inactive"; break;
default: label = "Unknown";
}
// ✅ (Java 14+)
String label = switch (status) {
case ACTIVE -> "Active";
case INACTIVE -> "Inactive";
default -> "Unknown";
};
// ❌ instanceof + cast
if (shape instanceof Circle) {
Circle c = (Circle) shape;
return c.radius() * c.radius() * Math.PI;
}
// ✅ Pattern matching (Java 16+)
if (shape instanceof Circle c) {
return c.radius() * c.radius() * Math.PI;
}
5. Concurrency {#concurrency}
// ❌ Raw Thread creation
Thread t = new Thread(() -> doWork());
t.start();
// ✅
ExecutorService exec = Executors.newVirtualThreadPerTaskExecutor(); // Java 21
exec.submit(() -> doWork());
// ❌ synchronized on this for fine-grained state
synchronized(this) { counter++; }
// ✅
AtomicInteger counter = new AtomicInteger();
counter.incrementAndGet();
Prefer CompletableFuture.allOf() over blocking .get() chains for parallel async work.
6. Error Handling {#errors}
// ❌ Catching Exception to log and swallow
try {
risky();
} catch (Exception e) {
log.error("error", e);
}
// ✅ — rethrow as unchecked if you can't handle it
try {
risky();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
// ❌ Checked exceptions declared on every method
…
अक्सर पूछे जाने वाले सवाल
Java में 'Records' क्या हैं?
Records एक आसान तरीका है immutable classes बनाने का, जो data रखती हैं, जैसे एक 'जानकारी का डिब्बा'। इसके लिए बार-बार लिखा जाने वाला ज़्यादा code नहीं लिखना पड़ता।
'Optional' क्यों इस्तेमाल करें?
Optional उन values को संभालने में मदद करता है जो हो भी सकती हैं और नहीं भी ('null' errors से बचाव)। इससे code ज़्यादा सुरक्षित रहता है और साफ़ रहता है कि क्या उम्मीद करनी है।
'Streams' क्या हैं?
Streams data की sequence (जैसे list) को प्रोसेस करने का तरीका है, जिसमें आप बताते हैं कि क्या करना है। इनमें filtering और transforming जैसे कामों को एक के बाद एक जोड़ा जा सकता है।
जानकारी
लेखक का मूल विवरण
Language-specific super-code guidelines for java.
लोकप्रियता
- GitHub स्टार
- 48k
- रैंकिंग में स्थान
- #5893
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
00-andruia-consultant
48kआपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।
007
48kआपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।
10-andruia-skill-smith
48kआपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।
20-andruia-niche-intelligence
48kआपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।