Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

Characters

Characters

In Java, the char data type is utilized for storing individual characters, requiring them to be enclosed within single quotes, such as ‘A’ or ‘c’.

Example

char myGrade = 'B';
System.out.println(myGrade);
Alternatively, familiarity with ASCII values allows you to utilize them for displaying specific characters.

Example

char myVar1 = 65, myVar2 = 66, myVar3 = 67;
System.out.println(myVar1);
System.out.println(myVar2);
System.out.println(myVar3);

Hint: Our ASCII Table Reference provides a comprehensive list of all ASCII values.

Strings

The String data type is employed to store a sequence of characters, commonly referred to as text. String values are required to be enclosed within double quote.s

Example

String greeting = "Hello World";
System.out.println(greeting);
 

The widespread use and integration of the String type in Java has earned it the moniker “the special ninth type”.

In Java, a String is classified as a non-primitive data type as it references an object, offering methods for various string operations. If the term “object” is unfamiliar, fret not; we’ll delve deeper into strings and objects in upcoming chapters.