Java Fundamentals Skill
Master core Java programming with production-quality patterns.
Overview
This skill covers Java fundamentals including syntax, OOP, collections, streams API, and exception handling for Java 8-21.
When to Use This Skill
Use when you need to:
- Write clean, idiomatic Java code
- Design classes following OOP principles
- Choose appropriate collection types
- Implement functional programming patterns
- Handle exceptions properly
Topics Covered
Core Syntax (Java 8-21)
- Variables, data types, operators
- Control flow, methods, classes
- Records (Java 16+), sealed classes (Java 17+)
- Pattern matching (Java 21)
Object-Oriented Programming
- Classes, inheritance, polymorphism
- Interfaces and abstract classes
- SOLID principles
Collections Framework
- List: ArrayList, LinkedList
- Set: HashSet, TreeSet
- Map: HashMap, ConcurrentHashMap
- Queue: ArrayDeque, PriorityQueue
Streams API
- filter, map, flatMap, reduce, collect
- Optional handling
- Parallel streams
Exception Handling
- Checked vs unchecked exceptions
- Try-with-resources
- Custom exceptions
Quick Reference
// Record (Java 16+)
public record User(String name, String email) {}
// Pattern matching (Java 21)
String format(Object obj) {
return switch (obj) {
case Integer i -> "Int: %d".formatted(i);
case String s -> "String: %s".formatted(s);
default -> obj.toString();
};
}
// Stream operations
List<String> names = users.stream()
.filter(User::isActive)
.map(User::getName)
.sorted()
.toList();
// Optional handling
String name = Optional.ofNullable(user)
.map(User::getName)
.orElse("Unknown");
Collection Selection
| Need |
Use |
Reason |
| Indexed access |
ArrayList |
O(1) random access |
| Unique elements |
HashSet |
O(1) contains |
| Sorted unique |
TreeSet |
O(log n) sorted |
| Key-value pairs |
HashMap |
O(1) get/put |
Troubleshooting
| Problem |
Cause |
Solution |
| NullPointerException |
Null reference |
Use Optional |
| ConcurrentModificationException |
Modify during iteration |
Iterator.remove() |
| ClassCastException |
Wrong type |
Use generics |
Usage
Skill("java-fundamentals")
1---2name: java-fundamentals3description: Master core Java programming - syntax, OOP, collections, streams, and exception handling4---5
6# Java Fundamentals Skill
7
8Master core Java programming with production-quality patterns.
9
10## Overview
11
12This skill covers Java fundamentals including syntax, OOP, collections, streams API, and exception handling for Java 8-21.
13
14## When to Use This Skill
15
16Use when you need to:
17- Write clean, idiomatic Java code
18- Design classes following OOP principles
19- Choose appropriate collection types
20- Implement functional programming patterns
21- Handle exceptions properly
22
23## Topics Covered
24
25### Core Syntax (Java 8-21)
26- Variables, data types, operators
27- Control flow, methods, classes
28- Records (Java 16+), sealed classes (Java 17+)
29- Pattern matching (Java 21)
30
31### Object-Oriented Programming
32- Classes, inheritance, polymorphism
33- Interfaces and abstract classes
34- SOLID principles
35
36### Collections Framework
37- List: ArrayList, LinkedList
38- Set: HashSet, TreeSet
39- Map: HashMap, ConcurrentHashMap
40- Queue: ArrayDeque, PriorityQueue
41
42### Streams API
43- filter, map, flatMap, reduce, collect
44- Optional handling
45- Parallel streams
46
47### Exception Handling
48- Checked vs unchecked exceptions
49- Try-with-resources
50- Custom exceptions
51
52## Quick Reference
53
54```java
55// Record (Java 16+)
56public record User(String name, String email) {}
57
58// Pattern matching (Java 21)
59String format(Object obj) {
60 return switch (obj) {
61 case Integer i -> "Int: %d".formatted(i);
62 case String s -> "String: %s".formatted(s);
63 default -> obj.toString();
64 };
65}
66
67// Stream operations
68List<String> names = users.stream()
69 .filter(User::isActive)
70 .map(User::getName)
71 .sorted()
72 .toList();
73
74// Optional handling
75String name = Optional.ofNullable(user)
76 .map(User::getName)
77 .orElse("Unknown");
78```
79
80## Collection Selection
81
82| Need | Use | Reason |
83|------|-----|--------|
84| Indexed access | ArrayList | O(1) random access |
85| Unique elements | HashSet | O(1) contains |
86| Sorted unique | TreeSet | O(log n) sorted |
87| Key-value pairs | HashMap | O(1) get/put |
88
89## Troubleshooting
90
91| Problem | Cause | Solution |
92|---------|-------|----------|
93| NullPointerException | Null reference | Use Optional |
94| ConcurrentModificationException | Modify during iteration | Iterator.remove() |
95| ClassCastException | Wrong type | Use generics |
96
97## Usage
98
99```
100Skill("java-fundamentals")
101```