Abstract
This chapter opens with some discussion of object-oriented concepts such as information hiding and the encapsulation of state and behavior inside objects. This is followed by an illustration of how classes and their fields and methods are represented in the Unified Modeling Language (UML). Subsequent code examples show how new domain classes can be created in Java, along with their fields, methods and constructors, and how Eclipse provides automated support for some of these tasks. The overloading of the constructor method to provide ways of creating objects with different sets of arguments is also explained. Further discussion of encapsulation covers constructor chaining and the four visibility modifiers; “public”, “private”, “default” and “protected”. The chapter goes on to show how the Javadoc tool can be used to generate HTML documentation for user-created classes, either from within Eclipse or from the command line. This includes some coverage of special Javadoc tags that can be added to comment blocks to provide additional information in the generated Javadoc. The final part of the chapter explores more specific aspects of creating classes including static fields and methods, JavaBean components, reflection and the “var” keyword, which can be used with local variables to allow the compiler to infer their data types.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
Copyright information
© 2020 Springer Nature Switzerland AG
About this chapter
Cite this chapter
Parsons, D. (2020). Creating Domain Classes. In: Foundational Java. Texts in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-030-54518-5_6
Download citation
DOI: https://doi.org/10.1007/978-3-030-54518-5_6
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-54517-8
Online ISBN: 978-3-030-54518-5
eBook Packages: Computer ScienceComputer Science (R0)