Book Image

Learn Java 12 Programming

By : Nick Samoylov
Book Image

Learn Java 12 Programming

By: Nick Samoylov

Overview of this book

Java is one of the preferred languages among developers, 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 will then focus on understanding object-oriented programming (OOP), with exclusive insights into concepts like 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. You will 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, which will hone your skills in building professional-grade apps. Further on, you’ll understand how to create a graphic user interface using JavaFX and learn to build scalable apps by taking advantage of reactive and functional programming. By the end of this book, you’ll not only be well versed with Java 10, 11, and 12, but also gain a perspective into the future of this language and software development in general.
Table of Contents (25 chapters)
Free Chapter
Section 1: Overview of Java Programming
Section 2: Building Blocks of Java
Section 3: Advanced Java

What this book covers

Chapter 1, Getting Started with Java 12, begins with the basics, first explaining what "Java" is and defining its main terms, then going on to how to install the necessary tools to write and run (execute) a program. This chapter also describes the basic Java language constructs, illustrating them with examples that can be executed immediately.

Chapter 2, Object-Oriented Programming (OOP), presents the concepts of object-oriented programming and how they are implemented in Java. Each concept is demonstrated with specific code examples. The Java language constructs of class and interface are discussed in detail, as well as overloading, overriding, hiding, and use of the final keyword. The last section of the chapter is dedicated to presenting the power of polymorphism.

Chapter 3, Java Fundamentals, presents to the reader a more detailed view of Java as a language. It starts with the code organization in packages and a description of the accessibility levels of classes (interfaces) and their methods and properties (fields). The reference types as the main types of Java's object-oriented nature are presented in much detail, followed by a list of reserved and restricted keywords and a discussion of their usage. The chapter ends with the methods of conversion between primitive types, and from a primitive type to the corresponding reference type and back.

Chapter 4, Exception Handling, tells the reader about the syntax of the Java constructs related to exception handling and the best practices to address (handle) exceptions. The chapter ends with the related topic of the assertion statement that can be used to debug the application code in production.

Chapter 5, Strings, Input/Output, and Files, discusses the String class methods, as well as popular string utilities from standard libraries and the Apache Commons project. An overview of Java input/output streams and related classes of the package follow along with some classes of the package. The file-managing classes and their methods are described in a dedicated section.

Chapter 6, Data Structures, Generics, and Popular Utilities, presents the Java collections framework and its three main interfaces, List, Set, and Map, including discussion and demonstration of generics. The equals() and hashCode() methods are also discussed in the context of Java collections. Utility classes for managing arrays, objects, and time/date values have corresponding dedicated sections, too.

Chapter 7, Java Standard and External Libraries, provides an overview of the functionality of the most popular packages of Java Class Library (JCL): java.lang, java.util, java.time, and java.nio, java.sql and javax.sql,, java.lang.math, java.math, java.awt, javax.swing, and javafx. The most popular external libraries are represented by the org.junit, org.mockito, org.apache.log4j, org.slf4j, and org.apache.commons packages. This chapter helps the reader to avoid writing custom code in cases where such functionality already exists and can be just imported and used out of the box.

Chapter 8, Multithreading and Concurrent Processing, presents the ways to increase Java application performance by using workers (threads) that process data concurrently. It explains the concept of Java threads and demonstrates their usage. It also talks about the difference between parallel and concurrent processing, and how to avoid unpredictable results caused by the concurrent modification of a shared resource.

Chapter 9, JVM Structure and Garbage Collection, provides the readers with an overview of JVM's structure and behavior, which are more complex than we usually expect. One of the service threads, called garbage collection, performs an important mission of releasing the memory from unused objects. After reading this chapter, the readers will understand better what constitutes Java application execution, Java processes inside JVM, garbage collection, and how JVM works in general.

Chapter 10, Managing Data in a Database, explains and demonstrates how to manage—that is, insert, read, update, and delete–data in a database from a Java application. It also provides a short introduction to the SQL language and basic database operations: how to connect to a database, how to create a database structure, how to write a database expression using SQL, and how to execute them.

Chapter 11, Network Programming, describes and discusses the most popular network protocols, User Datagram Protocol (UDP), Transmission Control Protocol (TCP), HyperText Transfer Protocol (HTTP), and WebSocket, and their support for JCL. It demonstrates how to use these protocols and how to implement client-server communication in Java code. The APIs reviewed include URL-based communication and the latest Java HTTP Client API.

Chapter 12, Java GUI Programming, provides an overview of Java GUI technologies and demonstrates how the JavaFX kit can be used to create a GUI application. The latest versions of JavaFX not only provide many helpful features, but also allow preserving and embedding legacy implementations and styles.

Chapter 13, Functional Programming, explains what a functional interface is, provides an overview of functional interfaces that come with JDK, and defines and demonstrates lambda expressions and how to use them with functional interfaces, including using method reference.

Chapter 14, Java Standard Streams, talks about the processing of data streams, which are different from the I/O streams reviewed in Chapter 5, Strings, Input/Output, and Files. It defines what data streams are, how to process their elements using methods (operations) of the object, and how to chain (connect) stream operations in a pipeline. It also discusses the stream's initialization and how to process the stream in parallel.

Chapter 15, Reactive Programming, introduces the Reactive Manifesto and the world of reactive programming. It starts with defining and discussing the main related concepts – "asynchronous", "non-blocking", "responsive", and so on. Using them, it then defines and discusses reactive programming, the main reactive frameworks, and talks about RxJava in more details.

Chapter 16, Microservices, explains how to build microservices – the foundational component for creating a reactive system. It discusses what a microservice is, how big or small they can be, and how existing microservices frameworks support message-driven architecture. The discussion is illustrated with a detailed code demonstration of a small reactive system built using the Vert.x toolkit.

Chapter 17, Java Microbenchmark Harness, presents the Java Microbenchmark Harness (JMH) project that allows us to measure various code performance characteristics. It defines what JMH is, how to create and run a benchmark, what the benchmark parameters are, and outlines supported IDE plugins. The chapter ends with some practical demo examples and recommendations.

Chapter 18, Best Practices for Writing High-Quality Code, introduces Java idioms and the most popular and useful practices for designing and writing application code.

Chapter 19, Java Gets New Features, talks about current the most significant projects that will add new features to Java and enhance it in other aspects. After reading this chapter, the reader will understand how to follow Java development and will be able to envision the roadmap of future Java releases. If so desired, the reader can become the JDK source contributor too.