Strings And Characters
A char stores one UTF-16 code unit and uses single quotes. A String stores a sequence of characters and uses double quotes.
Strings are objects, not primitives. They still receive special syntax because text is so common in programs.
One character and one string
public class Main {
public static void main(String[] args) {
char grade = 'A';
String subject = "Java";
System.out.println("Grade: " + grade);
System.out.println("Subject: " + subject);
}
}
Output:
Grade: A
Subject: Java
The character 'A' holds one code unit, while "Java" holds several characters. Both can take part in string concatenation once Java reaches a string operand.
'games' is invalid because a char literal holds exactly one character. Use "games" for text of any length.
Store section 'B' and course "Java" with the right text types, then print B-Java.