Q&A

Q1:I'm confused about the differences between objects and the primitive data types, such as int and boolean .
A1: The primitive types (byte , short , int , long , float , double , boolean , and char ) represent the smallest things in the language. They are not objects, although in many ways they can be handled like objects: They can be assigned to variables and passed in and out of methods. Most of the operations that work exclusively on objects, however, will not work with primitive types.

Objects are instances of classes and, as such, are usually much more complex data types than simple numbers and characters, often containing numbers and characters as instance or class variables.

Q2:The length() and charAt() methods in Listing 4.3 ...

Get Sams Teach Yourself Java 2 in 21 Days, Second 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.