Java 9 with JShell

Explore Java 9 with JShell and UML

Java 9 with JShell

This ebook is included in a Mapt subscription
Gastón C. Hillar

Explore Java 9 with JShell and UML
$10.00
$49.99
RRP $39.99
RRP $49.99
eBook
Print + eBook
Access every Packt eBook & Video for just $100
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Find Out More
 
Preview in Mapt

Book Details

ISBN 139781787282841
Paperback408 pages

Book Description

The release of Java 9 has brought many subtle and not-so-subtle changes to the way in which Java programmers approach their code. The most important ones are definitely the availability of a REPL, known as JShell, which will make experiments and prototyping much more straightforward than the old IDE-based project-led approach. Another, more subtle change can be seen in the module system, which will lead to more modularized, maintainable code. The techniques to take full advantage of object-oriented code, functional programming and the new modularity features in Java 9 form the main subjects of this book.

Each chapter will add to the full picture of Java 9 programming starting out with classes and instances and ending with generics and modularity in Java.

Table of Contents

Chapter 1: JShell – A Read-Evaluate-Print-Loop for Java 9
Getting ready for our journey toward OOP with Java 9
Installing the required software on Windows, macOS, or Linux
Running Java 9 code in JShell
Working with variables, methods, and sources
Editing the source code in our favorite external code editor
Loading source code
Test your knowledge
Summary
Chapter 2: Real-World Objects to UML Diagrams and Java 9 via JShell
Identifying objects from applications requirements
Capturing real-world objects
Generating classes to create objects
Recognizing variables and constants
Identifying actions to create methods
Organizing classes with UML diagrams
Using feedback from domain experts
Test your knowledge
Summary
Chapter 3: Classes and Instances
Understanding classes and instances in Java 9
Working with object initialization and its customization
Introducing garbage collection
Declaring classes
Customizing constructors and initialization
Understanding how garbage collection works
Creating instances of classes and understanding their scope
Exercises
Test your knowledge
Summary
Chapter 4: Encapsulation of Data
Understanding members composing a class
Declaring immutable fields
Working with setters and getters
Combining setters, getters, and fields
Transforming values with setters and getters
Using static fields to provide class-level values
Using static methods to provide overridable class-level values
Test your knowledge
Summary
Chapter 5: Mutable and Immutable Classes
Creating mutable classes in Java 9
Working with mutable objects in JShell
Building immutable classes in Java 9
Working with immutable objects in JShell
Understanding the differences between mutating and non-mutating objects
Learning the advantages of non-mutating objects when writing concurrent code
Working with instances of the immutable String class
Creating the immutable version of an existing mutable class
Test your knowledge
Summary
Chapter 6: Inheritance, Abstraction, Extension, and Specialization
Creating class hierarchies to abstract and specialize behavior
Understanding inheritance
Creating an abstract base class
Declaring classes that inherit from another class
Overriding and overloading methods
Test your knowledge
Summary
Chapter 7: Members Inheritance and Polymorphism
Creating concrete classes that inherit from abstract superclasses
Understanding polymorphism
Controlling overridability of members in subclasses
Controlling subclassing of classes
Creating methods that work with instances of different subclasses
Test your knowledge
Summary
Chapter 8: Contract Programming with Interfaces
Understanding how interfaces work in combination with classes
Declaring interfaces
Declaring classes that implement interfaces
Taking advantage of the multiple inheritance of interfaces
Combining class inheritance and interfaces
Test your knowledge
Summary
Chapter 9: Advanced Contract Programming with Interfaces
Working with methods receiving interfaces as arguments
Downcasting with interfaces and classes
Treating instances of an interface type as a different subclass
Taking advantage of default methods in interfaces in Java 9
Test your knowledge
Summary
Chapter 10: Maximization of Code Reuse with Generics
Understanding parametric polymorphism, Java 9 generics, and generic code
Declaring an interface to be used as a type constraint
Declaring a class that conforms to multiple interfaces
Declaring subclasses that inherit the implementation of interfaces
Creating exception classes
Declaring a class that works with a constrained generic type
Using a generic class for multiple compatible types
Test your knowledge
Summary
Chapter 11: Advanced Generics
Creating a new interface to be used as a constraint for a second type parameter
Declaring two classes that implement an interface to work with two type parameters
Declaring a class that works with two constrained generic types
Creating instances of a generic class with two generic type parameters
Test your knowledge
Summary
Chapter 12: Object-Oriented, Functional Programming, and Lambda Expressions
Understanding functions and methods as first-class citizens
Working with functional interfaces and lambda expressions
Creating a functional version of array filtering
Creating a data repository with generics and interfaces
Filtering collections with complex conditions
Using a map operation to transform values
Combining a map operation with reduce
Chaining many operations with map and reduce
Working with different collectors
Test your knowledge
Summary
Chapter 13: Modularity in Java 9
Refactoring existing code to take advantage of object-oriented programming
Organizing object-oriented code with the new modularity in Java 9
Creating modular source code
Compiling multiple modules with the Java 9 compiler
Run modularized code with Java 9
Test your knowledge
Summary

What You Will Learn

  • Engage with object-oriented programming in Java 9, starting with code snippets in JShell
  • Optimize your code, applying functional programming features
  • Discover the advantages of modularity.
  • Become very proficient at using JShell itself
  • Learn the new approach to Java programming, which uses the REPL as a prototyping tool

Authors

Table of Contents

Chapter 1: JShell – A Read-Evaluate-Print-Loop for Java 9
Getting ready for our journey toward OOP with Java 9
Installing the required software on Windows, macOS, or Linux
Running Java 9 code in JShell
Working with variables, methods, and sources
Editing the source code in our favorite external code editor
Loading source code
Test your knowledge
Summary
Chapter 2: Real-World Objects to UML Diagrams and Java 9 via JShell
Identifying objects from applications requirements
Capturing real-world objects
Generating classes to create objects
Recognizing variables and constants
Identifying actions to create methods
Organizing classes with UML diagrams
Using feedback from domain experts
Test your knowledge
Summary
Chapter 3: Classes and Instances
Understanding classes and instances in Java 9
Working with object initialization and its customization
Introducing garbage collection
Declaring classes
Customizing constructors and initialization
Understanding how garbage collection works
Creating instances of classes and understanding their scope
Exercises
Test your knowledge
Summary
Chapter 4: Encapsulation of Data
Understanding members composing a class
Declaring immutable fields
Working with setters and getters
Combining setters, getters, and fields
Transforming values with setters and getters
Using static fields to provide class-level values
Using static methods to provide overridable class-level values
Test your knowledge
Summary
Chapter 5: Mutable and Immutable Classes
Creating mutable classes in Java 9
Working with mutable objects in JShell
Building immutable classes in Java 9
Working with immutable objects in JShell
Understanding the differences between mutating and non-mutating objects
Learning the advantages of non-mutating objects when writing concurrent code
Working with instances of the immutable String class
Creating the immutable version of an existing mutable class
Test your knowledge
Summary
Chapter 6: Inheritance, Abstraction, Extension, and Specialization
Creating class hierarchies to abstract and specialize behavior
Understanding inheritance
Creating an abstract base class
Declaring classes that inherit from another class
Overriding and overloading methods
Test your knowledge
Summary
Chapter 7: Members Inheritance and Polymorphism
Creating concrete classes that inherit from abstract superclasses
Understanding polymorphism
Controlling overridability of members in subclasses
Controlling subclassing of classes
Creating methods that work with instances of different subclasses
Test your knowledge
Summary
Chapter 8: Contract Programming with Interfaces
Understanding how interfaces work in combination with classes
Declaring interfaces
Declaring classes that implement interfaces
Taking advantage of the multiple inheritance of interfaces
Combining class inheritance and interfaces
Test your knowledge
Summary
Chapter 9: Advanced Contract Programming with Interfaces
Working with methods receiving interfaces as arguments
Downcasting with interfaces and classes
Treating instances of an interface type as a different subclass
Taking advantage of default methods in interfaces in Java 9
Test your knowledge
Summary
Chapter 10: Maximization of Code Reuse with Generics
Understanding parametric polymorphism, Java 9 generics, and generic code
Declaring an interface to be used as a type constraint
Declaring a class that conforms to multiple interfaces
Declaring subclasses that inherit the implementation of interfaces
Creating exception classes
Declaring a class that works with a constrained generic type
Using a generic class for multiple compatible types
Test your knowledge
Summary
Chapter 11: Advanced Generics
Creating a new interface to be used as a constraint for a second type parameter
Declaring two classes that implement an interface to work with two type parameters
Declaring a class that works with two constrained generic types
Creating instances of a generic class with two generic type parameters
Test your knowledge
Summary
Chapter 12: Object-Oriented, Functional Programming, and Lambda Expressions
Understanding functions and methods as first-class citizens
Working with functional interfaces and lambda expressions
Creating a functional version of array filtering
Creating a data repository with generics and interfaces
Filtering collections with complex conditions
Using a map operation to transform values
Combining a map operation with reduce
Chaining many operations with map and reduce
Working with different collectors
Test your knowledge
Summary
Chapter 13: Modularity in Java 9
Refactoring existing code to take advantage of object-oriented programming
Organizing object-oriented code with the new modularity in Java 9
Creating modular source code
Compiling multiple modules with the Java 9 compiler
Run modularized code with Java 9
Test your knowledge
Summary

Book Details

ISBN 139781787282841
Paperback408 pages
Read More

Read More Reviews

Recommended for You

Mastering Concurrency Programming with Java 9 - Second Edition Book Cover
Mastering Concurrency Programming with Java 9 - Second Edition
$ 39.99
$ 10.00
Java Apps with Cloud9 on App Engine [Video] Book Cover
Java Apps with Cloud9 on App Engine [Video]
$ 124.99
$ 10.00
Functional Programming with Streams in Java 9 [Video] Book Cover
Functional Programming with Streams in Java 9 [Video]
$ 124.99
$ 10.00
Writing Java Apps with Cloud 9 [Video] Book Cover
Writing Java Apps with Cloud 9 [Video]
$ 124.99
$ 10.00
Writing High Performance Java Application in Java 9 [Video] Book Cover
Writing High Performance Java Application in Java 9 [Video]
$ 124.99
$ 10.00
Java 9 Concurrency - High-Level Elements [Video] Book Cover
Java 9 Concurrency - High-Level Elements [Video]
$ 124.99
$ 10.00