Code with Java 21 is a practical journey through one of the world’s most prolific computer programming languages. It is meant to help readers build up their knowledge of common Java programming constructs, data structures, and engineering paradigms. Filled with real-world examples, this book aims to build the reader’s understanding of building software applications with Java.
Seasoned Java developers should buckle in as this book takes a hands-on approach to leveraging popular Java frameworks like Spring and Vaadin to build rich, feature-filled web applications. It also covers building powerful data-driven applications on enterprise-grade databases like PostgreSQL and Apache Cassandra®. This book will also show how to use Java to animate with colorful graphics and even build a simple arcade game.
Around the world, Java runs on billions of devices. After its inception nearly 30 years ago, it remains one of the most popular and sought-after programming languages. Whether you are an aspiring computer hobbyist or want to gain a valuable skill en route to a lucrative career as a software developer, Code with Java 21 should be every developer’s go-to reference for building Java applications.
Cover
Title Page
Copyright Page
Dedication Page
About the Author
About the Reviewer
Acknowledgement
Preface
Table of Contents
1. Getting to Know Java
Introduction
Structure
Objectives
Why code with Java?
Configuring your environment
Operating System
Java Runtime Environment
Java Development Kit
JDK vendors and editions
Installation
Windows
MacOS
Linux
Version management
Integrated Development Environment
Java dependency management
Source control
Git installation
Object-oriented programming
Encapsulation
Inheritance
Abstraction
Polymorphism
Static polymorphism
Dynamic polymorphism
Advantages of OOP
What is new in Java 21?
Virtual threads
Sequenced Collections
String templates
Conclusion
Points to remember
2. Fundamental Programming Structures
Introduction
Structure
Objectives
Getting started
Maven
HelloWorld
Anonymous main classes
Variables and formatting
Reading input
Error handling
If statements
Switch/case statements
Loops
For loops
While loops
Do loops
Files
Writing to a file
Reading from a file
Reading row properties from a file
Methods and constructors
Conclusion
Points to remember
3. Strings, Characters, and Regular Expressions
Introduction
Structure
Objectives
Characters
ASCII art
Strings
substring
toUpperCase
toLowerCase
String equality
Equality of string suffixes
Equality of string prefixes
contains
Regular expressions
Conclusion
Points to remember
4. Arrays, Collections, and Records
Introduction
Structure
Objectives
Arrays
Multi-dimensional arrays
Collections and maps
Sets
HashSet
LinkedHashSet
TreeSet
ArrayList
LinkedList
Maps
HashMap
LinkedHashMap
TreeMap
Sequenced collections
Records
Building a simple example
RPGSimulation class
Player class
Hero class
RPGSimulation class continued
Conclusion
Points to remember
5. Arithmetic Operations
Introduction
Structure
Objectives
Integer arithmetic
Addition
Testing add() with JUnit
Subtraction
Multiplication
Division
Modulo
Exponent
Floating point arithmetic
Addition
Nuances with floating point arithmetic
Subtraction
Multiplication
Division
Formatting floating point values
Exponent
Square root
Cube root
Absolute value
Conclusion
Points to remember
6. Common Data Structures
Introduction
Structure
Objectives
Stacks
Queues
Linked lists
Binary trees
Conclusion
Points to remember
7. Working with Databases
Introduction
Structure
Introduction to databases
Short history of databases
CAP theorem
Consistency
Availability
Partition tolerance
CAP designations
PostgreSQL
ElephantSQL
Schema
Loading data
Querying data
Accessing from Java
Apache Cassandra
Astra DB
Schema
Loading data
Querying data
Accessing from Java
Choosing the right database
Conclusion
Points to remember
8. Web Applications
Introduction
Structure
Objectives
Restful operations
Restful URIs
Simple operations
Web services with Spring Boot
MVC
Weather application controller
Hello world service endpoint
Weather Application model
Define a new keyspace
Define a new table
Generate a new token
Set application properties and environment variables
Code with Java 21 is a practical journey through one of the world’s most prolific computer programming languages. It is meant to help readers build up their knowledge of common Java programming constructs, data structures, and engineering paradigms. Filled with real-world examples, this book aims to build the reader’s understanding of building software applications with Java.
Seasoned Java developers should buckle in as this book takes a hands-on approach to leveraging popular Java frameworks like Spring and Vaadin to build rich, feature-filled web applications. It also covers building powerful data-driven applications on enterprise-grade databases like PostgreSQL and Apache Cassandra®. This book will also show how to use Java to animate with colorful graphics and even build a simple arcade game.
Around the world, Java runs on billions of devices. After its inception nearly 30 years ago, it remains one of the most popular and sought-after programming languages. Whether you are an aspiring computer hobbyist or want to gain a valuable skill en route to a lucrative career as a software developer, Code with Java 21 should be every developer’s go-to reference for building Java applications.
Table of contents
Cover
Title Page
Copyright Page
Dedication Page
About the Author
About the Reviewer
Acknowledgement
Preface
Table of Contents
1. Getting to Know Java
Introduction
Structure
Objectives
Why code with Java?
Configuring your environment
Operating System
Java Runtime Environment
Java Development Kit
JDK vendors and editions
Installation
Windows
MacOS
Linux
Version management
Integrated Development Environment
Java dependency management
Source control
Git installation
Object-oriented programming
Encapsulation
Inheritance
Abstraction
Polymorphism
Static polymorphism
Dynamic polymorphism
Advantages of OOP
What is new in Java 21?
Virtual threads
Sequenced Collections
String templates
Conclusion
Points to remember
2. Fundamental Programming Structures
Introduction
Structure
Objectives
Getting started
Maven
HelloWorld
Anonymous main classes
Variables and formatting
Reading input
Error handling
If statements
Switch/case statements
Loops
For loops
While loops
Do loops
Files
Writing to a file
Reading from a file
Reading row properties from a file
Methods and constructors
Conclusion
Points to remember
3. Strings, Characters, and Regular Expressions
Introduction
Structure
Objectives
Characters
ASCII art
Strings
substring
toUpperCase
toLowerCase
String equality
Equality of string suffixes
Equality of string prefixes
contains
Regular expressions
Conclusion
Points to remember
4. Arrays, Collections, and Records
Introduction
Structure
Objectives
Arrays
Multi-dimensional arrays
Collections and maps
Sets
HashSet
LinkedHashSet
TreeSet
ArrayList
LinkedList
Maps
HashMap
LinkedHashMap
TreeMap
Sequenced collections
Records
Building a simple example
RPGSimulation class
Player class
Hero class
RPGSimulation class continued
Conclusion
Points to remember
5. Arithmetic Operations
Introduction
Structure
Objectives
Integer arithmetic
Addition
Testing add() with JUnit
Subtraction
Multiplication
Division
Modulo
Exponent
Floating point arithmetic
Addition
Nuances with floating point arithmetic
Subtraction
Multiplication
Division
Formatting floating point values
Exponent
Square root
Cube root
Absolute value
Conclusion
Points to remember
6. Common Data Structures
Introduction
Structure
Objectives
Stacks
Queues
Linked lists
Binary trees
Conclusion
Points to remember
7. Working with Databases
Introduction
Structure
Introduction to databases
Short history of databases
CAP theorem
Consistency
Availability
Partition tolerance
CAP designations
PostgreSQL
ElephantSQL
Schema
Loading data
Querying data
Accessing from Java
Apache Cassandra
Astra DB
Schema
Loading data
Querying data
Accessing from Java
Choosing the right database
Conclusion
Points to remember
8. Web Applications
Introduction
Structure
Objectives
Restful operations
Restful URIs
Simple operations
Web services with Spring Boot
MVC
Weather application controller
Hello world service endpoint
Weather Application model
Define a new keyspace
Define a new table
Generate a new token
Set application properties and environment variables