Learn Java 17 Programming - Second Edition

Book description

Explore the essential concepts of programming such as object-oriented, functional, and reactive programming by writing code and building projects using the latest LTS version of Java

Key Features

  • A step-by-step guide for beginners to get started with programming in Java 17
  • Explore core programming topics including GUI programming, concurrency, and error handling
  • Write efficient code and build projects while learning the fundamentals of programming

Book Description

Java is one of the most preferred languages among developers. It is used in everything right from smartphones and game consoles to even supercomputers, and its new features simply add to the richness of the language.

This book on Java programming begins by helping you learn how to install the Java Development Kit. You'll then focus on understanding object-oriented programming (OOP), with exclusive insights into concepts such as abstraction, encapsulation, inheritance, and polymorphism, which will help you when programming for real-world apps. Next, you'll cover fundamental programming structures of Java such as data structures and algorithms that will serve as the building blocks for your apps with the help of sample programs and practice examples. You'll also delve into core programming topics that will assist you with error handling, debugging, and testing your apps. As you progress, you'll move on to advanced topics such as Java libraries, database management, and network programming and also build a sample project to help you understand the applications of these concepts.

By the end of this Java book, you'll not only have become well-versed with Java 17 but also gained a perspective into the future of this language and have the skills to code efficiently with best practices.

What you will learn

  • Understand and apply object-oriented principles in Java
  • Explore Java design patterns and best practices to solve everyday problems
  • Build user-friendly and attractive GUIs with ease
  • Understand the usage of microservices with the help of practical examples
  • Discover techniques and idioms for writing high-quality Java code
  • Get to grips with the usage of data structures in Java

Who this book is for

This book is for those who would like to start a new career in the modern Java programming profession, as well as those who do it professionally already and would like to refresh their knowledge of the latest Java and related technologies and ideas.

Table of contents

  1. Learn Java 17 Programming
  2. Second Edition
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  7. Part 1: Overview of Java Programming
  8. Chapter 1: Getting Started with Java 17
    1. Technical requirements
    2. How to install and run Java
      1. What is the JDK and why do we need it?
      2. Installing Java SE
      3. Commands, tools, and utilities
    3. How to install and run an IDE
      1. Selecting an IDE
      2. Installing and configuring IntelliJ IDEA
      3. Creating a project
      4. Importing a project
      5. Executing examples from the command line
    4. Java primitive types and operators
      1. Boolean types
      2. Numeric types
      3. Default values of primitive types
      4. Literals of primitive types
      5. New compact number format
      6. Operators
    5. String types and literals
      1. String literals
      2. String immutability
    6. IDs and variables
      1. ID
      2. Variable declaration (definition) and initialization
    7. Java statements
      1. Expression statements
      2. Control flow statements
    8. Summary
    9. Quiz
  9. Chapter 2: Java Object-Oriented Programming (OOP)
    1. Technical requirements
    2. OOP concepts
      1. Object/class
      2. Inheritance
      3. Abstraction/interface
      4. Encapsulation
      5. Polymorphism
    3. Class
      1. Method
      2. Constructor
      3. The new operator
      4. Class java.lang.Object
      5. Instance and static properties and methods
    4. Interface
      1. Default methods
      2. Private methods
      3. Static fields and methods
      4. Interface versus abstract class
    5. Overloading, overriding, and hiding
      1. Overloading
      2. Overriding
      3. Hiding
    6. The final variable, method, and classes
      1. The final variable
      2. Final method
      3. Final class
    7. The record class
    8. Sealed classes and interfaces
    9. Polymorphism in action
      1. The object factory
      2. The instanceof operator
    10. Summary
    11. Quiz
  10. Chapter 3: Java Fundamentals
    1. Technical requirements
    2. Packages, importing, and access
      1. Packages
      2. Importing
      3. Access modifiers
    3. Java reference types
      1. Class and interface
      2. Array
      3. Enum
      4. Default values and literals
      5. A reference type as a method parameter
      6. equals() method
    4. Reserved and restricted keywords
      1. Reserved keywords
      2. Reserved identifiers
      3. Reserved words for literal values
      4. Restricted keywords
    5. Usage of the this and super keywords
      1. Usage of the this keyword
      2. Usage of the super keyword
    6. Converting between primitive types
      1. Widening conversion
      2. Narrowing conversion
      3. Methods of conversion
    7. Converting between primitive and reference types
      1. Boxing
      2. Unboxing
    8. Summary
    9. Quiz
  11. Part 2: Building Blocks of Java
  12. Chapter 4: Exception Handling
    1. Technical requirements
    2. The Java exceptions framework
    3. Checked and unchecked exceptions
    4. The try, catch, and finally blocks
    5. The throws statement
    6. The throw statement
    7. The assert statement
    8. Best practices of exception handling
    9. Summary
    10. Quiz
  13. Chapter 5: Strings, Input/Output,and Files
    1. Technical requirements
    2. String processing
      1. Methods of the String class
      2. String utilities
    3. I/O streams
      1. Stream data
      2. The InputStream class and its subclasses
      3. The OutputStream class and its subclasses
      4. The Reader and Writer classes and their subclasses
      5. Other classes of the java.io package
      6. The java.util.Scanner class
    4. File management
      1. Creating and deleting files and directories
      2. Listing files and directories
    5. Apache Commons’ FileUtils and IOUtils utilities
      1. The FileUtils class
      2. The IOUtils class
    6. Summary
    7. Quiz
  14. Chapter 6: Data Structures, Generics, and Popular Utilities
    1. Technical requirements
    2. List, Set, and Map interfaces
      1. Generics
      2. How to initialize List and Set
      3. java.lang.Iterable interface
      4. Collection interface
      5. List interface
      6. Set interface
      7. Map interface
      8. Unmodifiable collections
    3. Collections utilities
      1. java.util.Collections class
      2. CollectionUtils class
    4. Arrays utilities
      1. java.util.Arrays class
      2. ArrayUtils class
    5. Objects utilities
      1. java.util.Objects class
      2. ObjectUtils class
    6. The java.time package
      1. LocalDate class
      2. LocalTime class
      3. LocalDateTime class
      4. Period and Duration classes
      5. Period of day
    7. Summary
    8. Quiz
  15. Chapter 7: Java Standard and External Libraries
    1. Technical requirements
    2. Java Class Library (JCL)
      1. java.lang
      2. java.util
      3. java.time
      4. java.io and java.nio
      5. java.sql and javax.sql
      6. java.net
      7. java.lang.math and java.math
      8. java.awt, javax.swing, and javafx
    3. External libraries
      1. org.junit
      2. org.mockito
      3. org.apache.log4j and org.slf4j
      4. org.apache.commons
    4. Summary
    5. Quiz
  16. Chapter 8: Multithreading and Concurrent Processing
    1. Technical requirements
    2. Thread versus process
    3. User thread versus daemon
    4. Extending the Thread class
    5. Implementing the Runnable interface
    6. Extending Thread versus implementing Runnable
    7. Using a pool of threads
    8. Getting results from a thread
    9. Parallel versus concurrent processing
    10. Concurrent modification of the same resource
      1. Atomic variable
      2. Synchronized method
      3. Synchronized block
      4. Concurrent collections 
      5. Addressing memory consistency errors
    11. Summary
    12. Quiz
  17. Chapter 9: JVM Structure and Garbage Collection
    1. Technical requirements
    2. Java application execution
      1. Using an IDE
      2. Using the command line with classes
      3. Using the command line with JAR files
      4. Using the command line with an executable JAR file
    3. Java processes 
      1. Classloading
      2. Class linking
      3. Class initialization
      4. Class instantiation
      5. Method execution
      6. Garbage collection
      7. Application termination
    4. JVM’s structure
      1. Runtime data areas
      2. Classloaders
      3. Execution engine
    5. Garbage collection
      1. Responsiveness, throughput, and stop-the-world
      2. Object age and generation
      3. When stop-the-world is unavoidable
    6. Summary
    7. Quiz
  18. Chapter 10: Managing Data in a Database
    1. Technical requirements
    2. Creating a database
    3. Creating a database structure
    4. Connecting to a database
    5. Releasing the connection
    6. CRUD data
      1. The INSERT statement
      2. The SELECT statement
      3. The UPDATE statement
      4. The DELETE statement
      5. Using statements
      6. Using PreparedStatement
      7. Using CallableStatement
      8. Using a shared library JAR file to access a database
    7. Summary
    8. Quiz
  19. Chapter 11: Network Programming
    1. Technical requirements
    2. Network protocols
    3. UDP-based communication
    4. TCP-based communication
      1. The java.net.ServerSocket class
      2. The java.net.Socket class
      3. Running the examples
    5. UDP versus TCP protocols
    6. URL-based communication
      1. The URL syntax
      2. The java.net.URL class
    7. Using the HTTP 2 Client API
      1. Blocking HTTP requests
      2. Non-blocking (asynchronous) HTTP requests
      3. Server push functionality
      4. WebSocket support
    8. Summary
    9. Quiz
  20. Chapter 12: Java GUI Programming
    1. Technical requirements
    2. Java GUI technologies
    3. JavaFX fundamentals
    4. HelloWorld with JavaFX
    5. Control elements
    6. Charts
    7. Applying CSS
    8. Using FXML
    9. Embedding HTML
    10. Playing media
    11. Adding effects
    12. Summary
    13. Quiz
  21. Part 3: Advanced Java
  22. Chapter 13: Functional Programming
    1. Technical requirements
    2. What is functional programming?
      1. What is a functional interface?
      2. What is a Lambda expression?
    3. Standard functional interfaces
      1. Consumer<T>
      2. Predicate<T>
      3. Supplier<T>
      4. Function<T, R>
      5. Other standard functional interfaces
    4. Lambda expression limitations
    5. Method references
    6. Summary
    7. Quiz
  23. Chapter 14: Java Standard Streams
    1. Technical requirements
    2. Streams as a source of data and operations
    3. Stream initialization
      1. Stream interface
      2. The Stream.Builder interface
      3. Other classes and interfaces
    4. Operations (methods)
      1. Intermediate operations
      2. Terminal operations
    5. Numeric stream interfaces
      1. Creating a stream
      2. Intermediate operations
      3. Terminal operations
    6. Parallel streams
      1. Stateless and stateful operations
      2. Sequential or parallel processing?
    7. Summary
    8. Quiz
  24. Chapter 15: Reactive Programming
    1. Technical requirements
    2. Asynchronous processing
      1. Sequential and parallel streams
      2. Using the CompletableFuture object
    3. Non-blocking APIs
      1. The java.io package versus the java.nio package
      2. The event/run loop
    4. Reactive
      1. Responsive
      2. Resilient
      3. Elastic
      4. Message-driven
    5. Reactive streams
    6. RxJava
      1. Observable types
      2. Disposable
      3. Creating an observable
      4. Operators
      5. Multithreading (scheduler)
    7. Summary
    8. Quiz
  25. Chapter 16: Java Microbenchmark Harness
    1. Technical requirements
    2. What is JMH?
    3. Creating a JMH benchmark
    4. Running the benchmark
      1. Using an IDE plugin
    5. JMH benchmark parameters
      1. Mode
      2. Output time unit
      3. Iterations
      4. Forking
    6. JMH usage examples
      1. Using the @State annotation
      2. Using the Blackhole object
      3. Using the @CompilerControl annotation
      4. Using the @Param annotation
    7. A word of caution
    8. Summary
    9. Quiz
  26. Chapter 17: Best Practices for Writing High-Quality Code
    1. Technical requirements
    2. Java idioms, their implementation, and their usage
      1. The equals() and hashCode() methods
      2. The compareTo() method
      3. The clone() method
      4. The StringBuffer and StringBuilder classes
      5. The try, catch, and finally clauses
    3. Best design practices
      1. Identifying loosely coupled functional areas
      2. Breaking the functional area into traditional tiers
      3. Coding to an interface
      4. Using factories
      5. Preferring composition over inheritance
      6. Using libraries
    4. Code is written for people
    5. Use well-established frameworks and libraries
    6. Testing is the shortest path to quality code
    7. Summary
    8. Quiz
  27. Assessments
    1. Chapter 1 – Getting Started with Java 17
    2. Chapter 2 – Java Object-Oriented Programming (OOP)
    3. Chapter 3 – Java Fundamentals
    4. Chapter 4 – Exception Handling
    5. Chapter 5 – Strings, Input/Output, and Files
    6. Chapter 6 – Data Structures, Generics, and Popular Utilities
    7. Chapter 7 – Java Standard and External Libraries
    8. Chapter 8 – Multithreading and Concurrent Processing
    9. Chapter 9 – JVM Structure and Garbage Collection
    10. Chapter 10 – Managing Data in a Database
    11. Chapter 11 – Network Programming
    12. Chapter 12 – Java GUI Programming
    13. Chapter 13 – Functional Programming
    14. Chapter 14 – Java Standard Streams
    15. Chapter 15 – Reactive Programming
    16. Chapter 16 – Java Microbenchmark Harness
    17. Chapter 17 – Best Practices for Writing High-Quality Code
    18. Why subscribe?
  28. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Learn Java 17 Programming - Second Edition
  • Author(s): Nick Samoylov
  • Release date: July 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803241432