CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Java

Java Programming
String variables
Create a String object

Java provides the class String which contains various operations to manipulate a string.

How to create and use strings

  • A string can consist of any characters in the character set including letters, numbers, and special characters like *, &, and #.
  • In Java, a string is actually a String object that's created from the String class that's part of the Java API.
  • To specify the value of a string, you can enclose text in double quotation marks. This is known as a string literal.
  • To assign a null value to a string, you can use the null keyword. This means that the value of the string is unknown.
  • To assign an empty string to a String object, you can code a set of quotation marks with nothing between them.
  • To join (or concatenate) a string with another string or a data type, use a plus sign. Whenever possible, Java will automatically convert the data type so it can be used as part of the string.
  • When you append one string to another, you add one string to the end of another. To do that, you can use assignment statements.
  • The += operator is a shortcut for appending a string expression to a string variable.

Previous | String variables | Create a String object | Join and append strings | Special characters | Next