Characters In Java

April 30, 2017
Categorised in: Java Core
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.
Pratik Kataria is currently learning Springboot and Hibernate.
Technologies known and worked on: C/C++, Java, Python, JavaScript, HTML, CSS, WordPress, Angular, Ionic, MongoDB, SQL and Android.
Softwares known and worked on: Adobe Photoshop, Adobe Illustrator and Adobe After Effects.