Is your Java system setup to handle programming errors, or exceptions, gracefully and with minimal impact on the user experience? Do you know how to setup assertions to check your code? Do you know how to log events so that issues can be assessed and debugged painlessly and easily? Help is at hand! Welcome to your ‘Java Masterclass: Java Exceptions, Assertions and Logging’ – a concise, focused book designed to get you up-and-running in this critical world of Java development and administration.
Written by leading Java Expert, Sam Alapati, and aimed at newcomers to the world of exceptions, assertions and logging, this book cuts-to-the-chase in a logical and easy-to-understand manner. Get under the hood and find out about declaring, throwing and catching exceptions; what checked and unchecked exceptions mean; how to define custom exception classes; why (and how) you should use assertions; the value and power of logging; and much more! Even more experienced Java developers and administrators should gain valuable information and knowledge from this book.
> Learn about the different Types of Exception, and how to deal with them elegantly
> Dig deep into Exception Objects and learn how to Define Custom Exceptions
> Discover practical guidelines on the effective use of Exceptions, including when to chain Exceptions
> Sanity check your application code, using simple pass/fail Assertion tests
> Get to grips with java.util.logging, Log4J, and other logging frameworks
> Filled with lots of sample code, hints, tips and notes. Download the code from this website for free.
As a beginners guide, this book is primarily aimed at newcomers to the world of Java Exceptions, Assertions and Logging. More experienced administrators and developers may also find much of the information valuable and useful.
Sam Alapati is Senior Database Architect and Manager at Cash America, and the author of more than a dozen acclaimed IT books. He is an experienced Oracle database administrator who holds the Oracle Certified Professional designation and the Hewlett-Packard UNIX System Administrator certification.
Authors: Sam Alapati
Published May 15th, 2014 | 198 pages (paperback) $19.99 | eBook $9.99 | ISBN: 978-0957410541
Chapter 1 – Java 8 and Interface Enhancements
Introduction to Java 8
Default Methods and Functional Interfaces
Creating Default Methods
Understanding the Importance of Default Methods
Defining a Default Method
Overriding Default Methods
Using Inheritance with Default Methods
Working with Single Inheritance
Working with Multiple Inheritance
Understanding how Diamond Inheritance Works
Resolving Overridden Default Methods
Using Default Methods
Extending Existing Interfaces
Using Default Methods to Supplement Adapter Classes
Using Default Methods in Core Java Classes
Using a Class to Support Default Methods
Understanding the Difference between an Abstract Class and Interfaces
Using Static Interface Methods
Functional Interfaces
Creating a Functional Interface
Using the @FunctionalInterface Annotation
Overriding Object Class Methods in a Functional Interface
Using Functional Interfaces in the Core Libraries
Conclusion
Chapter 2 – Lambda Expressions
Understanding Lambda Expressions
Inferring the Type of the Target
Creating Lambda Expressions
Lambda Expression Syntax Rules
Declaring Parameter Types
Mixing Parameter Declarations
Omitting Parentheses
Eliminating the Block Statement
Using Multiple Statements in a Lambda Expression Body
Using a Return Value
Writing Succinct Lambda Expressions
Capturing Variables in a Lambda Expression
Differentiating between a Lambda Expression and a Closure
Method and Constructor References
Using Static Method References
Using Instance Method References
Using Constructor References
Working with Lambda Expressions
Using Lambda Expressions with Variable Declarations
Using Lambda Expressions as a Return Value
Using Exceptions with a Lambda Expression
Using Lambda Expressions with the Tertiary Operator
Casting Lambda Expressions
Using Lambda Expressions to Initialize an Array
Writing Recursive Lambda Expressions
Using the java.util.function Functional Interfaces
Using the Predicate Interface
Using the Function Interface
Using the BiFunction Interface
Using the Consumer Interface
Using the Supplier Interface
Using Operator Type Interfaces
Using the UnaryOperator Interface
Using the BinaryOperator Interface
Conclusion
Chapter 3 – Streams
Streams
Stream Characteristics
Streams Do Not Store Elements
Streams Can Be Unbounded
Streams Do Not Modify the Original Source
A Stream May Be Ordered
Automatic Parallelization
An Overview of Stream Methods
Creating a Stream
Using the Stream Interface’s of Method
Using the Collection Class’ stream Method
Using a Stream.Builder Interface
Using the builder method
Generating Infinite Streams
Using the iterate Method
Concatenating Streams
Generating an Empty Stream
Using Stream Methods
The Part Example Class
Using the forEach Method
Using the forEachOrdered Method
Using the map Method
Using Other Map Methods
Using the flatmap Method
Using the filter Method
Using the Match Type Methods
Using the findFirst Method
Using the findAny Method
Using the Optional Class
Using the reduce Method
Using the Collector Interface and the collect Method
Using the Collects Class
Using the iterator Method
Using the sorted Method
Using the distinct Method
Using the limit Method
Using the skip Method
Using the max, min, and count Methods
Streams for Primitive Types
Using the IntStream Interface
Understanding Lazy and Eager Evaluation
Using Short-Circuit Methods
Using Parallel Stream Operations
Conclusion
Chapter 4 – Date and Time
Introduction
Why a New API?
A Simple Example
The ISO-8601 String Format
Design Considerations
Understanding the Standard Method Names
Understanding the of Type Methods
Understanding the from Method
Understanding the parse Method
Understanding the format Method
Understanding the get Type Method
Understanding the is Type Methods
Understanding the with Type Methods
Understanding the plus Type Methods
Understanding minus Type Methods
Understanding the to Type Methods
Understanding the at Type Methods
Overview of the Date and Time Packages
Getting the Current Time
Working with the Instant Class
Creating an Instant
Creating an Instant Based on the Epoch
Creating an Instant Based on Parsing a UTC String
Creating an Instant by Adding or Subtracting a Time from an Instant
Using the Instant Class’ get Type Methods
Working with Time Intervals
Creating Offsets Using the of Type Methods
Creating Offsets Using the with Type Methods
Creating a Duration Using the parse Method
Creating a Duration by Adding or Subtracting a Unit
Using the Duration Class
Using the Period Class
Using Date and Time Classes
Creating Date and Time Classes
Date and Time get Type Methods
Adjusting a Date or Time
Using the YearMonth, MonthDay, and Year Classes
Comparing MonthDay Instances
Using the Enumerations DayOfWeek and Month
Using the DayOfWeek Enumeration
Using the Month Enumeration
Working with the Time Zone and Offset Classes
Obtaining Available Zone Ids
Working with ZoneOffsets
Working with Zone Rules
Formatting, Queries, and Value-Based Classes
Formatting Dates and Times
Using Temporal Queries
Understanding Value-Based Classes
Conclusion
Chapter 5 – Odds and Ends
Introduction
Using the Nashorn JavaScript Engine
Accessing the Nashorn Engine
Executing JavaScript Code
Executing Java Code from JavaScript
Implementing a Java Interface
File IO Enhancements
Using the FileFilter Interface
Using the PathMatcher Interface
Using the Files Class’ list Method
Using the Files Class’ walk Method
Using the Path Class’ lines Method
Concurrency Enhancements
Using the Arrays Class’ parallelSort Method
Using the Arrays Class’ parallelSetAll Method
Using the Arrays Class’ parallelPrefix Method
Collections Enhancements
Using the forEachRemaining Method
Using the replace Type Methods
Using the compute Type Methods
Project Jigsaw and Compact Profiles
The Compact Profiles
Using Compact Profiles
Other Enhancements
Javadoc Enhancements
Security Enhancements
VM Related Enhancements
Core Java Enhancements
Conclusion
Appendix A – Date and Time Classes
Of Type Methods
The from Method
The parse Method
Get Type Methods
Is Type Methods
With Type Methods
Plus Type Methods
Minus Type Methods
To Type Methods
At Type Methods
Book Categories: Java.