CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Character data type in Java

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor
  • Home

Character data type in Java

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 ยท 3 min read ยท 0 Comments
Share: in X

In Java, the char data type is used to represent a single Unicode character. It is a 16-bit unsigned integer that can hold values from 0 to 65,535. The char data type is denoted by the keyword char. In this post, we will learn the detail of character data type in Java.

Table of Contents

  • Declaration and Initialization
  • Unicode Representation
  • Escape Sequences
  • Character Literals
  • Character Operations
  • Frequently Asked Questions
    • What is the character data type in Java?
    • How do I declare and initialize a char variable in Java?
    • Can I store more than one character in a char variable?
    • What is the Unicode representation of a char in Java?
    • How can I convert a char to an integer in Java?

Declaration and Initialization

You can declare a char variable by specifying the char keyword, followed by the variable name. For example:

char myChar;

You can also initialize the variable at the time of declaration:

char myChar = 'A';

Unicode Representation

The char data type in Java represents characters using Unicode encoding.

Unicode is a universal character encoding standard that assigns a unique numerical value (code point) to each character from various writing systems and scripts.

Characters in Java are represented using the UTF-16 encoding, which uses 16 bits to represent a character.

Escape Sequences

In Java, you can use escape sequences to represent special characters that cannot be directly represented using a single character.

Some commonly used escape sequences include:

SequenceDescription
'\n'Newline
'\t'Tab
'\r'Carriage return
'\b'Backspace
'\''Single quote
'\"'Double quote
'\\'Backslash

Character Literals

Character literals in Java are enclosed in single quotes ('').

You can represent a character using its Unicode value, an escape sequence, or the actual character itself. For example:

char ch1 = 'A'; // Character 'A' char ch2 = '\u0041'; // Unicode representation of 'A' char ch3 = '\n'; // Newline character

Character Operations

You can perform various operations on char values, such as comparisons (==, !=), arithmetic operations (using the underlying Unicode values), and type conversions.

The char data type in Java allows you to work with individual characters and perform operations on them. It is widely used when dealing with text processing, string manipulation, and character-based operations.

Frequently Asked Questions

What is the character data type in Java?

The character data type in Java, denoted as char. It is used to represent single Unicode characters, such as letters, digits, and symbols.

How do I declare and initialize a char variable in Java?

You can declare and initialize a char variable like this:
char myChar = 'A';.

Can I store more than one character in a char variable?

No, a char variable can hold only a single character. To store multiple characters, you would use a String or an array of char.

What is the Unicode representation of a char in Java?

In Java, a char represents a Unicode character, which is a 16-bit value, allowing it to represent a wide range of characters from different languages.

How can I convert a char to an integer in Java?

You can convert a char to an integer using explicit casting, like this:
int charToInt = (int) myChar;.
This will give you the Unicode code point of the character.

Related Posts:

  • Integers In Java
  • Declaration in Java
  • Primitive data types in Java
  • Identifiers in Java
  • final Keyword in Java
  • Variable in Java
Tags:java
Was this article helpful?
โ† Previous ArticleFloating point in Java
Next Article โ†’Arrays in Java

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
ยฉ 2026 CoderSathi. All rights reserved. Privacy Policy ยท Sitemap