2.2 The Class String

Words, words, mere words, no matter from the heart.

—WILLIAM SHAKESPEARE, Troilus and Cressida

Strings of characters, such as "Enter the amount:", are treated slightly differently than values of the primitive types. Java has no primitive type for strings. However, Java supplies a class called String that can be used to create and process strings of characters. In this section, we introduce you to the class String.

Classes are central to Java, and you will soon define and use your own classes. However, this discussion of the class String gives us an opportunity to review some of the notation and terminology used for classes that Chapter 1 introduced.

String Constants and Variables

You have ...

Get Java: An Introduction to Problem Solving and Programming, 8th 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.