SH1801
Java Strings
I. Java Strings
• A string is composed of sequences of characters.
• Enclosed in double quotations (“”) in a statement
• Unique in that they do not need an array of characters for representation
II. Storing Text in Strings
A. Methods of Storing Text in Strings
• Text can be stored in strings by initializing a variable through the use of an
identifier.
• Text can also be stored via assigning of values on declared or existing
variables.
III. Special Characters in Strings
A. Why can’t I use some characters in Java strings?
• Some characters have an exclusive use in Java, such as arithmetic
operators.
• Some characters and symbols, when used, will cause errors in the
statements containing them.
B. The Backslash Symbol (\)
• Used to insert special characters in Java strings
• Also used to execute certain commands in strings values
IV. Displaying Strings
A. Statements used to display strings in Java
• [Link]( ) is used to print strings in a single line, without line breaks
for each consecutive statement; subsequent strings will continue to be printed
without line breaks as if printed in a single, continuous line.
• [Link]( ) is used to print strings with a line break at the end;
each consecutive string is printed on its own designated line.
B. What is printing?
• The method or task of displaying text in a Java program
• Used whenever a need to display output for an application arises
07 Handout 1 *Property of STI
Page 1 of 2
SH1801
V. Concatenating Strings
A. What is concatenation?
• The process of connecting two (2) related strings to form a single string
• Uses the plus sign (+) between two (2) string values; the sign “connects” two
string values to form a single Java string
VI. Other Variables with Strings
• Java allows non-string values and variables to be used in strings.
• Java can properly utilize variables and concatenation to produce varying string
values for a single task or process.
References:
• Deitel, H., & Deitel, P. (2004). Java: How to program (early objects). Prentice Hall.
• Lambert, K., Osborne, M. (2011). Fundamentals of Java. Cengage Learning Asia
Pte Ltd.
07 Handout 1 *Property of STI
Page 2 of 2