Core JAVA

Write Once, Run Anywhere

  • Java Basic
Java - Overview
Java - Environmental Setup
First Step towards Java Programming
Importing Classes
Java - Basic Datatypes
Java - Variable Types
Java - Modifier types
Java - Basic Operators
Java - Loop Control
Java - Decision Making
Java - Numbers
Java - Characters
Java - Strings
Java - Arrays
Java - Date & Time
Java - Regular Expressions
Java - Methods
Java - Files and I/O
Java - Exceptions
  • Java Object Oriented
Java - Inheritance
Java - Overriding
Java - Polymorphism
Java - Abstraction
Java - Encapsulation
Java - Interfaces
Java - Packages
  • Java Advanced
Java - Data Structures
Java - Collections
Java - Serialization
Java - Networking
Java - Multithreading
Java - Applet Basics


      Normally, when we work with Characters, we use primitive data types char.

Example




However in development we come across situations were we need to use objects instead of primitive data types. In-order to achieve this Java provides wrapper classes Character for primitive data type char.

The Character class offers a number of useful class (i.e., static) methods for manipulating characters. You can create a Character object with the Character constructor:



Character ch = new Character('a');

The Java compiler will also create a Character object for you under some circumstances. For example, if you pass a primitive char into a method that expects an object, the compiler automatically converts the char to a Character for you. This feature is called autoboxing or unboxing, if the conversion goes the other way.

Example




Escape Sequences

A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler.

The newline character (\n) has been used frequently in this tutorial in System.out.println() statements to advance to the next line after the string is printed.

Following table shows the Java escape sequences:

Escape Sequence Description
\t Insert a tab in the text at this point.
\b Insert a backspace in the text at this point.
\n Insert a newline in the text at this point.
\r Insert a carriage return in the text at this point.
\f Insert a form feed in the text at this point.
\' Insert a single quote character in the text at this point.
\" Insert a double quote character in the text at this point.
\\ Insert a backslash character in the text at this point.

When an escape sequence is encountered in a print statement, the compiler interprets it accordingly.

Example

If you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes:


Output


Characters Methods

Here is the list of the important instance methods that all the subclasses of the Character class implement:

SNMethods Description
1isLetter() Determines whether the specified char value is a letter.
2 isDigit() Determines whether the specified char value is a digit.
3 isWhitespace() Determines whether the specified char value is white space.
4 isUpperCase() Determines whether the specified char value is uppercase.
5 isLowerCase()Determines whether the specified char value is lowercase.
6 toUpperCase() Returns the uppercase form of the specified char value.
7 toLowerCase() Returns the lowercase form of the specified char value.
8 toString() Returns a String object representing the specified character valuethat is, a one-character string.
Powered by Blog - Widget
Face Upward - Widget