Teachnique
      CourseRoadmaps
      Login

      OverviewHistoryFeaturesJava 8 - New Featuresvs C++Virtual Machine(JVM)JDK vs JRE vs JVMHello World ProgramEnvironment SetupBasic SyntaxVariable TypesData TypesType CastingUnicode SystemBasic OperatorsCommentsStreamsNew Date-Time API

      Loop ControlDecision Makingif-else Statementswitch statementfor loopfor each Loopwhile Loopdo...while Loopbreak Statementcontinue Statement

      OOPs (Object-Oriented Programming) ConceptsObject and ClassesClass AttributesClass MethodsMethodsVariable ScopesConstructorsAccess ModifiersInheritanceAggregationPolymorphismOverridingMethod OverloadingDynamic BindingStatic BindingInstance Initializer BlockAbstractionEncapsulationInterfacesPackagesInner classesStatic ClassesAnonymous ClassesSingleton ClassWrapper ClassesEnum Class

      Number ClassBoolean classCharacter ClassArraysMath Class

      File ClassCreating FilesWrite To FilesReading FileDelete FilesDirectory OperationsFiles and I/O

      ExceptionsTry Catch BlockTry with ResourcesMultiple Catch BlocksNested Try BlockFinally BlockThrows and Throw | Throw an ExceptionException PropagationBuilt-in ExceptionsCustom Exception

      MultithreadingThread Life CycleCreating a ThreadStarting a ThreadJoining ThreadsNaming a Thread with ExamplesScheduling Threads with ExamplesThread PoolsMain ThreadThread PriorityDaemon ThreadThreadGroup ClassJVM Shutdown Hook

      Thread SynchronizationBlock SynchronizationStatic SynchronizationInter Thread CommunicationThread DeadlockInterrupting ThreadThread ControlReentrant Monitor

      NetworkingSocket ProgrammingURL ProcessingURL ClassURLConnection ClassHttpURLConnection ClassSocket Class with ExamplesGenerics

      Collections FrameworkCollection Interface

      List InterfaceArrayList Class

      Queue InterfaceArrayDeque Class

      Map InterfaceSortedMap Interface

      Set InterfaceSortedSet Interface

      Data Structures Enumeration Interface BitSet Class

      How to Use Iterator?How to Use Comparator?How to Use Comparable?

      RecursionRegular ExpressionsSerializationString ClassJava Arrays - Class

      Feedback

      Submit request if you have any questions.

      Course
      Character Class

      Java Tutorial

      This Java tutorial is tailored for newcomers, offering a journey from basic principles to complex Java programming techniques. Completing this tutorial equips you with a solid understanding of Java, preparing you for advanced learning. You'll emerge ready to tackle the challenges of becoming a top-tier software engineer, with the skills to innovate and excel in the vast world of software development.

      Character Class

      
      Normally, when we work with characters, we use primitive data types char.
      Example
      char ch = 'a';
      
      // Unicode for uppercase Greek omega character
      char uniChar = '\u039A';
      
      // an array of chars
      char[] charArray ={ 'a', 'b', 'c', 'd', 'e' };

      Use of Character Class in Java

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

      Java Character Class

      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 of Java Character Class

      // Here following primitive char 'a'
      // is boxed into the Character object ch
      Character ch = 'a';
      
      // Here primitive 'x' is boxed for method test,
      // return is unboxed to char 'c'
      char c = test('x');

      Escape Sequences

      A character preceded by a backslash (\) is an escape sequence and has a 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
      Inserts a tab in the text at this point.
      \b
      Inserts a backspace in the text at this point.
      \n
      Inserts a newline in the text at this point.
      \r
      Inserts a carriage return in the text at this point.
      \f
      Inserts a form feed in the text at this point.
      \'
      Inserts a single quote character in the text at this point.
      \"
      Inserts a double quote character in the text at this point.
      \\
      Inserts 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: Escape Sequences

      If you want to put quotes within quotes, you must use the escape sequence, \", on the interior quotes
      public class Test {
      
      public static void main(String args[]) {
      System.out.println("She said \"Hello!\" to me.");
      }
      }

      Output

      She said "Hello!" to me.

      Character Class Methods

      Following is the list of the important instance methods that all the subclasses of the Character class implement
      Sr.No.
      Method & Description
      1
      isLetter()
      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 value that is, a one-character string.
      For a complete list of methods, please refer to the java.lang.Character API specification.