Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment
Back to Classroom
Char
Java Basics Course
Engineers From These Top Companies and Universities Trust EXLskills
1M+ Professionals | 100+ Institutions
This is the EXLskills free and open-source Java Basics Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.
-->
Is this course FREE?
Yes, this a 100% free course that you can contribute to on GitHub here!
The next datatype we will look at is character, which is represented with char in Java. A char can almost represent any character in any language. To see a full list of potential characters, look up the Unicode character table. View the code below for an example of how to declare and use the character datatype.
CharDataTypeExample.java
package exlcode;
public class CharDataTypeExample {
// char can be any one character, including spaces
public static char exampleVariableOne = 'c';
public static char exampleVariableTwo = 'V';
public static char exampleVariableThree = ' ';
public static void main(String[] args) {
System.out.println(exampleVariableOne);
System.out.println(exampleVariableTwo);
System.out.println(exampleVariableThree + "Hello World!");
}
}
char holds a single character with an apostrophe on each side. Notice that double quotation marks will not work for characters. Keep in mind that upper and lower case characters are represented by a different pattern. Additionally, special characters such as punctuation and spaces can be represented by the char data type as well.