Char variables

Programs that manipulate numbers are all well and good, but quite often, we want to be able to work with text and words as well. To help us do this, Java defines the character, or char, the primitive type. Characters are the smallest entity of text that you can work with on a computer. We can think of them to start off with as single letters.

Let's create a new project; we'll call it Characters.java. We'll start our program by simply defining a single character. We'll call it character1 and we'll assign to it the value of uppercase H:

package characters; 
 
public class Characters { 
    public static void main(String[] args) { 
        char character1 = 'H'; 
    } 
} 

Just as we have to use some extra syntax when defining a floating-point number ...

Get Java Programming for Beginners 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.