7.3. Field Defaults and Field Initializers

Local variables do not have a default value. They cannot be used until they are initialized. By contrast, class fields are automatically initialized to the default values for their types. As you may recall from Chapter 3, fields are set to 0 or null or false by default, depending on their type. It is a good idea, however, to set your instance fields to something you can use and not just leave them with their defaults.

As you might imagine, initializing a class field value looks like this:

public int i = 3; 
public static boolean b = true;

The syntax here is useful if you want to have all of a class's constructors set your instance field to the same value. You can initialize objects through initialization ...

Get Java™ for ColdFusion® Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.