Home / Programs / character in java
🚀 Programming Example

character in java

👁 25,875 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 Program Code

 /*
        Java char Example
        This Java Example shows how to declare and use Java primitive char variable
        inside a java class.
*/
 
public class JavaCharExample {
 
        public static void main(String[] args) {
               
                /*
                 * char is 16 bit type and used to represent Unicode characters.
                 * Range of char is 0 to 65,536.
                 *
                 * Declare char varibale as below
                 *
                 * char <variable name> = <default value>;
                 *
                 * here assigning default value is optional.
                 */
 
                char ch1 = 'a';
                char ch2 = 65; /* ASCII code of 'A'*/
               
                System.out.println("Value of char variable ch1 is :" + ch1);   
                System.out.println("Value of char variable ch2 is :" + ch2);             
        }
}
 
                        

🖥 Program Output

Value of char variable ch1 is :a
Value of char variable ch2 is :A
Press any key to continue . . .
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.