I recently bought Java Coding Problems by Anghel Leonard because the topics covered in this book interested me as a Java trainer. I decided to buy it after I saw the TOC here. Since Java has started to evolve quite fast is hard to keep myself up to date and is quite easy to miss new Java features or to not have time to explore them in detail.
I bought the paperback which is quite heavy. The book has 800+ pages. But, obviously, what matters the most is the content. As a quick hint: you can count on the 360+ applications containing 1,000+ examples.
The book is structured in 13 chapters that covers 260+ problems ranging Java 8 to Java 13. Mainly, the author uses the crafted problems as a pretext to cover all Java 8-12 features. From popular features such as Java streams or Optional to less popular features such as Java 11 nest-based access control (nests).
Chapter 1: Strings, Numbers, and Math
This chapter includes 39 problems that involve strings, numbers, and mathematical operations. The chapter starts with a bunch of classical problems for strings such as counting duplicates, reversing a string, and removing white spaces. The chapter continues with problems dedicated to numbers and mathematical operations such as summing two large numbers, operation overflow, comparing two unsigned numbers, computing the floor of a division and a modulus, and much more. Each problem is passed through several solutions, including Java 8 functional
style. Moreover, the chapter covers problems that futures added in JDK 9, 10, 11, and 12.
Chapter 2: Objects, Immutability, and Switch Expressions
This includes 18 problems that involve objects, immutability, and switch
expressions. The chapter starts with several problems about dealing with null references. It continues with problems regarding checking indexes, equals() and hashCode(), and immutability (for example, writing immutable classes and passing/returning mutable objects from immutable classes). The last part of the chapter deals with cloning objects and JDK 12 switch expressions.
Chapter 3: Working with Date and Time
This chapter includes 20 problems that involve date and time. These problems are meant to cover a wide range of topics (converting, formatting, adding, subtracting, defining periods/durations, computing, and so on) via Date, Calendar, LocalDate, LocalTime, LocalDateTime, ZoneDateTime, OffsetDateTime, OffsetTime, Instant, and so on. By the end of this chapter, you will have no problems shaping date and time to conform to your application's needs.
Chapter 4: Type Inference
This chapter includes 21 problems that involve JEP 286, Java Local Variable Type Inference (LVTI), or the var type. These problems have been carefully crafted to reveal the best practices and common mistakes involved in using var. By the end of this chapter, you will have everything you need to know about var to push it in production.
Chapter 5: Arrays, Collections, and Data Structures
This chapter includes 30 problems that involve arrays, collections, and several data structures. The aim is to provide solutions to a category of problems encountered in a wide range of applications, such as sorting, finding, comparing, ordering, reversing, filling, merging, copying, replacing, and so on. The provided solutions are implemented in Java 8-12 and they can be used as the base for solving other related problems as well. By the end of this chapter, you will have a solid base of knowledge that's useful for solving a lot of problems that involve arrays, collections, and data structures.
Chapter 6: Java I/O Paths, Files, Buffers, Scanning, and Formatting
This chapter includes 20 problems that involve Java I/O for files. From
manipulating, walking, and watching paths to streaming files and efficient ways for reading/writing text and binary files, we will cover problems that are a must in the arsenal of any Java developer. With the skills gained from this chapter, you will be able to tackle most of the common problems that involve Java I/O files.
Chapter 7: Java Reflection Classes, Interfaces, Constructors, Methods, and Fields
This chapter includes 17 problems that involve the Java Reflection API. From classical topics, such as inspecting and instantiating Java artifacts (for
example, modules, packages, classes, interfaces, super-classes, constructors, methods, annotations, arrays, and so on), to synthetic and bridge constructs or nest-based access control (JDK 11), this chapter provides solid coverage of the Java Reflection API.
Chapter 8: Functional Style Programming – Fundamentals and Design Patterns
This chapter includes 11 problems that involve Java functional programming. The chapter starts with a problem designed to acquaint you completely with functional interfaces. It continues with a suite of design patterns from GoF interpreted in Java functional style.
Chapter 9: Functional Style Programming – Deep Dive
This chapter includes 22 problems that involve Java functional programming. Here, we focus on several problems that involve classical operations encountered in streams (for example, filters, and maps), and we discuss infinite streams, null-safe streams, and default methods. A comprehensive list of problems covers grouping, partitioning, and collectors, including the JDK 12 teeing() collector and the matter of writing a custom collector. In addition, takeWhile(), dropWhile(), composing functions, predicates and comparators, testing and debugging lambdas,
and other cool topics are discussed as well.
Chapter 10: Concurrency – Thread Pools, Callables, and Synchronizers
This chapter includes 14 problems that involve Java concurrency. This chapter starts with several fundamental problems about the thread life cycle and object-/class-level locking. It continues with a bunch of problems about thread pools in Java, including JDK 8 work-stealing thread pools.
Afterward, we have problems dedicated to Callable and Future. Next, we dedicate several problems to Java synchronizers (for example, barrier, semaphore, and exchanger). By the end of this chapter, you should be familiar with the main coordinates of Java concurrency and be ready to continue with a set of advanced problems.
Chapter 11: Concurrency – Deep Dive
This chapter includes 13 problems that involve Java concurrency. This chaper covers problems about fork/join frameworks, CompletableFuture, ReentrantLock, ReentrantReadWriteLock, StampedLock, atomic variables, task cancelation, interruptible methods, thread-local locks, and deadlocks. Completing this chapter will guarantee the achievement of the considerable amount of concurrency knowledge needed by any Java developer.
Chapter 12: Optional
This chapter includes 24 problems meant to draw several rules for working with Optional. The problems and solutions presented in this section are based on the Brian Goetz' (Java's language architect) definition—Optional is intended to provide a limited mechanism for library method return types where there needed to be a clear way to represent no result, and using null for such was overwhelmingly likely to cause errors. But where there are rules, there are exceptions as well. Therefore, do not conclude that the rules (or practices) presented here should be followed (or avoided) at all costs. Like always, the solution depends on the problem.
Chapter 13: HTTP Client and WebSocket APIs
This chapter includes 20 problems meant to cover the HTTP Client and Webocket APIs. Remember HttpUrlConnection? Well, JDK 11 comes with the HTTP Client API as a reinvention of HttpUrlConnection. The HTTP Client API is easy to use and supports HTTP/2 (default) and HTTP/1.1. For
backward compatibility, the HTTP Client API will automatically downgrade from HTTP/2 to HTTP 1.1 when the server doesn't support HTTP/2. Moreover, the HTTP Client API supports synchronous and asynchronous programming models and relies on streams to transfer data (reactive streams). It also supports the WebSocket protocol used in real-time web applications to provide client-server communication with low message overhead.
What I liked?
What I didn't liked?
I score this book with 4.8 from 5 starts.
I strongly recommended it as a reference book for Java 8 - 13 topics.
Create your free account to unlock your custom reading experience.