Skip to content

Commit f4f1282

Browse files
committed
Add Java core modules
1 parent 80e8982 commit f4f1282

34 files changed

Lines changed: 1408 additions & 29 deletions

File tree

CONCEPT_INDEX.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ Use this page to browse the same concept across every active language track.
2525

2626
| Concept | C++ | C# | Go | Java | Python | TypeScript |
2727
| --- | --- | --- | --- | --- | --- | --- |
28-
| input-validation | [C++](languages/cpp/02-core/input-validation/README.md) | [C#](languages/csharp/02-core/input-validation/README.md) | [Go](languages/go/02-core/input-validation/README.md) | Planned | [Python](languages/python/02-core/input-validation/README.md) | [TypeScript](languages/typescript/02-core/input-validation/README.md) |
29-
| algorithms-basics | [C++](languages/cpp/02-core/algorithms-basics/README.md) | [C#](languages/csharp/02-core/algorithms-basics/README.md) | [Go](languages/go/02-core/algorithms-basics/README.md) | Planned | [Python](languages/python/02-core/algorithms-basics/README.md) | [TypeScript](languages/typescript/02-core/algorithms-basics/README.md) |
30-
| file-io-basics | [C++](languages/cpp/02-core/file-io-basics/README.md) | [C#](languages/csharp/02-core/file-io-basics/README.md) | [Go](languages/go/02-core/file-io-basics/README.md) | Planned | [Python](languages/python/02-core/file-io-basics/README.md) | [TypeScript](languages/typescript/02-core/file-io-basics/README.md) |
31-
| sorting-and-searching | [C++](languages/cpp/02-core/sorting-and-searching/README.md) | [C#](languages/csharp/02-core/sorting-and-searching/README.md) | [Go](languages/go/02-core/sorting-and-searching/README.md) | Planned | [Python](languages/python/02-core/sorting-and-searching/README.md) | [TypeScript](languages/typescript/02-core/sorting-and-searching/README.md) |
32-
| maps-and-frequency-counting | [C++](languages/cpp/02-core/maps-and-frequency-counting/README.md) | [C#](languages/csharp/02-core/maps-and-frequency-counting/README.md) | [Go](languages/go/02-core/maps-and-frequency-counting/README.md) | Planned | [Python](languages/python/02-core/maps-and-frequency-counting/README.md) | [TypeScript](languages/typescript/02-core/maps-and-frequency-counting/README.md) |
33-
| error-handling-and-defensive-programming | [C++](languages/cpp/02-core/error-handling-and-defensive-programming/README.md) | [C#](languages/csharp/02-core/error-handling-and-defensive-programming/README.md) | [Go](languages/go/02-core/error-handling-and-defensive-programming/README.md) | Planned | [Python](languages/python/02-core/error-handling-and-defensive-programming/README.md) | [TypeScript](languages/typescript/02-core/error-handling-and-defensive-programming/README.md) |
28+
| input-validation | [C++](languages/cpp/02-core/input-validation/README.md) | [C#](languages/csharp/02-core/input-validation/README.md) | [Go](languages/go/02-core/input-validation/README.md) | [Java](languages/java/02-core/input-validation/README.md) | [Python](languages/python/02-core/input-validation/README.md) | [TypeScript](languages/typescript/02-core/input-validation/README.md) |
29+
| algorithms-basics | [C++](languages/cpp/02-core/algorithms-basics/README.md) | [C#](languages/csharp/02-core/algorithms-basics/README.md) | [Go](languages/go/02-core/algorithms-basics/README.md) | [Java](languages/java/02-core/algorithms-basics/README.md) | [Python](languages/python/02-core/algorithms-basics/README.md) | [TypeScript](languages/typescript/02-core/algorithms-basics/README.md) |
30+
| file-io-basics | [C++](languages/cpp/02-core/file-io-basics/README.md) | [C#](languages/csharp/02-core/file-io-basics/README.md) | [Go](languages/go/02-core/file-io-basics/README.md) | [Java](languages/java/02-core/file-io-basics/README.md) | [Python](languages/python/02-core/file-io-basics/README.md) | [TypeScript](languages/typescript/02-core/file-io-basics/README.md) |
31+
| sorting-and-searching | [C++](languages/cpp/02-core/sorting-and-searching/README.md) | [C#](languages/csharp/02-core/sorting-and-searching/README.md) | [Go](languages/go/02-core/sorting-and-searching/README.md) | [Java](languages/java/02-core/sorting-and-searching/README.md) | [Python](languages/python/02-core/sorting-and-searching/README.md) | [TypeScript](languages/typescript/02-core/sorting-and-searching/README.md) |
32+
| maps-and-frequency-counting | [C++](languages/cpp/02-core/maps-and-frequency-counting/README.md) | [C#](languages/csharp/02-core/maps-and-frequency-counting/README.md) | [Go](languages/go/02-core/maps-and-frequency-counting/README.md) | [Java](languages/java/02-core/maps-and-frequency-counting/README.md) | [Python](languages/python/02-core/maps-and-frequency-counting/README.md) | [TypeScript](languages/typescript/02-core/maps-and-frequency-counting/README.md) |
33+
| error-handling-and-defensive-programming | [C++](languages/cpp/02-core/error-handling-and-defensive-programming/README.md) | [C#](languages/csharp/02-core/error-handling-and-defensive-programming/README.md) | [Go](languages/go/02-core/error-handling-and-defensive-programming/README.md) | [Java](languages/java/02-core/error-handling-and-defensive-programming/README.md) | [Python](languages/python/02-core/error-handling-and-defensive-programming/README.md) | [TypeScript](languages/typescript/02-core/error-handling-and-defensive-programming/README.md) |
3434

3535
### 03-advanced
3636

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Thank you for contributing to this repository.
99
- Use clear English for all text, comments, and instructions.
1010
- Maintain cross-platform compatibility (Windows MSYS2 + Linux).
1111
- Keep Node-based tooling simple and explicit when touching the TypeScript track.
12-
- Keep Java foundations on plain `javac`/`java` until the track intentionally adopts build tooling.
12+
- Keep Java modules on plain `javac`/`java` until the track intentionally adopts build tooling.
1313

1414
## Workflow
1515

@@ -99,7 +99,7 @@ Use [EDUCATIONAL_EXAMPLE_REVIEW_RUBRIC.md](EDUCATIONAL_EXAMPLE_REVIEW_RUBRIC.md)
9999
- Avoid external dependencies and test frameworks for C++ modules.
100100
- Avoid external dependencies and test frameworks for non-C++ checkpoints.
101101
- Keep the TypeScript track on plain Node console programs; do not introduce browser, DOM, or framework dependencies.
102-
- Keep the Java foundations MVP on package-free single-file programs; do not introduce Maven, Gradle, or `src/main/java` yet.
102+
- Keep the Java MVP on package-free single-file programs; do not introduce Maven, Gradle, or `src/main/java` yet.
103103
- Keep examples aligned with C++17.
104104
- Keep documentation in English and keep path names consistent with folder names.
105105
- Keep parity planning updated in `LANGUAGE_PARITY_MATRIX.md` when adding modules or checkpoints to non-C++ tracks.

LANGUAGE_PARITY_MATRIX.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This matrix tracks module and checkpoint parity across C++, C#, Go, Java, Python
44

55
- Canonical order is defined by the C++ track.
66
- C++, C#, Go, Python, and TypeScript now reach module and checkpoint parity through `04-expert`.
7-
- Java currently tracks `01-foundations` as a Java 21 MVP.
7+
- Java currently tracks `01-foundations` and `02-core` as a Java 21 MVP.
88
- Status labels:
99
- `Done`: module implemented with example, exercises, and README.
1010
- `Planned`: module not implemented yet, already queued in order.
@@ -28,18 +28,18 @@ Current parity progress in non-C++ tracks:
2828

2929
- C#: `6/6` modules complete
3030
- Go: `6/6` modules complete
31-
- Java: `0/6` modules complete
31+
- Java: `6/6` modules complete
3232
- Python: `6/6` modules complete
3333
- TypeScript: `6/6` modules complete
3434

3535
| Order | Module | C++ | C# | Go | Java | Python | TypeScript |
3636
| --- | --- | --- | --- | --- | --- | --- | --- |
37-
| 1 | input-validation | Done | Done | Done | Planned | Done | Done |
38-
| 2 | algorithms-basics | Done | Done | Done | Planned | Done | Done |
39-
| 3 | file-io-basics | Done | Done | Done | Planned | Done | Done |
40-
| 4 | sorting-and-searching | Done | Done | Done | Planned | Done | Done |
41-
| 5 | maps-and-frequency-counting | Done | Done | Done | Planned | Done | Done |
42-
| 6 | error-handling-and-defensive-programming | Done | Done | Done | Planned | Done | Done |
37+
| 1 | input-validation | Done | Done | Done | Done | Done | Done |
38+
| 2 | algorithms-basics | Done | Done | Done | Done | Done | Done |
39+
| 3 | file-io-basics | Done | Done | Done | Done | Done | Done |
40+
| 4 | sorting-and-searching | Done | Done | Done | Done | Done | Done |
41+
| 5 | maps-and-frequency-counting | Done | Done | Done | Done | Done | Done |
42+
| 6 | error-handling-and-defensive-programming | Done | Done | Done | Done | Done | Done |
4343

4444
## Advanced and Expert
4545

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ If you only want to learn one track, follow that track README first because lang
3636
- [TypeScript Guide](languages/typescript/README.md)
3737
2. Start at the first roadmap for that track:
3838
- C++: [00-setup](languages/cpp/00-setup/README.md), then `01-foundations`
39-
- C#, Go, Java, Python, TypeScript: `01-foundations`
39+
- Java: `01-foundations`, then `02-core`
40+
- C#, Go, Python, TypeScript: `01-foundations`
4041
3. Run one module example.
4142
4. Solve `exercises/01` and `exercises/02` in that module.
4243
5. Mark progress in the language checklist.
@@ -55,7 +56,7 @@ If you only want to learn one track, follow that track README first because lang
5556
| C++ | 00-setup, 01-foundations, 02-core, 03-advanced, 04-expert | Foundations, Core, Advanced, Expert, projects, assessments | Most complete and primary track |
5657
| C# | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
5758
| Go | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
58-
| Java | 01-foundations | 8/8 foundations modules | Java 21 MVP; core, advanced, expert, projects, and assessments planned |
59+
| Java | 01-foundations, 02-core | 8/8 foundations modules, 6/6 core modules | Java 21 MVP; advanced, expert, projects, and assessments planned |
5960
| Python | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
6061
| TypeScript | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
6162

languages/java/02-core/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Java 02 Core
2+
3+
This level moves from syntax practice into defensive programs, small algorithms, file handling, and collection-based analysis.
4+
5+
## Learning Metadata
6+
7+
- Difficulty: Intermediate.
8+
- Estimated Time: 4-6 hours.
9+
- Prerequisites: Completion of `01-foundations`.
10+
- Study Strategy: Run each example, trace the edge cases, then solve both exercises before comparing the same module in another language.
11+
12+
## Module Order
13+
14+
1. [input-validation](./input-validation/README.md)
15+
2. [algorithms-basics](./algorithms-basics/README.md)
16+
3. [file-io-basics](./file-io-basics/README.md)
17+
4. [sorting-and-searching](./sorting-and-searching/README.md)
18+
5. [maps-and-frequency-counting](./maps-and-frequency-counting/README.md)
19+
6. [error-handling-and-defensive-programming](./error-handling-and-defensive-programming/README.md)
20+
21+
Track progress in [../CHECKLIST.md](../CHECKLIST.md).
22+
23+
## Level Outcomes
24+
25+
- Validate console input without crashing.
26+
- Implement search, counting, sorting, and aggregation logic.
27+
- Read and write small text files with `Path` and `Files`.
28+
- Use maps for frequency analysis and defensive branches for invalid data.
29+
30+
## Done When
31+
32+
- [ ] I ran every `example/Main.java` file.
33+
- [ ] I completed both exercises in every core module.
34+
- [ ] I can explain at least one edge case for each exercise.
35+
- [ ] I can compare Java's standard-library APIs with the same concept in another track.
36+
37+
## Study Tip
38+
39+
Keep the programs package-free for now. The goal is to practice core logic before introducing Maven, Gradle, or multi-file project layout.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Algorithms Basics (Java)
2+
3+
This module practices small search and counting algorithms over arrays.
4+
5+
## Learning Metadata
6+
7+
- Difficulty: Intermediate.
8+
- Estimated Time: 30-45 minutes.
9+
- Prerequisites: `01-foundations/arrays-and-vectors`, `01-foundations/control-flow`.
10+
- Cross-Language Lens: Compare Java loops and helper methods with the same algorithmic patterns in C++, C#, Go, Python, and TypeScript.
11+
12+
## Quick Run
13+
14+
~~~bash
15+
javac -d build/java languages/java/02-core/algorithms-basics/example/Main.java
16+
java -cp build/java Main
17+
~~~
18+
19+
## Topics Covered
20+
21+
- Linear search.
22+
- Counting matching values.
23+
- Aggregating minimum, maximum, and even counts.
24+
- Returning sentinel values such as `-1`.
25+
26+
## Common Pitfalls
27+
28+
- Returning the last match when the task asks for the first.
29+
- Forgetting to handle empty input.
30+
- Mixing index positions with values.
31+
32+
## Cross-Language Notes
33+
34+
- Java arrays expose `.length`, not a `size()` method.
35+
- Helper methods make algorithm intent easier to test.
36+
- Sentinel values should be documented in output labels and exercise specs.
37+
38+
## Exercise Focus
39+
40+
- exercises/Exercise01.java: find the first index and occurrence count for a target value.
41+
- exercises/Exercise02.java: summarize minimum, maximum, and even values.
42+
43+
### Exercise Specs
44+
45+
1. exercises/Exercise01.java
46+
- Input: count, that many integers, then target integer.
47+
- Output: first index and occurrence count.
48+
- Edge cases: target missing; target at index 0.
49+
50+
2. exercises/Exercise02.java
51+
- Input: count followed by that many integers.
52+
- Output: minimum, maximum, and count of even numbers.
53+
- Edge cases: single value; negative values; all odd values.
54+
55+
## Checkpoint
56+
57+
- [ ] I can write a linear search.
58+
- [ ] I can count matches in one pass.
59+
- [ ] I completed exercises/Exercise01.java.
60+
- [ ] I completed exercises/Exercise02.java.
61+
- [ ] I tested a missing-target case.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Module focus: Walking data step by step to compute summaries and decisions.
2+
// Why it matters: practicing algorithms basics patterns makes exercises and checkpoints easier to reason about.
3+
4+
public class Main {
5+
static int firstIndexOf(int[] values, int target) {
6+
for (int i = 0; i < values.length; i++) {
7+
if (values[i] == target) {
8+
// Return immediately because the first match is the result this helper promises.
9+
return i;
10+
}
11+
}
12+
return -1;
13+
}
14+
15+
static int countOccurrences(int[] values, int target) {
16+
int count = 0;
17+
for (int value : values) {
18+
// Counting does not stop at the first match; every element still matters.
19+
if (value == target) {
20+
count++;
21+
}
22+
}
23+
return count;
24+
}
25+
26+
public static void main(String[] args) {
27+
int[] values = {4, 7, 4, 2, 4, 9};
28+
int target = 4;
29+
30+
// Report both position and frequency so learners can compare related scans.
31+
System.out.println("First index of 4: " + firstIndexOf(values, target));
32+
System.out.println("Occurrences of 4: " + countOccurrences(values, target));
33+
}
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
3+
public class Exercise01 {
4+
public static void main(String[] args) {
5+
Scanner scanner = new Scanner(System.in);
6+
int count = scanner.nextInt();
7+
int[] values = new int[count];
8+
for (int i = 0; i < count; i++) {
9+
values[i] = scanner.nextInt();
10+
}
11+
int target = scanner.nextInt();
12+
13+
int firstIndex = -1;
14+
int occurrences = 0;
15+
for (int i = 0; i < values.length; i++) {
16+
if (values[i] == target) {
17+
occurrences++;
18+
if (firstIndex == -1) {
19+
firstIndex = i;
20+
}
21+
}
22+
}
23+
24+
System.out.println("First index: " + firstIndex);
25+
System.out.println("Occurrences: " + occurrences);
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.Scanner;
2+
3+
public class Exercise02 {
4+
public static void main(String[] args) {
5+
Scanner scanner = new Scanner(System.in);
6+
int count = scanner.nextInt();
7+
if (count <= 0) {
8+
System.out.println("Count must be positive.");
9+
return;
10+
}
11+
12+
int minimum = Integer.MAX_VALUE;
13+
int maximum = Integer.MIN_VALUE;
14+
int evenCount = 0;
15+
for (int i = 0; i < count; i++) {
16+
int value = scanner.nextInt();
17+
minimum = Math.min(minimum, value);
18+
maximum = Math.max(maximum, value);
19+
if (value % 2 == 0) {
20+
evenCount++;
21+
}
22+
}
23+
24+
System.out.println("Minimum: " + minimum);
25+
System.out.println("Maximum: " + maximum);
26+
System.out.println("Even numbers: " + evenCount);
27+
}
28+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Error Handling and Defensive Programming (Java)
2+
3+
This module practices handling invalid operations and malformed records explicitly.
4+
5+
## Learning Metadata
6+
7+
- Difficulty: Intermediate.
8+
- Estimated Time: 35-50 minutes.
9+
- Prerequisites: `02-core/input-validation`, `02-core/file-io-basics`.
10+
- Cross-Language Lens: Compare Java exceptions and guard clauses with defensive patterns in C++, C#, Go, Python, and TypeScript.
11+
12+
## Quick Run
13+
14+
~~~bash
15+
javac -d build/java languages/java/02-core/error-handling-and-defensive-programming/example/Main.java
16+
java -cp build/java Main
17+
~~~
18+
19+
## Topics Covered
20+
21+
- Guarding invalid operations.
22+
- Catching parsing failures.
23+
- Continuing after malformed records.
24+
- Reporting accepted and skipped data.
25+
26+
## Common Pitfalls
27+
28+
- Catching exceptions too broadly and hiding the real problem.
29+
- Dividing before checking for zero.
30+
- Treating malformed rows as valid default values.
31+
32+
## Cross-Language Notes
33+
34+
- Java uses exceptions for many parse and I/O failures.
35+
- Guard clauses keep the happy path easier to read.
36+
- Defensive programs should explain what was skipped and why.
37+
38+
## Exercise Focus
39+
40+
- exercises/Exercise01.java: divide two integers defensively.
41+
- exercises/Exercise02.java: parse name-score rows until EOF and summarize accepted rows.
42+
43+
### Exercise Specs
44+
45+
1. exercises/Exercise01.java
46+
- Input: two integer tokens.
47+
- Output: integer division result or a clear error message.
48+
- Edge cases: non-integer input; division by zero.
49+
50+
2. exercises/Exercise02.java
51+
- Input: rows shaped as `name score` until EOF.
52+
- Output: accepted row count, skipped row count, and average score.
53+
- Edge cases: malformed rows; score outside 0..100.
54+
55+
## Checkpoint
56+
57+
- [ ] I can use guard clauses before risky operations.
58+
- [ ] I can catch parsing errors without masking valid data.
59+
- [ ] I completed exercises/Exercise01.java.
60+
- [ ] I completed exercises/Exercise02.java.
61+
- [ ] I tested at least one malformed input row.

0 commit comments

Comments
 (0)