Please disable adblock to view this page.

← Go home

Characters In Java

java-display

April 30, 2017
Published By : Pratik Kataria
Categorised in:

Understanding Through Code

public class CharacterInJava {

	public static void main( String[] args ){

		char charVal1 = '1';
		char charVal2 = '2';
		char charVal3 = '3';

		System.out.println("charVal1: " +charVal1);
		System.out.println("charVal2: " +charVal2);
		System.out.println("charVal3: " +charVal3);

		char unicodeDollar = '\u0024';

		System.out.println("unicodeDollar: " +unicodeDollar);

		char c1 = 'a';
		char c2 = 'b';

		System.out.print(Character.toUpperCase(c1));  //Note print is used not println
		System.out.println(Character.toUpperCase(c2));


	}
}

Output

  • charVal1: 1
  • charVal2: 2
  • charVal3: 3
  • unicodeDollar: $
  • AB

Notes

  • In Java character variable can be assigned many characters.
  • Character is a primitive type.
  • Literals for character are wrapped in single quotes ‘ ‘
  • You can assign character variable a unicode number.
  • Character is the helper class that can be used on this primitive type.
  • ln is for line feed. So System.out.print() does not give a line feed.