Book Image

The Java Workshop

By : David Cuartielles, Andreas Göransson, Eric Foster-Johnson
Book Image

The Java Workshop

By: David Cuartielles, Andreas Göransson, Eric Foster-Johnson

Overview of this 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 into 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.
Table of Contents (20 chapters)

Pure Functions

The purest of functions can be considered black boxes, meaning that what happens inside the function is not really of any interest to the programmer. They are only interested in what is put into the box, and what comes out of it as a result—that's because there will always be a result of a pure function.

The pure function takes arguments and produces a result based on these arguments. The pure function will never change the state of the outside world or rely on it. Everything that is required by the function should be available inside it, or as an input to it.

Exercise 1: Writing Pure Functions

A grocery store has a system for managing their stock; however, the company that built their software has gone bankrupt and has lost all the source code for their system. This is a system that only allows customers to buy one thing at a time. Because their customers want to buy two things at a time, never more or less, they have asked you to implement a function...