- JAVA OVERVIEW
- History of Java
- Tools you will need for java
- Java Environment Setup
- Popular Java Editors
- Java Basic Syntax/First-Program
- Java Identifiers
- Java Modifiers
- Java Arrays
- Java Enums
- Java Keywords
- Comments in Java
- Java - Objects and Classes
- Objects in Java
- Classes in Java
- Constructors
- Creating an Object
- Accessing Instance Variables and Methods
- Source file declaration rules
- Java Package
- Simple Case Study
- Basic Data Types
- Primitive Data Types
- Reference Data Types
- Java Literals
- Variable Types
- Local variables
- Instance variables
- Class or static variables
- Java Access Modifiers
- What is OOPS
- Inheritance concept
- Encapsulation
- What is Polymorphism
- Method Overloading
- Method Overriding
- Abstraction in Java
- Abstract class
- Interface in Java
- Method overloading in Java:
- What is Annonymous object?
- Java 8
What is literals in Java?
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.
Literals in Java are a sequence of characters (digits, letters, and other characters) that represent constant values to be stored in variables.
For 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 indicates 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:
"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";
Java language supports few special escape sequences for String and char literals as well.
They are:
Notation Character represented
\b Backspace (0x08)
\s Space (0x20)
\t Tab
\" Double quote
\' Single quote
\\ Backslash
\ddd Octal character (ddd)
\uxxxx Hexadecimal UNICODE character (xxxx)