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

Identifying actions to create methods


So far, we designed nine classes and identified the necessary fields for each of them. Now, it is time to add the necessary pieces of code that work with the previously defined fields to perform all the necessary tasks, that is, to calculate perimeters and areas. We have to make sure that each class has the necessary encapsulated functions that process the property values specified in the objects to perform all the tasks.

Let's forget a bit about similarities between the different classes. We will work with them individually as if we didn't have the necessary knowledge of geometric formulas. We will start with the Circle class. We need pieces of code that allow each instance of this class to use the value of the radius property to calculate the area and perimeter.

Note

The functions defined in a class to encapsulate the behavior of each instance of the class are known as methods. Each instance can access the set of methods exposed by the class. The code...