What Are Literals In Java? - Tutorialspoint
Maybe your like
- Home
- Whiteboard
- Online Compilers
- Practice
- Articles
- AI Assistant
- Jobs
- Tools
- Corporate Training
- Courses
- Certifications
- Switch theme
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
A literal is a source code representation of a fixed value. They are represented directly in the code without any computation.
Literals can be assigned to any primitive type variable.
Example
byte a = 68; char a = 'A'
byte, int, long, and short can be expressed in decimal(base 10), hexadecimal(base 16) or octal(base 8) number systems as well.
Prefix 0 is used to indicate octal, and prefix 0x indicates hexadecimal when using these number systems for literals. For example −
int decimal = 100; int octal = 0144; int hexa = 0x64;String literals in Java are specified like they are in most other languages by enclosing a sequence of characters between a pair of double quotes. Examples of string literals are −
Example
"Hello World" "two\nlines" ""This is in quotes""String and char types of literals can contain any Unicode characters. For example −
char a = '\u0001'; String a = "\u0001";
Johar Ali Updated on: 2019-07-30T22:30:20+05:30 2K+ Views
Kickstart Your Career
Get certified by completing the course
Get StartedTag » What Is A Literal In Java
-
Literals In Java: Types Of Literals In Java [With Examples] - UpGrad
-
Literals In Java - GeeksforGeeks
-
Literals In Java - Javatpoint
-
Java Variables And Literals (With Examples) - Programiz
-
Literals In Java - Integral, Floating-Point, Char, String, Boolean
-
Literals - Wikibooks, Open Books For An Open World
-
What Is A Literal In Java - Linux Hint
-
Java Literals - Concept Every Java Programmer Must Know
-
Literals In Java
-
What Are Literals In Java: The Complete Guide - AppDividend
-
What Are Literals In Java? - Quora
-
Literals In Java - YouTube
-
Literal Expressions - The Java EE 6 Tutorial
-
Java Literals - What Is Literal In Java? Type Of Literal - Computer Notes