About the Book
Java is a versatile, popular programming language used across a wide range of industries. Learning how to write effective Java code can take your career to the next level, and The Java Workshop will help you do just that. This book is designed to take the pain out of Java coding and teach you everything you need to know to be productive in building real-world software.
The Workshop starts by showing you how to use classes, methods, and the built-in Collections API to manipulate data structures effortlessly. You’ll dive right in to learning about object-oriented programming by creating classes and interfaces and making use of inheritance and polymorphism. After learning how to handle exceptions, you’ll study the modules, packages, and libraries that help you organize your code. As you progress, you’ll discover how to connect to external databases and web servers, work with regular expressions, and write unit tests to validate your code. You’ll also be introduced to functional programming and see how to implement it using lambda functions.
By the end of this Workshop, you'll be well-versed with key Java concepts and have the knowledge and confidence to tackle your own ambitious projects with Java.
About the Chapters
Chapter 1, Getting Started, covers the basics of writing and testing programs, a first step towards building all the code that you will find in this book.
Chapter 2, Learning the Basics, covers the basic syntax of the Java language, especially ways to control the flow of your applications.
Chapter 3, Object-Oriented Programming, provides an overview of OOP and details the aspects that make Java a popular language.
Chapter 4, Collections, Lists, and Java's Built-In APIs, covers the popular Java collections framework, which is used to store, sort, and filter data.
Chapter 5, Exceptions, provides recommendations on how to deal with exceptions on a more conceptual level, providing a list of best practices that any professional programmer will follow.
Chapter 6, Libraries, Packages, and Modules, introduces you to various ways to package and bundle Java code, along with tools to help you build Java projects.
Chapter 7, Databases and JDBC, shows how to use JDBC to access relational databases from your Java applications.
Chapter 8, Sockets, Files, and Streams, aids you in working with external data storage systems.
Chapter 9, Working with HTTP, explains how to create programs that connect to a specific web server and downloads data.
Chapter 10, Encryption, explores how applying encryption to your software is vital to safeguard yours, or your customers, integrity, data, and business.
Chapter 11, Processes, briefly discusses how processes function and are dealt with in Java.
Chapter 12, Regular Expressions, decrypts what regular expressions mean and looks at how this comes in handy in Java.
Chapter 13, Functional Programming with Lambda Expressions, discusses how Java doubles up as a functional programming language, and how lambda expressions are used to perform pattern matching in Java.
Chapter 14, Recursion, looks at a couple of problems that are solved using the recursion technique.
Chapter 15, Processing Data with Streams, explains how you can use streams to write more expressive programs with fewer lines of code, and also how you can easily chain multiple operations on large lists.
Chapter 16, Predicates and Other Functional Interfaces, explores some of the valid use cases of functional interfaces.
Chapter 17, Reactive Programming with Java Flow, talks about the Java Flow API and the advantages of the Reactive Streams specification.
Chapter 18, Unit Testing, delves into testing with JUnit, one of the primary testing frameworks for Java.
Conventions
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "You can nest if
statements within any block of code, including the block of code that follows an if statement.".
Words that you see on the screen, for example, in menus or dialog boxes, also appear in the text like this: "Click
on Create
New
Project
."
A block of code is set as follows:
if (i == 5) { System.out.println("i is 5"); } i = 0;
New terms and important words are shown like this: "This kind of data is what we call a variable type."
Large code snippets are truncated and the corresponding names of the code files on GitHub are placed at the top of the truncated code. The permalinks to the entire code are placed below the code snippet. It should look as follows:
Exercise02.java
6Â Â if (distanceToHome > maxDistance) { 7Â Â System.out.println("Distance from the store to your home is"); 8Â Â System.out.println(" more than " + maxDistance + "km away."); 9Â Â System.out.println("That is too far for free delivery.");
https://packt.live/32Ca9YS
Before You Begin
Each great journey begins with a humble step. Our upcoming adventure with Java is no exception. Before we can do awesome things using Java, we must be prepared with a productive environment. In this small note, we shall see how to do that.
Installation of JRE
To install JRE on your systems, refer to: https://www.java.com/en/download/manual.jsp.
Installation of JDK
To install JDK on your systems, refer to: https://www.oracle.com/technetwork/java/javase/downloads/index.html.
Installation of IntelliJ IDEA
While all the code present in the course runs on all Java compilers, we have used IntelliJ IDEA on our systems. All the instructions in the exercises and the activities are tailored to work on IntelliJ. To install IntelliJ on your system, visit jetbrains.com/idea/.
If you have any issues or questions about installation please email us at workshops@packt.com
.
Installing the Code Bundle
Download the code files from GitHub at https://packt.live/2Jgzz6D and place them in a new folder called C:\Code
. Refer to these code files for the complete code bundle.