Book Image

Learn Java with Projects

By : Dr. Seán Kennedy, Maaike van Putten
5 (3)
Book Image

Learn Java with Projects

5 (3)
By: Dr. Seán Kennedy, Maaike van Putten

Overview of this book

Learn Java with Projects stands out in the world of Java guides; while some books skim the surface and others get lost in too much detail, this one finds a nice middle ground. You’ll begin by exploring the fundamentals of Java, from its primitive data types through to loops and arrays. Next, you’ll move on to object-oriented programming (OOP), where you’ll get to grips with key topics such as classes, objects, encapsulation, inheritance, polymorphism, interfaces, and more. The chapters are designed in a way that focuses on topics that really matter in real-life work situations. No extra fluff here, so that you get more time to spend on the basics and form a solid foundation. As you make progress, you’ll learn advanced topics including generics, collections, lambda expressions, streams and concurrency. This book doesn't just talk about theory—it shows you how things work with little projects, which eventually add up to one big project that brings it all together. By the end of this Java book, you’ll have sound practical knowledge of Java and a helpful guide to walk you through the important parts of Java.
Table of Contents (22 chapters)
1
Part 1: Java Fundamentals
9
Part 2: Object-Oriented Programming
15
Part 3: Advanced Topics

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.