Chapter 2. Classes and Objects

 

First things first, but not necessarily in that order.

 
 --Dr. Who, Meglos

The fundamental programming unit of the Java programming language is the class. Classes provide the structure for objects and the mechanisms to manufacture objects from a class definition. Classes define methods: collections of executable code that are the focus of computation and that manipulate the data stored in objects. Methods provide the behavior of the objects of a class. Although you can compute using only primitive types—integer, floating-point, and so on—almost any interesting program will create and manipulate objects.

Object-oriented programming strictly separates the notion of what is to be done from how it is done. “What” is described ...

Get THE Java™ Programming Language, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.