What this book covers
Chapter 1, Getting Started with Java, starts by discussing the main Java features, such as OOP. How to install Java on various operating systems and how to write your first Java program with and without an IDE are also explored.
Chapter 2, Variables and Primitive Data Types, explains what a variable is and the fact that Java uses “strong-typing” (you must declare a variables type). This chapter also covers Java’s primitive data types, their sizes in bytes (needed to understand for later when discussing casting), and their ranges.
Chapter 3, Operators and Casting, explores how Java’s operators cooperate using precedence and associativity. We discuss Java’s various operators and explain both widening and narrowing when casting in Java.
Chapter 4, Conditional Statements, focuses on both scope and conditional statements. We initially examine Java’s use of block scope. We then explain the various forms of the if
statement; and conclude the chapter with both switch
statements and switch
expressions.
Chapter 5, Understanding Iteration, discusses loops, including while
, do-while
, for,
and enhanced for. This chapter also explores the break
and continue
statements.
Chapter 6, Working with Arrays, describes why one needs arrays. We show how to declare and initialize arrays of various primitive types, including using the shorthand syntax. We discuss how to loop through an array, processing each element. Multi-dimensional arrays are also covered; as is the Arrays
class.
Chapter 7, Methods, discusses the importance of methods and the difference between the method definition and method execution. Method overloading is discussed and the varargs format is explained. Lastly, the important concept of call-by-value is explained.
Chapter 8, Classes, Objects, and Enums, is a significant OOP chapter and details the following: the difference between classes and objects; the this
reference; access modifiers; basic and advanced encapsulation; the object life cycle; the instanceof
keyword; enums and records.
Chapter 9, Inheritance and Polymorphism, explains inheritance and polymorphism. We detail what overriding means and discuss the super
, protected
, abstract,
and final
keywords. We also explore sealed
classes and upcasting/downcasting.
Chapter 10, Interfaces and Abstract Classes, covers both abstract
classes and interfaces. We explain static
, default
, and private
interface methods and also sealed
interfaces.
Chapter 11, Dealing with Exceptions, explains exceptions and their purpose. We explain the difference between checked and unchecked exceptions. We delve into throwing exceptions and how to create your own custom exceptions. The important catch or declare principle is discussed; as are the try-catch, try-catch-finally, and try-with-resources blocks.
Chapter 12, Java Core API, introduces important classes/interfaces from the API, such as Scanner
. We compare and contrast String
and StringBuilder
and discuss how to create a custom immutable type. We example the List
interface and its popular implementation ArrayList
. Lastly, we explore the Date API.
Chapter 13, Generics and Collections, discusses the collections framework and its interfaces List
, Set
, Map
, and Queue
. We examine several implementations of each and basic operations. We explain sorting using both the Comparable
and Comparator
interfaces. We finish by examining generics and basic hashing concepts.
Chapter 14, Lambda Expressions, explains what lambda expressions are and their relationship to functional interfaces. Several functional interfaces from the API are examined. Lastly, method references and the role of context in understanding them are outlined.
Chapter 15, Streams: Fundamentals, is our first chapter on streams. In this chapter, we discuss what a stream pipeline is and what stream laziness means. We show different ways to create both finite and infinite streams. We examine the terminal operations that start off the streaming process - including reductions such as collect()
which is very useful for extracting information out of a stream.
Chapter 16, Streams: Advanced Concepts, starts by examining intermediate operations such as filter()
, map()
, and sorted()
. We explore the primitive streams followed by how to map from one stream to another, regardless of type. The Optional
type is explained and we conclude with a discussion of parallel streams.
Chapter 17, Concurrency, starts by explaining what concurrency is. We examine working with threads and present issues with concurrent access. Mechanisms to resolve these issues are discussed; namely: atomic classes, synchronized
blocks, and the Lock
interface. Concurrent collections and the ExecutorService
are explored next. We finish with a discussion on threading problems such as data races, deadlock, and livelock.