Learn Java with Projects: A concise practical guide to learning everything a Java professional really needs to know

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Refine your Java skills by seamlessly blending foundational core concepts with hands-on coding applications

Key Features

  • Gain a deep understanding of essential topics that will help you progress with Java
  • Learn by working on mini-projects to help reinforce the concepts you’ve learned
  • Gain comprehensive knowledge of the core concepts of Java
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

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 and objects, inheritance, interfaces, lambda expressions, 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 how to create your own generic types and streams. 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.

What you will learn

  • Get a clear understanding of Java fundamentals such as primitive types, operators, scope, conditional statements, loops, exceptions, and arrays
  • Master OOP constructs such as classes, objects, enums, interfaces, and records
  • Develop a deep understanding of OOP principles such as polymorphism, inheritance, and encapsulation
  • Delve into the advanced topics of generics, collections, lambdas, streams, and concurrency
  • Visualize what is happening in memory when you call a method or create an object
  • Appreciate how effective learning-by-doing is

Who this book is for

This book is for anyone looking to learn the core concepts of Java. If you’re learning programming (and Java) for the first time or want to upskill to Java (with experience in a different language), then this book is for you. Prior knowledge of programming is helpful but not necessary.

Table of Contents

  1. Getting Started with Java
  2. Variables and Primitive Data Types
  3. Operators and Casting
  4. Conditional Statements
  5. Understanding Iteration
  6. Working with Arrays
  7. Methods
  8. Classes, Objects, and Enums
  9. Inheritance and Polymorphism
  10. Interfaces and Abstract Classes
  11. Dealing with Exceptions
  12. Java Core API
  13. Generics and Collections
  14. Lambda Expressions
  15. Streams - Fundamentals
  16. Streams: Advanced Concepts
  17. Concurrency

Author(s): Dr. Seán Kennedy, Maaike van Putten
Edition: 1
Publisher: Packt Publishing
Year: 2023

Language: English
Commentary: Publisher EPUB | Published: November 2023
Pages: 602
City: Birmingham
Tags: Java; Java Programming Language; Object Oriented Programming; Java Core API; Generics; Collections; Lambda Expressions; Streams; Concurrency

Cover
Title Page
Copyright and Credits
Contributors
Table of Contents
Preface
Part 1: Java Fundamentals
Chapter 1: Getting Started with Java
Technical requirements
Exploring Java features
OOP in Java
Working with OOP
Compiled language
Write once, run anywhere
Automatic memory management
Installing Java
Checking whether Java is installed on your system
Installing Java on Windows
Installing Java on macOS
Installing Java on Linux
Running Java online
Writing our first program
Hello world
Steps to create the program
Understanding the program
Compiling and running Java programs
Understanding the compilation process
Compiling the code with javac on the command line
Running the compiled code with Java on the command line
Working with an IDE
What is an IDE?
Choosing an IDE
Creating and running a program with an IDE
Creating a program in an IDE
Running your program
Debugging a program
Exercises
Project
Summary
Chapter 2: Variables and Primitive Data Types
Technical requirements
Understanding and declaring variables
What is a variable?
Declaring a variable
Naming a variable
Accessing a variable
Accessing a variable that you have not declared
Understanding Java’s primitive data types
Java’s primitive data types
Screen output
Exercises
Project – dinosaur profile generator
Summary
Chapter 3: Operators and Casting
Technical requirements
Learning how Java’s operators cooperate
Order of precedence
Associativity
Understanding Java’s operators
Unary operators
Arithmetic operators
Relational operators
Logical operators
Bitwise operators
Ternary operator
Compound assignment operators
Explaining Java casting
Widening
Narrowing
Exercises
Project – Dino meal planner
Summary
Chapter 4: Conditional Statements
Technical requirements
Understanding scope
What is a block?
Exploring if statements
The if statement itself
else if statements
else statements
Mastering switch statements and expressions
switch statements
switch expressions
Exercises
Project – Task allocation system
Summary
Chapter 5: Understanding Iteration
Technical requirements
while loops
do-while loops
while versus do-while
for loops
Traditional for loop
Enhanced for loop
Nested loops
break and continue statements
break statements
continue statements
Exercises
Project – Dino meal planner
Summary
Chapter 6: Working with Arrays
Technical requirements
Arrays – what, when, and why?
Arrays explained
When to use arrays
Declaring and initializing arrays
Declaring arrays
Initializing arrays
Short syntax for array initialization
Accessing elements in an array
Understanding indexing
Accessing array elements
Modifying array elements
Working with length and bounds
Determining the length of an array
Dealing with the bounds of an array
Iterating over arrays
Using the for loop
Using the for each loop
Choosing between the regular loop and the enhanced for loop
Handling multidimensional arrays
Declaring and initializing multidimensional arrays
Accessing and modifying elements of multidimensional arrays
Iterating over multidimensional arrays
Using Java’s built-in methods for arrays
Built-in Arrays class for working with arrays
Exercises
Project – Dino tracker
Summary
Chapter 7: Methods
Technical requirements
Explaining why methods are important
Flow of control
Abstraction
Code duplication
Understanding the difference between method definition and method execution
Method definition
Method execution
Exploring method overloading
Method signature
Overloading a method
Explaining varargs
Mastering call by value
Primitives versus references in memory
Exercises
Project – Mesozoic Eden assistant
Summary
Part 2: Object-Oriented Programming
Chapter 8: Classes, Objects, and Enums
Technical requirements
Understanding the differences between classes and objects
Classes
Objects
Getting familiar with the new keyword
Contrasting instance with class members
Instance members (methods/data)
Class members (methods/data)
Exploring the “this” reference
Associating an instance with the “this” reference
Shadowing or hiding an instance variable
Applying access modifiers
private
Package-private
protected
public
packages
Encapsulation
Achieving encapsulation
Mastering advanced encapsulation
Call By value revisited
The issue
The solution
Delving into the object life cycle
Garbage collection
Object life cycle example
Explaining the instanceof keyword
Understanding enums
Simple enums
Complex enums
Appreciating records
Record patterns
Exercises
Project – Mesozoic Eden park manager
Summary
Chapter 9: Inheritance and Polymorphism
Technical requirements
Understanding inheritance
Advantages of inheritance
Disadvantages of inheritance
Base class
Subclass
The “is-a” relationship
Applying inheritance
extends
implements
Exploring polymorphism
Separating the reference type from the object type
Applying polymorphism
JVM – object type versus reference type usage
Contrasting method overriding and method overloading
Method overloading
Method overriding
Exploring the super keyword
super()
super.
An example of using super
Revisiting the protected access modifier
The UML diagram
The package with the protected member
The other package
Pattern matching for switch
Explaining the abstract and final keywords
The abstract keyword
The final keyword
Applying sealed classes
sealed and permits
non-sealed
Example using sealed, permits, and non-sealed
Understanding instance and static blocks
Instance blocks
static blocks
Mastering upcasting and downcasting
Upcasting
Downcasting
Exercises
Project
Summary
Chapter 10: Interfaces and Abstract Classes
Technical requirements
Understanding abstract classes
Mastering interfaces
Abstract methods in interfaces
Interface constants
Multiple interface inheritance
Examining default and static interface methods
‘default’ interface methods
‘static’ interface methods
Multiple interface inheritance
Explaining ‘private’ interface methods
Exploring sealed interfaces
Exercises
Project – unified park management system
Summary
Chapter 11: Dealing with Exceptions
Technical requirements
Understanding exceptions
What are exceptions?
Need for exception handling
Common situations that require exception handling
Understanding the exception hierarchy
Checked exceptions
Unchecked exceptions
Working with basic I/O operations
Reading from a file using FileReader
Writing to a file using FileWriter
Throwing exceptions
The throw keyword
Creating and throwing custom exceptions
The catch or declare principle
Understanding the principle
Declaring exceptions using throws
Handling exceptions with try-catch
Handling exceptions with try-with-resources
Working with inheritance and exceptions
Declaring exceptions in method signatures
Overriding methods and exception handling
Exercises
Project – dinosaur care system
Summary
Chapter 12: Java Core API
Technical requirements
Understanding the Scanner class
Using Scanner to read from the keyboard
Using Scanner to read from a file
Using Scanner to read from a string
Comparing String with StringBuilder
String class
StringBuilder class
String versus StringBuilder example
Designing a custom immutable type
The checklist
Examining List and ArrayList
List properties
Exploring the Date API
Dates and times
Duration and Period
Additional interesting types
Formatting dates and times
Exercises
Project – dinosaur care system
Summary
Part 3: Advanced Topics
Chapter 13: Generics and Collections
Technical requirements
Getting to know collections
Overview of different collection types
List
ArrayList
LinkedList
Exploring the basic operations for lists
Set
HashSet
TreeSet
LinkedHashSet
Performing basic operations on a set
Map
HashMap
TreeMap
LinkedHashMap
Basic operations on maps
Queue
Queue implementations
Basic operations on the Queue interface
Sorting collections
Natural ordering
The Comparable and Comparator interfaces
Working with generics
Life before generics – objects
Use case of generics
Syntax generics
Bounded generics
Hashing and overriding hashCode()
Understanding basic hashing concepts
hashCode() and its role in collections
Overriding hashCode() and best practices
Using hashCode() in custom generic types
Exercises
Project – advanced dinosaur care system
Summary
Chapter 14: Lambda Expressions
Technical requirements
Understanding lambda expressions
Functional Interfaces
Lambda expressions
final or effectively final
Exploring functional interfaces from the API
Predicate and BiPredicate
Supplier
Consumer and BiConsumer
Function and BiFunction
UnaryOperator and BinaryOperator
Mastering method references
Bound method references
Unbound method references
Static method references
Constructor method references
Method references and context
Exercises
Project – agile dinosaur care system
Summary
Chapter 15: Streams – Fundamentals
Technical requirements
Understanding stream pipelines
Stream pipeline
Exploring stream laziness
Creating streams
Streaming from an array
Streaming from a collection
Stream.of()
Streaming from a file
Infinite streams
Mastering terminal operations
count()
min() and max()
findAny() and findFirst()
anyMatch(), allMatch, and noneMatch()
forEach()
reduce()
collect()
collect(Collector)
Exercises
Project – dynamic dinosaur care system
Summary
Chapter 16: Streams: Advanced Concepts
Technical requirements
Examining intermediate operations
filter(Predicate)
distinct()
limit(long)
map(Function)
flatMap(Function)
sorted() and sorted(Comparator)
Delving into primitive streams
Creating primitive streams
Common primitive stream methods
New primitive stream interfaces
Mapping streams
Mapping from Object streams
Mapping from primitive streams
Explaining Optionals
Creating Optionals
Using the Optional API
Primitive Optionals
Understanding parallel streams
Creating parallel streams
Parallel decomposition
Parallel reductions using reduce()
Parallel reductions using collect()
Exercises
Project – dynamic dinosaur care system
Summary
Chapter 17: Concurrency
Technical requirements
Understanding concurrency
Multiprocessing
Multitasking
Multithreading
Importance of concurrency in modern applications
Challenges in concurrent programming
Working with threads
The Thread class
The Runnable interface
Lambda expressions with Runnable
Thread management – sleep() and join()
The Thread.sleep() method
Handling InterruptedException
Using the join() method
Atomic classes
AtomicInteger, AtomicLong, and AtomicReference
The synchronized keyword
Using synchronized methods
Using synchronized blocks
Synchronized methods versus synchronized blocks
The Lock interface
ReentrantLock
Best practices for working with locks
Concurrent collections
Concurrent collection interfaces
Understanding SkipList collections
Understanding CopyOnWrite collections
Synchronized collections
ExecutorService and thread pools
Executing tasks using SingleThreadExecutor
The Callable interface and Future
Submitting tasks and handling results
Future objects and their methods
Invoking multiple tasks and handling the results
Thread pools and task execution
ScheduledExecutorServices
Data races
Threading problems
Data races
Race conditions
Deadlocks
Livelocks
Starvation
Exercises
Project – Park Operations System – the calm before the storm
Summary
Index
Other Books You May Enjoy