Book Image

Java 9 with JShell

By : Gaston C. Hillar
Book Image

Java 9 with JShell

By: Gaston C. Hillar

Overview of this book

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 (23 chapters)
Java 9 with JShell
Credits
About the Author
Acknowledgement
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Index

Recognizing variables and constants


We know the information required for each of the shapes to achieve our goals. Now, we have to design the classes to include the necessary fields that provide the required data to each instance. We have to make sure that each class has the necessary fields that encapsulate all the data required by the objects to perform all the tasks based on our application domain.

Let's start with the Circle class. We need to know the radius for each instance of this class, that is, for each circle object. Thus, we need an encapsulated variable that allows each instance of the Circle class to specify the value for the radius.

Note

The variables defined in a class to encapsulate the data for each instance of the class in Java 9 are known as fields. Each instance has its own independent value for the fields defined in the class. The fields allow us to define the characteristics for an instance of the class. In other programming languages that support object-oriented principles...