Pro Java 8 Programming, 3rd Edition

Pro Java 8 Programming, 3rd Edition

English | 2015 | ISBN: 978-1-4842-0641-6 | 695 Pages | PDF +code | 10 MB

Pro Java 8 Programming covers the core Java development kit and the finer points of the core standard edition (SE) and development kit version 8. You’ll discover the particulars of working with the Java language and APIs to develop applications in many different contexts.
You will also delve into more advanced topics like lambda expressions, closures, new i/o (NIO.2), enums, generics, XML, metadata and the Swing APIs for GUI design and development. By the end of the book, you’ll be fully prepared to take advantage of Java’s ease of development, and able to create powerful, sophisticated Java applications.


Java has been described as “a simple, robust, object-oriented, platform-independent, multithreaded, dynamic, general-purpose programming environment.” Living up to this definition allowed Java to grow and expand into so many niches that it’s almost unrecognizable from its earliest days. Today you can find Java just about anywhere you can find a microprocessor. It’s used in the largest of enterprises to the smallest of devices, and it’s used in devices from cell phones to supercooled mainframes. For Java to support such a wide range of environments, an almost bewildering array of application programming interfaces (APIs) and versions have been developed, though they’re built around a common set of core classes. In order to become a good Java programmer, it’s important to be able to do the basics well. Being able to produce a highly complex user interface is all very well, but if your code is bloated, memory hungry, and inefficient, your users won’t be happy. This book isn’t about the huge array of development options available to you as a Java developer but about how to do the common tasks that as a Java developer you’ll encounter again and again. Over the course of the book, we’ll examine some of the core language features, such as threading and memory management, that can really make the difference in a professional-quality Java application.

At the core of Java’s adaptability, and hence popularity, is that it’s platform-independent. Its “write once, run anywhere” (WORA) capability stems from the way Java itself operates and in particular from the use of an abstract execution environment that allows Java code to be separated from the underlying operating system. Whereas the rest of this book will be about exploring the programming language and APIs of Java, in this chapter we’ll look at the foundations of how Java really operates under the hood, with the Java Virtual Machine (JVM). Understanding the inner workings of Java will give you as a programmer a better understanding of the language, which should make you a better programmer.

In this chapter, we’ll cover the following:

  • How the JVM allows Java to be platform-independent
  • What happens when you run a Java program
  • What a Java class file really contains
  • The key tools needed to work with a JVM
  • First, then, let’s look at what Java actually is.

In this chapter, we covered a number of issues related to the design of packages, classes, and methods,
including the following:

  • You can make a library of classes more manageable by organizing the classes into packages.
  • Creating classes, interfaces, and packages with loose coupling and strong cohesion tends to make those items more reusable.
  • Encapsulation provides many advantages, including the ability to hide implementation details and insulation from changes in implementation.
  • Immutable objects and fields can simplify an object-oriented design. •
  • The Objectclass contains a number of important methods that it may be necessary or helpful to override.
  • Method design and naming are an important part of a good design. Method design greatly influences the reusability of your code, while naming is an important part of making your code intuitive and easy to understand.
  • Minimizing code duplication not only saves time but also makes your code more reliable and maintainable.
  • Java’s exception handling mechanism is a powerful, flexible facility that can handle conditions that require attention during the execution of your application.
  • Assertions can improve your code’s correctness by checking for a condition that you expect to be true under normal circumstances.
  • Enumerations are useful when defining a finite set of values that are employed to identify a selection or some kind of state

In this chapter we’ve examined some—but certainly not all—of the features that have caused Java 8 to receive so much attention, including lambda expressions, default methods, the Streams API, and the new Date and Time API. These are arguably the most important of the new features introduced in Java 8, and when used in a Java application they make that application easier to write, and easier to maintain, and can allow it to process larger volumes of data more efficiently.