-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepomix-output.xml
More file actions
2128 lines (1686 loc) · 79.1 KB
/
Copy pathrepomix-output.xml
File metadata and controls
2128 lines (1686 loc) · 79.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
This file is a merged representation of the entire codebase, combined into a single document by Repomix.
<file_summary>
This section contains a summary of this file.
<purpose>
This file contains a packed representation of the entire repository's contents.
It is designed to be easily consumable by AI systems for analysis, code review,
or other automated processes.
</purpose>
<file_format>
The content is organized as follows:
1. This summary section
2. Repository information
3. Directory structure
4. Repository files (if enabled)
5. Multiple file entries, each consisting of:
- File path as an attribute
- Full contents of the file
</file_format>
<usage_guidelines>
- This file should be treated as read-only. Any changes should be made to the
original repository files, not this packed version.
- When processing this file, use the file path to distinguish
between different files in the repository.
- Be aware that this file may contain sensitive information. Handle it with
the same level of security as you would the original repository.
</usage_guidelines>
<notes>
- Some files may have been excluded based on .gitignore rules and Repomix's configuration
- Binary files are not included in this packed representation. Please refer to the Repository Structure section for a complete list of file paths, including binary files
- Files matching patterns in .gitignore are excluded
- Files matching default ignore patterns are excluded
- Files are sorted by Git change count (files with more changes are at the bottom)
</notes>
</file_summary>
<directory_structure>
gradle/
wrapper/
gradle-wrapper.jar
gradle-wrapper.properties
modules/
00-setup-java-gradle/
01-objectives/
README.md
02-concepts/
01-jvm-and-gradle.md
README.md
03-exercises/
README.md
04-verification/
checklist.md
README.md
01-java-refresh-oop/
01-objectives/
README.md
02-concepts/
01-records-and-invariants.java
README.md
03-exercises/
README.md
04-verification/
checklist.md
src/
main/
java/
com/
learning/
java/
orders/
domain/
Customer.java
Money.java
Order.java
OrderItem.java
OrderStatus.java
Product.java
README.md
02-collections-generics-optionals/
01-objectives/
README.md
02-concepts/
01-lookup-and-optionals.java
README.md
03-exercises/
src/
main/
java/
com/
learning/
java/
exercises/
OrderLookup.java
README.md
04-verification/
checklist.md
solutions/
src/
main/
java/
com/
learning/
java/
solutions/
OrderLookup.java
README.md
03-functional-java-streams/
01-objectives/
README.md
02-concepts/
01-stream-pipeline.java
README.md
03-exercises/
src/
main/
java/
com/
learning/
java/
exercises/
OrderStreams.java
README.md
04-verification/
checklist.md
solutions/
src/
main/
java/
com/
learning/
java/
solutions/
OrderStreams.java
README.md
04-exceptions-validation-testing/
01-objectives/
README.md
02-concepts/
01-validation-boundary.java
README.md
03-exercises/
src/
main/
java/
com/
learning/
java/
exercises/
OrderValidator.java
README.md
04-verification/
checklist.md
solutions/
src/
main/
java/
com/
learning/
java/
solutions/
OrderValidator.java
README.md
05-concurrency-and-jvm-basics/
01-objectives/
README.md
02-concepts/
01-executor-ownership.java
README.md
03-exercises/
src/
main/
java/
com/
learning/
java/
exercises/
NotificationProcessor.java
README.md
04-verification/
checklist.md
solutions/
src/
main/
java/
com/
learning/
java/
solutions/
NotificationProcessor.java
README.md
06-spring-boot-rest-api/
01-objectives/
README.md
02-concepts/
01-controller-flow.java
README.md
03-exercises/
README.md
04-verification/
checklist.md
src/
main/
java/
com/
learning/
java/
orders/
api/
OrderController.java
OrdersApiApplication.java
README.md
07-persistence-hibernate-jpa/
01-objectives/
README.md
02-concepts/
01-entity-and-repository.java
README.md
03-exercises/
README.md
04-verification/
checklist.md
src/
main/
java/
com/
learning/
java/
orders/
persistence/
OrderEntity.java
OrderJpaRepository.java
README.md
08-enterprise-api-quality/
01-objectives/
README.md
02-concepts/
01-validation-and-errors.java
README.md
03-exercises/
README.md
04-verification/
checklist.md
src/
main/
java/
com/
learning/
java/
orders/
quality/
ApiExceptionHandler.java
CreateOrderRequest.java
README.md
09-security-observability-production/
01-objectives/
README.md
02-concepts/
01-authentication-vs-authorization.java
README.md
03-exercises/
README.md
04-verification/
checklist.md
src/
main/
java/
com/
learning/
java/
orders/
security/
SecurityConfiguration.java
README.md
10-android-java-orientation/
01-objectives/
README.md
02-concepts/
01-order-screen-state.java
README.md
03-exercises/
README.md
04-verification/
checklist.md
README.md
11-big-data-java-orientation/
01-objectives/
README.md
02-concepts/
01-local-to-distributed.java
README.md
03-exercises/
src/
main/
java/
com/
learning/
java/
exercises/
OrderEventAnalytics.java
README.md
04-verification/
checklist.md
solutions/
src/
main/
java/
com/
learning/
java/
solutions/
OrderEventAnalytics.java
README.md
12-capstone-enterprise-orders/
01-objectives/
README.md
02-concepts/
01-hexagonal-seam.java
README.md
03-exercises/
README.md
04-verification/
checklist.md
src/
main/
java/
com/
learning/
java/
orders/
api/
CapstoneApplication.java
OrderApiController.java
OrderBeans.java
domain/
Customer.java
Money.java
Order.java
OrderItem.java
OrderStatus.java
Product.java
service/
InMemoryOrderRepository.java
OrderRepository.java
OrderService.java
test/
java/
com/
learning/
java/
orders/
OrderServiceTest.java
README.md
.gitignore
BACKGROUND.md
build.gradle.kts
CLAUDE.md
gradlew
gradlew.bat
plan-implementation-java-learning-module.md
README.md
settings.gradle.kts
</directory_structure>
<files>
This section contains the contents of the repository's files.
<file path="gradle/wrapper/gradle-wrapper.properties">
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
</file>
<file path="modules/00-setup-java-gradle/01-objectives/README.md">
# Objectives
Verify JDK 17, understand JVM/JDK/JRE, and run the Gradle wrapper.
</file>
<file path="modules/00-setup-java-gradle/02-concepts/01-jvm-and-gradle.md">
# JVM and Gradle in one build
`javac` compiles `.java` source into platform-independent `.class` bytecode. The JVM loads that bytecode and executes it. A JDK includes the JVM plus developer tools such as `javac`; a JRE is the runtime portion.
Gradle reads `build.gradle.kts`, resolves declared libraries, compiles source, and runs tests. The wrapper pins the Gradle version in `gradle/wrapper/gradle-wrapper.properties`, which makes the build reproducible across developer machines and CI.
```text
Order.java --javac--> Order.class --JVM--> running process
^
Gradle orchestrates this step and test execution
```
The Java toolchain in the root build asks Gradle for Java 17 even if a developer’s shell defaults to another version.
</file>
<file path="modules/00-setup-java-gradle/02-concepts/README.md">
# Concepts
The JVM executes bytecode; the JDK adds compiler and tools; the wrapper pins build behavior for the project.
</file>
<file path="modules/00-setup-java-gradle/03-exercises/README.md">
# Exercise
Run `java -version`, `./gradlew test`, and import the project into an IDE.
</file>
<file path="modules/00-setup-java-gradle/04-verification/checklist.md">
- [ ] Java reports version 17
- [ ] `./gradlew test` completes
</file>
<file path="modules/00-setup-java-gradle/README.md">
# Module 00: Java and Gradle Setup
## Why this module exists
Before writing application code, verify that the JDK, compiler, and build tool agree on Java 17. Gradle is not just a command runner: it describes how source code becomes a tested, repeatable artifact.
## Prerequisites
None. This is the starting point.
## What you will learn
- The distinction between the JDK, JRE, JVM, source code, and bytecode.
- Why a project uses a Gradle Wrapper instead of relying on a globally installed Gradle version.
- The standard `src/main/java` and `src/test/java` layout.
## Learn by doing
1. Run `java -version` and confirm Java 17.
2. Run `./gradlew test` from the project root.
3. Open [build.gradle.kts](../../build.gradle.kts) and find the Java toolchain declaration.
4. Import the root folder into IntelliJ IDEA as a Gradle project.
## Success looks like
Gradle reports successful tests and your IDE recognises Java source roots. Continue to [Module 01](../01-java-refresh-oop/README.md).
</file>
<file path="modules/01-java-refresh-oop/01-objectives/README.md">
# Objectives
Model an order domain with records, classes, enums, interfaces, packages, and validation.
</file>
<file path="modules/01-java-refresh-oop/02-concepts/01-records-and-invariants.java">
package examples;
import java.math.BigDecimal;
// A record gives us final fields, accessors, equals/hashCode, and toString.
record Price(BigDecimal amount, String currency) {
Price {
// Constructor validation prevents invalid values from ever becoming a Price.
if (amount == null || amount.signum() < 0) {
throw new IllegalArgumentException("amount must not be negative");
}
}
}
enum ShippingStatus { NEW, SHIPPED, CANCELLED }
final class RecordsAndInvariants {
static void main(String[] args) {
// BigDecimal is preferred to double for values such as money.
Price price = new Price(new BigDecimal("19.99"), "USD");
System.out.println(price.amount());
}
}
</file>
<file path="modules/01-java-refresh-oop/02-concepts/README.md">
# Concepts
Records are compact immutable data carriers. Interfaces define behavior; enums model finite state; package visibility controls boundaries.
</file>
<file path="modules/01-java-refresh-oop/03-exercises/README.md">
# Exercise
Extend the supplied `Product`, `Customer`, `Money`, and `OrderStatus` types with an `Order` aggregate.
</file>
<file path="modules/01-java-refresh-oop/04-verification/checklist.md">
- [ ] Invalid product and money values are rejected
- [ ] Domain types have focused responsibilities
</file>
<file path="modules/01-java-refresh-oop/src/main/java/com/learning/java/orders/domain/Customer.java">
package com.learning.java.orders.domain;
public record Customer(String id, String email) {
public Customer { if (id == null || id.isBlank() || email == null || !email.contains("@")) throw new IllegalArgumentException("Invalid customer"); }
}
</file>
<file path="modules/01-java-refresh-oop/src/main/java/com/learning/java/orders/domain/Money.java">
package com.learning.java.orders.domain;
import java.math.BigDecimal;
import java.util.Objects;
/** Value object: a money amount is meaningful only together with its currency. */
public record Money(BigDecimal amount, String currency) {
public Money {
Objects.requireNonNull(amount, "amount");
Objects.requireNonNull(currency, "currency");
// Reject invalid values at creation time so every Money instance is safe to use later.
if (amount.signum() < 0 || currency.isBlank()) throw new IllegalArgumentException("Invalid money");
}
}
</file>
<file path="modules/01-java-refresh-oop/src/main/java/com/learning/java/orders/domain/Order.java">
package com.learning.java.orders.domain;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
/** Aggregate root that owns its order lines and lifecycle state. */
public record Order(String id, Customer customer, List<OrderItem> items, OrderStatus status) {
public Order {
if (id == null || id.isBlank()) id = UUID.randomUUID().toString();
if (customer == null || items == null || items.isEmpty()) throw new IllegalArgumentException("Order requires customer and items");
// A defensive copy prevents callers from modifying an order through their original list.
items = List.copyOf(items);
if (status == null) status = OrderStatus.NEW;
}
/** Decimal arithmetic avoids floating-point rounding errors in currency totals. */
public BigDecimal total() { return items.stream().map(OrderItem::total).reduce(BigDecimal.ZERO, BigDecimal::add); }
}
</file>
<file path="modules/01-java-refresh-oop/src/main/java/com/learning/java/orders/domain/OrderItem.java">
package com.learning.java.orders.domain;
import java.math.BigDecimal;
public record OrderItem(Product product, int quantity) {
public OrderItem { if (product == null || quantity < 1) throw new IllegalArgumentException("Quantity must be positive"); }
public BigDecimal total() { return product.price().amount().multiply(BigDecimal.valueOf(quantity)); }
}
</file>
<file path="modules/01-java-refresh-oop/src/main/java/com/learning/java/orders/domain/OrderStatus.java">
package com.learning.java.orders.domain;
public enum OrderStatus { NEW, PAID, SHIPPED, CANCELLED }
</file>
<file path="modules/01-java-refresh-oop/src/main/java/com/learning/java/orders/domain/Product.java">
package com.learning.java.orders.domain;
public record Product(String id, String name, Money price) {
public Product { if (id == null || id.isBlank() || name == null || name.isBlank()) throw new IllegalArgumentException("Product fields are required"); }
}
</file>
<file path="modules/01-java-refresh-oop/README.md">
# Module 01: Java Refresh and Object-Oriented Modelling
## Why this module exists
Backend code is easier to change when its types mirror the business vocabulary. The order domain in `src/main/java` models products, customers, order lines, money, and order state using Java 17 records and an enum.
## Prerequisites
- Module 00: Java 17 and Gradle setup.
## What you will learn
- When a `record` is a better fit than a mutable class.
- How constructor validation protects an aggregate from invalid state.
- Why an enum is safer than arbitrary strings for an order lifecycle.
- How package boundaries communicate ownership.
## Learn by doing
Read `Money`, `Product`, and `Order` in that order. Create an order with two `OrderItem` values, call `total()`, then try an invalid quantity and observe the exception.
## Key idea
An `Order` owns its list of lines. The constructor takes an immutable copy so callers cannot modify an already-created order through a shared list reference.
## Next
Continue to [Module 02](../02-collections-generics-optionals/README.md) to store and retrieve those domain objects safely.
</file>
<file path="modules/02-collections-generics-optionals/01-objectives/README.md">
# Objectives
Choose collection types, constrain generic APIs, and represent missing values safely with `Optional`.
</file>
<file path="modules/02-collections-generics-optionals/02-concepts/01-lookup-and-optionals.java">
package examples;
import java.util.Map;
import java.util.Optional;
final class LookupAndOptionals {
static Optional<String> findCustomerEmail(Map<String, String> emails, String customerId) {
// get() can return null; Optional makes that absence visible in the return type.
return Optional.ofNullable(emails.get(customerId));
}
static void main(String[] args) {
Map<String, String> emails = Map.of("c-1", "learner@example.com");
// orElse is a deliberate fallback, not a null check hidden in the caller.
System.out.println(findCustomerEmail(emails, "missing").orElse("not found"));
}
}
</file>
<file path="modules/02-collections-generics-optionals/02-concepts/README.md">
# Concepts
Prefer `List` for order lines, `Map` for keyed lookup, immutable copies at boundaries, and `Optional` for absent results.
</file>
<file path="modules/02-collections-generics-optionals/03-exercises/src/main/java/com/learning/java/exercises/OrderLookup.java">
package com.learning.java.exercises;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/** Starter exercise: implement lookup without returning null or mutable internals. */
public final class OrderLookup<T> {
private final Map<String, T> orders;
public OrderLookup(Map<String, T> orders) {
// Copy at the boundary: later changes to the caller's map must not affect this lookup.
this.orders = Map.copyOf(orders);
}
public Optional<T> findById(String id) { return Optional.empty(); }
public List<T> all() { return List.of(); }
}
</file>
<file path="modules/02-collections-generics-optionals/03-exercises/README.md">
# Exercise
Complete `src/main/java/com/learning/java/exercises/OrderLookup.java`. It must return an `Optional` for a missing ID and immutable results. Compare your work with `solutions/src/main/java` only after attempting it.
</file>
<file path="modules/02-collections-generics-optionals/04-verification/checklist.md">
- [ ] No null is returned for a missing order
- [ ] Callers cannot mutate stored collections
</file>
<file path="modules/02-collections-generics-optionals/solutions/src/main/java/com/learning/java/solutions/OrderLookup.java">
package com.learning.java.solutions;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public final class OrderLookup<T> {
private final Map<String, T> orders;
public OrderLookup(Map<String, T> orders) { this.orders = Map.copyOf(orders); }
public Optional<T> findById(String id) { return Optional.ofNullable(orders.get(id)); }
public List<T> all() { return List.copyOf(orders.values()); }
}
</file>
<file path="modules/02-collections-generics-optionals/README.md">
# Module 02: Collections, Generics, and Optional
## Why this module exists
Most backend services spend more time moving groups of objects than creating individual objects. This module shows how `Map`, `List`, generics, immutable copies, and `Optional` make that movement explicit and safe.
## Prerequisites
- Module 01: records and the order domain.
## What you will learn
- Use `Map<String, T>` for fast lookup by an identifier.
- Use `List<T>` when ordering matters.
- Use a generic type parameter to reuse a repository-shaped utility without losing type safety.
- Return `Optional<T>` for a genuinely absent value instead of returning `null`.
## Learn by doing
Complete `03-exercises/src/main/java/com/learning/java/exercises/OrderLookup.java`. Start with `findById`, then return an immutable list from `all`. Compare only afterwards with `solutions/`.
## Common pitfall
`Map.copyOf` freezes the map structure, but it does not make mutable objects inside it immutable. Treat domain values as immutable too.
## Next
Continue to [Module 03](../03-functional-java-streams/README.md).
</file>
<file path="modules/03-functional-java-streams/01-objectives/README.md">
# Objectives
Use lambdas, method references, stream pipelines, and collectors for order analytics.
</file>
<file path="modules/03-functional-java-streams/02-concepts/01-stream-pipeline.java">
package examples;
import java.math.BigDecimal;
import java.util.List;
final class StreamPipeline {
record Sale(BigDecimal total, boolean paid) { }
static BigDecimal paidRevenue(List<Sale> sales) {
return sales.stream()
// Intermediate operation: keep only business-relevant events.
.filter(Sale::paid)
// Transform each Sale into the number we want to aggregate.
.map(Sale::total)
// The identity defines the answer for an empty list.
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
}
</file>
<file path="modules/03-functional-java-streams/02-concepts/README.md">
# Concepts
Separate stream transformation (`map`, `filter`) from terminal aggregation (`toList`, `groupingBy`, `reduce`).
</file>
<file path="modules/03-functional-java-streams/03-exercises/src/main/java/com/learning/java/exercises/OrderStreams.java">
package com.learning.java.exercises;
import java.math.BigDecimal;
import java.util.List;
import java.util.function.Predicate;
public final class OrderStreams {
public record Sale(String customerId, BigDecimal total, boolean paid) { }
// Return a new list; do not modify the caller's collection inside a stream pipeline.
public List<Sale> filterPaid(List<Sale> sales) { return List.of(); }
public BigDecimal revenue(List<Sale> sales, Predicate<Sale> condition) { return BigDecimal.ZERO; }
}
</file>
<file path="modules/03-functional-java-streams/03-exercises/README.md">
# Exercise
Complete `src/main/java/com/learning/java/exercises/OrderStreams.java`: filter paid sales and calculate revenue with a predicate. A reference implementation is in `solutions/src/main/java`.
</file>
<file path="modules/03-functional-java-streams/04-verification/checklist.md">
- [ ] Pipelines are side-effect free
- [ ] Empty input has a defined result
</file>
<file path="modules/03-functional-java-streams/solutions/src/main/java/com/learning/java/solutions/OrderStreams.java">
package com.learning.java.solutions;
import java.math.BigDecimal;
import java.util.List;
import java.util.function.Predicate;
public final class OrderStreams {
public record Sale(String customerId, BigDecimal total, boolean paid) { }
public List<Sale> filterPaid(List<Sale> sales) { return sales.stream().filter(Sale::paid).toList(); }
public BigDecimal revenue(List<Sale> sales, Predicate<Sale> condition) { return sales.stream().filter(condition).map(Sale::total).reduce(BigDecimal.ZERO, BigDecimal::add); }
}
</file>
<file path="modules/03-functional-java-streams/README.md">
# Module 03: Functional Java and Streams
## Why this module exists
Streams make transformations over order data compact and composable when each step has one clear purpose. They are not automatically better than loops; they are best for a readable pipeline of filtering, mapping, grouping, or reducing.
## Prerequisites
- Module 02: collections and generics.
## What you will learn
- Lambdas and method references.
- Intermediate operations such as `filter` and `map`.
- Terminal operations such as `toList` and `reduce`.
- Why monetary totals start from `BigDecimal.ZERO`.
## Learn by doing
Implement `filterPaid` and `revenue` in `OrderStreams`. Add a sale that is not paid to ensure the predicate affects the total.
## Common pitfall
Do not mutate shared variables inside a stream pipeline. Return transformed data instead.
## Next
Continue to [Module 04](../04-exceptions-validation-testing/README.md).
</file>
<file path="modules/04-exceptions-validation-testing/01-objectives/README.md">
# Objectives
Design useful exceptions, validate boundaries, and write focused JUnit 5 tests.
</file>
<file path="modules/04-exceptions-validation-testing/02-concepts/01-validation-boundary.java">
package examples;
import java.math.BigDecimal;
final class ValidationBoundary {
static void validateTotal(BigDecimal total) {
// This is a caller error, so an unchecked argument exception is appropriate.
if (total == null || total.signum() <= 0) {
throw new IllegalArgumentException("total must be positive");
}
}
static void main(String[] args) {
validateTotal(new BigDecimal("12.50"));
// validateTotal(BigDecimal.ZERO); // Try this to see the contract fail fast.
}
}
</file>
<file path="modules/04-exceptions-validation-testing/02-concepts/README.md">
# Concepts
Use checked exceptions for recoverable contracts and unchecked exceptions for invalid state. Test behavior, not implementation details.
</file>
<file path="modules/04-exceptions-validation-testing/03-exercises/src/main/java/com/learning/java/exercises/OrderValidator.java">
package com.learning.java.exercises;
import java.math.BigDecimal;
public final class OrderValidator {
// Validation makes invalid input fail where it enters the application, not later in a workflow.
public void validate(String customerId, BigDecimal total) { /* Throw IllegalArgumentException for invalid input. */ }
}
</file>
<file path="modules/04-exceptions-validation-testing/03-exercises/README.md">
# Exercise
Complete `src/main/java/com/learning/java/exercises/OrderValidator.java`, then add JUnit tests for blank customers and zero/negative totals. Check the reference solution after testing your version.
</file>
<file path="modules/04-exceptions-validation-testing/04-verification/checklist.md">
- [ ] Happy path and failure path are covered
- [ ] Assertions describe business behavior
</file>
<file path="modules/04-exceptions-validation-testing/solutions/src/main/java/com/learning/java/solutions/OrderValidator.java">
package com.learning.java.solutions;
import java.math.BigDecimal;
public final class OrderValidator {
public void validate(String customerId, BigDecimal total) {
if (customerId == null || customerId.isBlank()) throw new IllegalArgumentException("customerId is required");
if (total == null || total.signum() <= 0) throw new IllegalArgumentException("total must be positive");
}
}
</file>
<file path="modules/04-exceptions-validation-testing/README.md">
# Module 04: Exceptions, Validation, and Testing
## Why this module exists
An API or service should reject invalid requests at its boundary, with a message that lets callers fix the input. Tests make those rules executable and protect them when the implementation changes.
## Prerequisites
- Modules 01–03.
## What you will learn
- The difference between expected validation failures and infrastructure failures.
- When `IllegalArgumentException` communicates an invalid caller input.
- The arrange-act-assert shape of a focused JUnit test.
## Learn by doing
Complete `OrderValidator`, then write tests for a blank customer, a zero total, and a valid order. The valid case should not throw.
## Key idea
Validation belongs close to the boundary where bad data first enters the system, rather than allowing it to create a broken domain object later.
## Next
Continue to [Module 05](../05-concurrency-and-jvm-basics/README.md).
</file>
<file path="modules/05-concurrency-and-jvm-basics/01-objectives/README.md">
# Objectives
Understand threads, executors, futures, visibility, and basic JVM memory vocabulary.
</file>
<file path="modules/05-concurrency-and-jvm-basics/02-concepts/01-executor-ownership.java">
package examples;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
final class ExecutorOwnership {
static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(2);
try {
// The executor owns worker threads; submitting work is cheaper than creating threads per task.
executor.submit(() -> System.out.println("send notification"));
} finally {
// Always release resources owned by this scope, even when a task fails.
executor.shutdown();
}
}
}
</file>
<file path="modules/05-concurrency-and-jvm-basics/02-concepts/README.md">
# Concepts
Prefer executors over manually managed threads; make shared state immutable or synchronize access explicitly.
</file>
<file path="modules/05-concurrency-and-jvm-basics/03-exercises/src/main/java/com/learning/java/exercises/NotificationProcessor.java">
package com.learning.java.exercises;
import java.util.List;
import java.util.concurrent.ExecutorService;
public final class NotificationProcessor {
/** The caller owns the executor lifecycle; this method only submits and collects work. */
public List<String> sendAll(List<String> orderIds, ExecutorService executor) {
return List.of(); // Submit each independent notification and preserve input order.
}
}
</file>
<file path="modules/05-concurrency-and-jvm-basics/03-exercises/README.md">
# Exercise
Complete `src/main/java/com/learning/java/exercises/NotificationProcessor.java` using the supplied executor. Preserve the input order without mutable shared state. A solution is included under `solutions/`.
</file>
<file path="modules/05-concurrency-and-jvm-basics/04-verification/checklist.md">
- [ ] Executor is shut down
- [ ] Shared state has a clear ownership policy
</file>
<file path="modules/05-concurrency-and-jvm-basics/solutions/src/main/java/com/learning/java/solutions/NotificationProcessor.java">
package com.learning.java.solutions;
import java.util.List;
import java.util.concurrent.ExecutorService;
public final class NotificationProcessor {
public List<String> sendAll(List<String> orderIds, ExecutorService executor) {
try {
return executor.invokeAll(orderIds.stream().<java.util.concurrent.Callable<String>>map(id -> () -> "sent:" + id).toList())
.stream().map(future -> {
try { return future.get(); } catch (Exception exception) { throw new IllegalStateException(exception); }
}).toList();
} catch (InterruptedException exception) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Notification processing interrupted", exception);
}
}
}
</file>
<file path="modules/05-concurrency-and-jvm-basics/README.md">
# Module 05: Concurrency and JVM Basics
## Why this module exists
Order notifications are independent units of work, but running work concurrently introduces ordering, failure, and shared-state concerns. This module starts with a deterministic executor-based example before discussing larger async designs.
## Prerequisites
- Modules 01–04.
## What you will learn
- Why an `ExecutorService` is preferable to creating raw threads.
- How `invokeAll` waits for a batch and preserves task order.
- What interruption means and why an interrupt flag must be restored.
- The difference between stack, heap, and garbage collection at a practical level.
## Learn by doing
Implement `NotificationProcessor.sendAll` using the passed executor. Use a fixed-size pool in a test and always shut it down in a `finally` block.
## Next
Continue to [Module 06](../06-spring-boot-rest-api/README.md).
</file>
<file path="modules/06-spring-boot-rest-api/01-objectives/README.md">
# Objectives
Design a Spring Boot HTTP API for orders with DTOs and explicit response codes.
</file>