how to declare and use Java primitive char variable - Java Language Basics

Java examples for Language Basics:char

Introduction

Java char is 16 bit type and used to represent Unicode characters.

Range of char is 0 to 65,536.

Demo Code

 
public class Main {
        public static void main(String[] args) {
                char ch1 = 'a';
                char ch2 = 65; /* ASCII code of 'A'*/
               /* w ww  . ja  v a  2 s  .  c  o  m*/
                System.out.println("Value of char variable ch1 is :" + ch1);   
                System.out.println("Value of char variable ch2 is :" + ch2);             
        }
}

Result


Related Tutorials