Learn Java 17 Programming - Nick Samoylov - E-Book

Learn Java 17 Programming E-Book

Nick Samoylov

0,0
32,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 757

Veröffentlichungsjahr: 2022

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Learn Java 17 Programming Second Edition

Learn the fundamentals of Java Programming with this updated guide with the latest features

Nick Samoylov

BIRMINGHAM—MUMBAI

Learn Java 17 Programming

Second Edition

Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Publishing Product Manager: Gebin George

Senior Editor: Kinnari Chohan

Technical Editor: Pradeep Sahu

Copy Editor: Safis Editing

Project Coordinator: Manisha Singh

Proofreader: Safis Editing

Indexer: Manju Arasan

Production Designer: Vijay Kamble

Marketing Coordinator: Pooja Yadav

Business Development Executive: Kriti Sharma

First published: April 2019

Second edition: July 2022

Production reference: 1060722

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80324-143-2

www.packt.com

To my wife, Luda, a software developer too, who was the source of my inspiration and the sound technical advice for this book.

– Nick Samoylov

Contributors

About the author

Nick Samoylov graduated from Moscow Institute of Physics and Technology, working as a theoretical physicist and learning to program as a tool for testing his mathematical models. After the demise of the USSR, Nick created and successfully ran a software company, but was forced to close it under the pressure of governmental and criminal rackets. In 1999, with his wife Luda and two daughters, he emigrated to the USA and has been living in Colorado since then, working as a Java programmer. In his free time, Nick likes to write and hike in the Rocky Mountains.

About the reviewers

Alain Trottier loves to drive struggling people, processes, and products to their better versions. He finds immense joy in taking the efforts to help a person find their version 2.0. He believes that there’s a thrill in taking a jackhammer to an industrial process and building a more effective version in its place. He finds it invigorating to deconstruct a product or service to reveal key principles and then innovate something way better. He finds delight in smashing everything that makes a client feel awful and turning them into family. These all, he believes are ways to manhandle technology into doing what is right and best.

Fabrizio Marmitt has been a software development engineer for the past 15 years, building web applications as a full-stack software development engineer, from setting up servers to styling frontends. He currently works at Epic Games.

Table of Contents

Preface

Part 1: Overview of Java Programming

Chapter 1: Getting Started with Java 17

Technical requirements

How to install and run Java

What is the JDK and why do we need it?

Installing Java SE

Commands, tools, and utilities

How to install and run an IDE

Selecting an IDE

Installing and configuring IntelliJ IDEA

Creating a project

Importing a project

Executing examples from the command line

Java primitive types and operators

Boolean types

Numeric types

Default values of primitive types

Literals of primitive types

New compact number format

Operators

String types and literals

String literals

String immutability

IDs and variables

ID

Variable declaration (definition) and initialization

Java statements

Expression statements

Control flow statements

Summary

Quiz

Chapter 2: Java Object-Oriented Programming (OOP)

Technical requirements

OOP concepts

Object/class

Inheritance

Abstraction/interface

Encapsulation

Polymorphism

Class

Method

Constructor

The new operator

Class java.lang.Object

Instance and static properties and methods

Interface

Default methods

Private methods

Static fields and methods

Interface versus abstract class

Overloading, overriding, and hiding

Overloading

Overriding

Hiding

The final variable, method, and classes

The final variable

Final method

Final class

The record class

Sealed classes and interfaces

Polymorphism in action

The object factory

The instanceof operator

Summary

Quiz

Chapter 3: Java Fundamentals

Technical requirements

Packages, importing, and access

Packages

Importing

Access modifiers

Java reference types

Class and interface

Array

Enum

Default values and literals

A reference type as a method parameter

equals() method

Reserved and restricted keywords

Reserved keywords

Reserved identifiers

Reserved words for literal values

Restricted keywords

Usage of the this and super keywords

Usage of the this keyword

Usage of the super keyword

Converting between primitive types

Widening conversion

Narrowing conversion

Methods of conversion

Converting between primitive and reference types

Boxing

Unboxing

Summary

Quiz

Part 2: Building Blocks of Java

Chapter 4: Exception Handling

Technical requirements

The Java exceptions framework

Checked and unchecked exceptions

The try, catch, and finally blocks

The throws statement

The throw statement

The assert statement

Best practices of exception handling

Summary

Quiz

Chapter 5: Strings, Input/Output,and Files

Technical requirements

String processing

Methods of the String class

String utilities

I/O streams

Stream data

The InputStream class and its subclasses

The OutputStream class and its subclasses

The Reader and Writer classes and their subclasses

Other classes of the java.io package

The java.util.Scanner class

File management

Creating and deleting files and directories

Listing files and directories

Apache Commons’ FileUtils and IOUtils utilities

The FileUtils class

The IOUtils class

Summary

Quiz

Chapter 6: Data Structures, Generics, and Popular Utilities

Technical requirements

List, Set, and Map interfaces

Generics

How to initialize List and Set

java.lang.Iterable interface

Collection interface

List interface

Set interface

Map interface

Unmodifiable collections

Collections utilities

java.util.Collections class

CollectionUtils class

Arrays utilities

java.util.Arrays class

ArrayUtils class

Objects utilities

java.util.Objects class

ObjectUtils class

The java.time package

LocalDate class

LocalTime class

LocalDateTime class

Period and Duration classes

Period of day

Summary

Quiz

Chapter 7: Java Standard and External Libraries

Technical requirements

Java Class Library (JCL)

java.lang

java.util

java.time

java.io and java.nio

java.sql and javax.sql

java.net

java.lang.math and java.math

java.awt, javax.swing, and javafx

External libraries

org.junit

org.mockito

org.apache.log4j and org.slf4j

org.apache.commons

Summary

Quiz

Chapter 8: Multithreading and Concurrent Processing

Technical requirements

Thread versus process

User thread versus daemon

Extending the Thread class

Implementing the Runnable interface

Extending Thread versus implementing Runnable

Using a pool of threads

Getting results from a thread

Parallel versus concurrent processing

Concurrent modification of the same resource

Atomic variable

Synchronized method

Synchronized block

Concurrent collections 

Addressing memory consistency errors

Summary

Quiz

Chapter 9: JVM Structure and Garbage Collection

Technical requirements

Java application execution

Using an IDE

Using the command line with classes

Using the command line with JAR files

Using the command line with an executable JAR file

Java processes 

Classloading

Class linking

Class initialization

Class instantiation

Method execution

Garbage collection

Application termination

JVM’s structure

Runtime data areas

Classloaders

Execution engine

Garbage collection

Responsiveness, throughput, and stop-the-world

Object age and generation

When stop-the-world is unavoidable

Summary

Quiz

Chapter 10: Managing Data in a Database

Technical requirements

Creating a database

Creating a database structure

Connecting to a database

Releasing the connection

CRUD data

The INSERT statement

The SELECT statement

The UPDATE statement

The DELETE statement

Using statements

Using PreparedStatement

Using CallableStatement

Using a shared library JAR file to access a database

Summary

Quiz

Chapter 11: Network Programming

Technical requirements

Network protocols

UDP-based communication

TCP-based communication

The java.net.ServerSocket class

The java.net.Socket class

Running the examples

UDP versus TCP protocols

URL-based communication

The URL syntax

The java.net.URL class

Using the HTTP 2 Client API

Blocking HTTP requests

Non-blocking (asynchronous) HTTP requests

Server push functionality

WebSocket support

Summary

Quiz

Chapter 12: Java GUI Programming

Technical requirements

Java GUI technologies

JavaFX fundamentals

HelloWorld with JavaFX

Control elements

Charts

Applying CSS

Using FXML

Embedding HTML

Playing media

Adding effects

Summary

Quiz

Part 3: Advanced Java

Chapter 13: Functional Programming

Technical requirements

What is functional programming?

What is a functional interface?

What is a Lambda expression?

Standard functional interfaces

Consumer<T>

Predicate<T>

Supplier<T>

Function<T, R>

Other standard functional interfaces

Lambda expression limitations

Method references

Summary

Quiz

Chapter 14: Java Standard Streams

Technical requirements

Streams as a source of data and operations

Stream initialization

Stream interface

The Stream.Builder interface

Other classes and interfaces

Operations (methods)

Intermediate operations

Terminal operations

Numeric stream interfaces

Creating a stream

Intermediate operations

Terminal operations

Parallel streams

Stateless and stateful operations

Sequential or parallel processing?

Summary

Quiz

Chapter 15: Reactive Programming

Technical requirements

Asynchronous processing

Sequential and parallel streams

Using the CompletableFuture object

Non-blocking APIs

The java.io package versus the java.nio package

The event/run loop

Reactive

Responsive

Resilient

Elastic

Message-driven

Reactive streams

RxJava

Observable types

Disposable

Creating an observable

Operators

Multithreading (scheduler)

Summary

Quiz

Chapter 16: Java Microbenchmark Harness

Technical requirements

What is JMH?

Creating a JMH benchmark

Running the benchmark

Using an IDE plugin

JMH benchmark parameters

Mode

Output time unit

Iterations

Forking

JMH usage examples

Using the @State annotation

Using the Blackhole object

Using the @CompilerControl annotation

Using the @Param annotation

A word of caution

Summary

Quiz

Chapter 17: Best Practices for Writing High-Quality Code

Technical requirements

Java idioms, their implementation, and their usage

The equals() and hashCode() methods

The compareTo() method

The clone() method

The StringBuffer and StringBuilder classes

The try, catch, and finally clauses

Best design practices

Identifying loosely coupled functional areas

Breaking the functional area into traditional tiers

Coding to an interface

Using factories

Preferring composition over inheritance

Using libraries

Code is written for people

Use well-established frameworks and libraries

Testing is the shortest path to quality code

Summary

Quiz

Assessments

Chapter 1 – Getting Started with Java 17

Chapter 2 – Java Object-Oriented Programming (OOP)

Chapter 3 – Java Fundamentals

Chapter 4 – Exception Handling

Chapter 5 – Strings, Input/Output, and Files

Chapter 6 – Data Structures, Generics, and Popular Utilities

Chapter 7 – Java Standard and External Libraries

Chapter 8 – Multithreading and Concurrent Processing

Chapter 9 – JVM Structure and Garbage Collection

Chapter 10 – Managing Data in a Database

Chapter 11 – Network Programming

Chapter 12 – Java GUI Programming

Chapter 13 – Functional Programming

Chapter 14 – Java Standard Streams

Chapter 15 – Reactive Programming

Chapter 16 – Java Microbenchmark Harness

Chapter 17 – Best Practices for Writing High-Quality Code

Other Books You May Enjoy

Part 1: Overview of Java Programming

Get up and running with fundamental concepts of Java and OOP with practical examples and sample programs. This will build a base, which will help the readers get started with some core/advanced concepts of Java.

This part contains the following chapters:

Chapter 1, Getting Started with Java 17Chapter 2, Java Object-Oriented Programming (OOP)Chapter 3, Java Fundamentals