You are on page 1of 11

Literals and

Data Types
Java Rice Group 1.0
In Java, literals and data types are two
interconnected concepts that play a
crucial role in building programs.
These are two fundamental concepts in
any programming language:
LITERALS
Literals are fixed values represented
directly in your code. They cannot be
changed without reassignment.

In Java, literals are artificial


representations of character,
numeric, string, and boolean data.
They are a way for certain values to
be expressed within a program.
These are program-direct constant
values that can now be set to a
variable.
TYPES OF LITERALS IN JAVA
1. Integral Literals - In computer programming, integral literals are constant values that represent
integers in various number systems, such as decimal, binary, octal, and hexadecimal. These
literals assign fixed integer values directly to variables or expressions in code.
2. Floating-Point Literals - Floating-point literals are literal in programming that represent real
numbers (numbers with a decimal point) using the floating-point notation. These literals are
commonly used to represent numbers that can have fractional parts.
3. Char Literals - Character (Char) literals have the type char and are an unsigned integer
primitive type. They are constant value character expressions in the Java program.
4. String Literals - A sequence of (zero or more including Unicode characters) characters within
double quotes is referred to as string literals.
5. Boolean Literals - Boolean literals allow only two values and thus are divided into two
literals: TRUE & FALSE
6. Null Literals - Null literal is a particular literal in Java representing a null value. This value
refers to no object.
DATA
TYPES
Data types define the nature and
limitations of data that can be stored in
a variable or literal. They dictate how
much space to allocate in memory and
the operations applicable to the data.

Data types are divided into two groups:


• Primitive data types – includes byte,
short, int, long, float, double, boolean
and char
• Non-primitive data types - such as
String, Arrays and Classes
Examples
Literals Data Types
int integerLiteral = 42; int integerVariable = 42; // Integer data type
double floatingPointLiteral = 3.14; double doubleVariable = 3.14; // Double (floating-point) data type
char charLiteral = 'A'; char charVariable = 'A'; // Character data type
String stringLiteral = "Hello, Java!"; String stringVariable = "Hello"; // String data type
boolean booleanLiteral = true; boolean booleanVariable = true; // Boolean data type
References
• https://bard.google.com


https://www.tutorialspoint.com/What-is-the-difference-between-data-types-and-literals-in-Java#:~:text=Data
%20types%20are%20those%20which,the%20code%20without%20any%20computation
.

• https://techvidvan.com/tutorials/literals-in-java/

• https://chat.openai.com

• https://www.upgrad.com/blog/types-of-literals-in-java/
Thanks
!
Members
Jan Patrick Nocillado
Paolo Bartolay
Sherwen Benocas
Czar Andrei Valdecino
Lorie Anne Balingbing

You might also like