From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Working with character values - Java Tutorial
From the course: Java 8 Essential Training
Working with character values
- Java distinguishes between characters and strings. A character is a primitive data type, and it consists of just a single character. A string is a complex object, and can consist of many characters. I'll show you how to to declare and initialize characters here, and I'll add code to the main method to declare a single variable with the data type of char, C-H-A-R, a name of c1, and a value of '1', wrapped in single quotes. Literals for characters are always wrapped in single quotes, while literals for strings are wrapped in double quotes. I'll duplicate that line of code a couple of times. And then I'll change the names of the variables, to c2 and c3. And I'll change their equivalent values. Then, I'll output these values. I'll use System.out, and I'll start with the label of Char 1, and I'll append c1. I'll duplicate that a couple of times, and change the labels and values. And I get the values as expected. You can also declare a character using a literal that's a Unicode escape…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Working with primitive variables8m 4s
-
Declaring and initializing numeric primitives6m 14s
-
Representing currency values with BigDecimal5m 10s
-
Converting numeric values5m 37s
-
Using mathematical operators and the Math class6m 1s
-
Working with Boolean values and expressions4m 49s
-
Working with character values3m 23s
-
Using Java operators6m 11s
-
-
-
-
-
-
-
-
-
-