Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Java 9 with JShell

You're reading from   Java 9 with JShell Introducing the full range of Java 9's new features via JShell

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781787282841
Length 408 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Gaston C. Hillar Gaston C. Hillar
Author Profile Icon Gaston C. Hillar
Gaston C. Hillar
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. JShell – A Read-Evaluate-Print-Loop for Java 9 FREE CHAPTER 2. Real-World Objects to UML Diagrams and Java 9 via JShell 3. Classes and Instances 4. Encapsulation of Data 5. Mutable and Immutable Classes 6. Inheritance, Abstraction, Extension, and Specialization 7. Members Inheritance and Polymorphism 8. Contract Programming with Interfaces 9. Advanced Contract Programming with Interfaces 10. Maximization of Code Reuse with Generics 11. Advanced Generics 12. Object-Oriented, Functional Programming, and Lambda Expressions 13. Modularity in Java 9 A. Exercise Answers Index

Creating mutable classes in Java 9

When we declare instance fields without the final keyword, we create a mutable instance field, which means that we can change their values for each new instance we create after the field is initialized. When we create an instance of a class that defines at least one mutable field, we create a mutable object, which is an object that can change its state after its initialization.

Note

A mutable object is also known as a mutating object.

For example, imagine that we have to develop a Web Service that renders elements in the 3D world and returns a high-resolution rendered scene. Such a task requires us to work with 3D vectors. First, we will work with a mutable 3D vector with three mutable fields: x, y, and z. The mutable 3D vector must provide the following features:

  • Three mutable instance fields of type double: x, y, and z.
  • A constructor that creates an instance by providing the initial values for the x, y, and z fields.
  • A constructor that creates an instance...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime