SlideShare a Scribd company logo
Literals:
A constant value which can be assigned to the variable is called Literals.
1ASHUTOSH TRIVEDI
 For the Integral data types (byte, short, int, long) the following are various
ways to specify Literal value.
Decimal Literals :-
 Allowed digit are 0 to 9
Example: int x=10;
Integral Literals:
2ASHUTOSH TRIVEDI
2) Octal Literals :-
 Allowed digit are 0 to 7
 Literal value should be prefixed with 0 [zero]
Example: int x= 010;
3) Hexadecimal Literals :-
 Allowed digit are 0 to 9 , a to f [OR] A to F
 For the extra digits we can use both upper case & lower case this is one of very few places where java is not case
sensitive.
 Literal value should be prefixed with 0x [OR] 0X
Example: int x= 0x10;
[OR]
Int x=0X10;
 These are the only possible ways to specify integral Literal.
3ASHUTOSH TRIVEDI
Example:
class TestLiterals
{
public static void main(String args[])
{
int x=10;
int y=010;
int z=0X10;
System.out.println(x+"---"+y+"-----"+z);
}
}
Output:- (10)8 = (?)10
0*80 +1*81 =8
(10)16 = (?)10
0*160 +1*161 =16
10---8-----16 4ASHUTOSH TRIVEDI
Que-) which of the following declarations are valid.
1.int x=10;
2.int x=066;
3.int x=0786; CE: integer number too large: 0786
4.int x=0XFACE; // 64206
5.int x=0xBea; // 3050
5ASHUTOSH TRIVEDI
By default every integral Literal is of int type but we can specify explicitly as long type by
suffixing with l or L
Example;
1)int i=10; // Valid
2) int i=10l; CE: possible loss of precision
int i=10l;
^ required: int
found: long
1)long l=10l; // Valid
2)long l=10; // Valid
6ASHUTOSH TRIVEDI
 There is no way to specify integral Literal is of byte & short types explicitly.
 If we are assigning integral Literal to the byte variable & that integral literal is within the
range of byte then it treats as byte literal automatically. Similarly short Literal also.
byte b=10; Valid
byte b=130;
CE: possible loss of precision
int i=10l;
^ required: byte
found: int
7ASHUTOSH TRIVEDI
By default the decimal point values represent double type & hence
we cannot assign directly to float variable.
 So if we want to assign the floating point values to the variables
we must attach the suffix F or f to the number. If we are not providing
the number we will get compilation error possible loss of precision.
Floating point literal & double literal:-
8ASHUTOSH TRIVEDI
 Example-
float f=123.456;
CE: possible loss of precision
Found: double
Required: float
float f=123.456f; // valid
double d=123.456; //valid
9ASHUTOSH TRIVEDI
 We can specify floating point literal explicitly as double type by suffixing
with d or D.
Ex- double d=123.456D; // valid
float f=123.4567d; // Invalid
CE: possible loss of precision
Found: double
Required: float
10ASHUTOSH TRIVEDI
 We can specify floating point literal only in decimal form & we can’t specify
in octal & hexadecimal form.
Example:
double d=123.456;(valid)
double d=0123.456;(valid) //it is treated as decimal value but not octal
double d=0x123.456; //C. E: malformed floating point literal(invalid)
11ASHUTOSH TRIVEDI
Which of the following floating point declarations are valid?
float f=123.456; //C.E:possible loss of precision(invalid)
float f=123.456D; //C.E:possible loss of precision(invalid)
double d=0x123.456; //C.E:malformed floating point literal(invalid)
double d=0xFace; (valid)
double d=0xBeef; (valid)
12ASHUTOSH TRIVEDI
We can assign integral literal directly to the floating point data types and that integral literal can
be specified in decimal, octal and Hexa decimal form also.
Example:
double d=0xBeef;
System.out.println(d);//48879.0
But we can't assign floating point literal directly to the integral types.
Example:
int x=10.0;//C.E:possible loss of precision
13ASHUTOSH TRIVEDI
A char literal can be represented as single character within single quotes.
Example:
char ch='a';(valid)
char ch=a;//C.E:cannot find symbol(invalid)
char ch="a";//C.E:incompatible types(invalid)
char ch='ab';//C.E:unclosed character literal(invalid)
Char literals:-
14ASHUTOSH TRIVEDI
 We can specify a char literal as integral literal which represents Unicode of that
character.
 We can specify that integral literal either in decimal or octal or hexadecimal
form but allowed values range is 0 to 65535.
 Example:
char ch=97; (valid)
char ch=0xFace; (valid)
System.out.println(ch); //?
char ch=65536; //C.E: possible loss of precision(invalid)
15ASHUTOSH TRIVEDI
 The only allowed values for the boolean type are true (or) false where
case is important. i.e., lower case
Example:
boolean b=true; (valid)
boolean b=0; //C.E:incompatible types(invalid)
boolean b=True; //C.E:cannot find symbol(invalid)
boolean b="true"; //C.E:incompatible types(invalid)
Boolean literal:-
16ASHUTOSH TRIVEDI
17ASHUTOSH TRIVEDI
The following 2 are enhancements
1. Binary Literals
2. Usage of '_' in Numeric Literals
• Binary Literals:
 For the integral data types until 1.6v we can specified literal value in the following
ways
1. Decimal
2. Octal
3. Hexa decimal
1.7 Version enhancements with respect to Literals:
18ASHUTOSH TRIVEDI
 But from 1.7v onwards we can have specified literal value in binary form also.
 The allowed digits are 0 to 1.
 Literal value should be prefixed with Ob or OB
int x = 0b111;
System.out.println(x); // 7
19ASHUTOSH TRIVEDI
Usage of _ symbol in numeric literals:
 From 1.7v onwards we can use underscore (_) symbol in numeric literals.
double d = 123456.789; //valid
double d = 1_23_456.7_8_9; //valid
double d = 123_456.7_8_9; //valid
20ASHUTOSH TRIVEDI
The main advantage of this approach is readability of the code will be improved at the time of
compilation ' _ ' symbols will be removed automatically, hence after compilation the above
lines will become double d = 123456.789
We can use more than one underscore symbol also between the digits.
Ex: double d = 1_23_ _456.789;
We should use underscore symbol only between the digits.
double d=_1_23_456.7_8_9; //invalid
double d=1_23_456.7_8_9_; //invalid
double d=1_23_456_.7_8_9; //invalid
21ASHUTOSH TRIVEDI

More Related Content

What's hot

sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Exception handling
Exception handlingException handling
Exception handling
Pranali Chaudhari
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
Md. Tanvir Hossain
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Vineeta Garg
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
MD Sulaiman
 
User defined functions
User defined functionsUser defined functions
User defined functions
Rokonuzzaman Rony
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Type casting
Type castingType casting
Type casting
simarsimmygrewal
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Paumil Patel
 
Programming in c
Programming in cProgramming in c
Programming in c
indra Kishor
 

What's hot (20)

sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Exception handling
Exception handlingException handling
Exception handling
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Java keywords
Java keywordsJava keywords
Java keywords
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
class and objects
class and objectsclass and objects
class and objects
 
Type casting
Type castingType casting
Type casting
 
10. switch case
10. switch case10. switch case
10. switch case
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Programming in c
Programming in cProgramming in c
Programming in c
 

Viewers also liked

JDK,JRE,JVM
JDK,JRE,JVMJDK,JRE,JVM
JDK,JRE,JVM
Cognizant
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
kamal kotecha
 
Aditivos para Concreto
Aditivos para ConcretoAditivos para Concreto
Aditivos para Concreto
JOHNNY JARA RAMOS
 
PandJ Final Essay .
PandJ Final Essay .PandJ Final Essay .
PandJ Final Essay .Cori Muller
 
Work,energyandpower
Work,energyandpowerWork,energyandpower
Work,energyandpower
Conferat Conferat
 
Continues delivery - Introduction
Continues delivery - IntroductionContinues delivery - Introduction
Continues delivery - Introduction
Erez Attar
 
Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...
Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...
Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...Mehdi Kordi
 
Advertising Ideas For The Betterment Of Business Field
Advertising Ideas For The Betterment Of Business FieldAdvertising Ideas For The Betterment Of Business Field
Advertising Ideas For The Betterment Of Business Field
craigmatthewfeigin
 
Classification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj SenClassification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj Sen
Arvind Surve
 
Green Fish Proposal V6 DC
Green Fish Proposal V6 DCGreen Fish Proposal V6 DC
Green Fish Proposal V6 DCDavid Cooper
 
Χαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων Ρόδου
Χαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων ΡόδουΧαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων Ρόδου
Χαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων Ρόδου
ΚΠΕ Πεταλούδων Ρόδου
 
Ejercicios de Cinematica Para Pre-Ingenierias
Ejercicios de Cinematica Para Pre-IngenieriasEjercicios de Cinematica Para Pre-Ingenierias
Ejercicios de Cinematica Para Pre-Ingenierias
JOHNNY JARA RAMOS
 
Всероссийская акция "Стоп ВИЧ/СПИД"
Всероссийская акция "Стоп ВИЧ/СПИД"Всероссийская акция "Стоп ВИЧ/СПИД"
Всероссийская акция "Стоп ВИЧ/СПИД"
school135
 
AONI Condoms - THINNEST latex condoms in the world!
AONI Condoms - THINNEST latex condoms in the world! AONI Condoms - THINNEST latex condoms in the world!
AONI Condoms - THINNEST latex condoms in the world!
aonicondoms
 
Manual
ManualManual
фото навчальна практика
фото навчальна практикафото навчальна практика
фото навчальна практика
artischenkonatalia
 

Viewers also liked (17)

Java literals
Java literalsJava literals
Java literals
 
JDK,JRE,JVM
JDK,JRE,JVMJDK,JRE,JVM
JDK,JRE,JVM
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Aditivos para Concreto
Aditivos para ConcretoAditivos para Concreto
Aditivos para Concreto
 
PandJ Final Essay .
PandJ Final Essay .PandJ Final Essay .
PandJ Final Essay .
 
Work,energyandpower
Work,energyandpowerWork,energyandpower
Work,energyandpower
 
Continues delivery - Introduction
Continues delivery - IntroductionContinues delivery - Introduction
Continues delivery - Introduction
 
Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...
Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...
Parker Simpson & Kordi - 2016 - Comparison of Critical Power and wprime deriv...
 
Advertising Ideas For The Betterment Of Business Field
Advertising Ideas For The Betterment Of Business FieldAdvertising Ideas For The Betterment Of Business Field
Advertising Ideas For The Betterment Of Business Field
 
Classification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj SenClassification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj Sen
 
Green Fish Proposal V6 DC
Green Fish Proposal V6 DCGreen Fish Proposal V6 DC
Green Fish Proposal V6 DC
 
Χαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων Ρόδου
Χαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων ΡόδουΧαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων Ρόδου
Χαράλαμπος Συργιάννης Τα ΚΠΕ και ο ρόλος τους στην ΠΕ Το ΚΠΕ Πεταλούδων Ρόδου
 
Ejercicios de Cinematica Para Pre-Ingenierias
Ejercicios de Cinematica Para Pre-IngenieriasEjercicios de Cinematica Para Pre-Ingenierias
Ejercicios de Cinematica Para Pre-Ingenierias
 
Всероссийская акция "Стоп ВИЧ/СПИД"
Всероссийская акция "Стоп ВИЧ/СПИД"Всероссийская акция "Стоп ВИЧ/СПИД"
Всероссийская акция "Стоп ВИЧ/СПИД"
 
AONI Condoms - THINNEST latex condoms in the world!
AONI Condoms - THINNEST latex condoms in the world! AONI Condoms - THINNEST latex condoms in the world!
AONI Condoms - THINNEST latex condoms in the world!
 
Manual
ManualManual
Manual
 
фото навчальна практика
фото навчальна практикафото навчальна практика
фото навчальна практика
 

Similar to JAVA Literals

CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
Hossein Zahed
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 
representing Data in C.pptx
representing Data in C.pptxrepresenting Data in C.pptx
representing Data in C.pptx
SherryAnnCervantesNa
 
Programming in Arduino (Part 1)
Programming in Arduino (Part 1)Programming in Arduino (Part 1)
Programming in Arduino (Part 1)
Niket Chandrawanshi
 
C tutorial
C tutorialC tutorial
C tutorial
Anurag Sukhija
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
Tanishq Soni
 
[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes
Muhammad Hammad Waseem
 
Constants
ConstantsConstants
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
guptkashish
 
Arrays cpu2
Arrays cpu2Arrays cpu2
Arrays cpu2
Krunal Koladiya
 
C operators
C operatorsC operators
C operators
srmohan06
 
c_tutorial_2.ppt
c_tutorial_2.pptc_tutorial_2.ppt
c_tutorial_2.ppt
gitesh_nagar
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
Kuntal Bhowmick
 

Similar to JAVA Literals (20)

C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
2 1 data
2 1  data2 1  data
2 1 data
 
Data types
Data typesData types
Data types
 
representing Data in C.pptx
representing Data in C.pptxrepresenting Data in C.pptx
representing Data in C.pptx
 
Data types
Data typesData types
Data types
 
Programming in Arduino (Part 1)
Programming in Arduino (Part 1)Programming in Arduino (Part 1)
Programming in Arduino (Part 1)
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
C tutorial
C tutorialC tutorial
C tutorial
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Variable declaration
Variable declarationVariable declaration
Variable declaration
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
 
[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes
 
Constants
ConstantsConstants
Constants
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
Arrays cpu2
Arrays cpu2Arrays cpu2
Arrays cpu2
 
C operators
C operatorsC operators
C operators
 
c_tutorial_2.ppt
c_tutorial_2.pptc_tutorial_2.ppt
c_tutorial_2.ppt
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
 

Recently uploaded

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 

Recently uploaded (20)

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 

JAVA Literals

  • 1. Literals: A constant value which can be assigned to the variable is called Literals. 1ASHUTOSH TRIVEDI
  • 2.  For the Integral data types (byte, short, int, long) the following are various ways to specify Literal value. Decimal Literals :-  Allowed digit are 0 to 9 Example: int x=10; Integral Literals: 2ASHUTOSH TRIVEDI
  • 3. 2) Octal Literals :-  Allowed digit are 0 to 7  Literal value should be prefixed with 0 [zero] Example: int x= 010; 3) Hexadecimal Literals :-  Allowed digit are 0 to 9 , a to f [OR] A to F  For the extra digits we can use both upper case & lower case this is one of very few places where java is not case sensitive.  Literal value should be prefixed with 0x [OR] 0X Example: int x= 0x10; [OR] Int x=0X10;  These are the only possible ways to specify integral Literal. 3ASHUTOSH TRIVEDI
  • 4. Example: class TestLiterals { public static void main(String args[]) { int x=10; int y=010; int z=0X10; System.out.println(x+"---"+y+"-----"+z); } } Output:- (10)8 = (?)10 0*80 +1*81 =8 (10)16 = (?)10 0*160 +1*161 =16 10---8-----16 4ASHUTOSH TRIVEDI
  • 5. Que-) which of the following declarations are valid. 1.int x=10; 2.int x=066; 3.int x=0786; CE: integer number too large: 0786 4.int x=0XFACE; // 64206 5.int x=0xBea; // 3050 5ASHUTOSH TRIVEDI
  • 6. By default every integral Literal is of int type but we can specify explicitly as long type by suffixing with l or L Example; 1)int i=10; // Valid 2) int i=10l; CE: possible loss of precision int i=10l; ^ required: int found: long 1)long l=10l; // Valid 2)long l=10; // Valid 6ASHUTOSH TRIVEDI
  • 7.  There is no way to specify integral Literal is of byte & short types explicitly.  If we are assigning integral Literal to the byte variable & that integral literal is within the range of byte then it treats as byte literal automatically. Similarly short Literal also. byte b=10; Valid byte b=130; CE: possible loss of precision int i=10l; ^ required: byte found: int 7ASHUTOSH TRIVEDI
  • 8. By default the decimal point values represent double type & hence we cannot assign directly to float variable.  So if we want to assign the floating point values to the variables we must attach the suffix F or f to the number. If we are not providing the number we will get compilation error possible loss of precision. Floating point literal & double literal:- 8ASHUTOSH TRIVEDI
  • 9.  Example- float f=123.456; CE: possible loss of precision Found: double Required: float float f=123.456f; // valid double d=123.456; //valid 9ASHUTOSH TRIVEDI
  • 10.  We can specify floating point literal explicitly as double type by suffixing with d or D. Ex- double d=123.456D; // valid float f=123.4567d; // Invalid CE: possible loss of precision Found: double Required: float 10ASHUTOSH TRIVEDI
  • 11.  We can specify floating point literal only in decimal form & we can’t specify in octal & hexadecimal form. Example: double d=123.456;(valid) double d=0123.456;(valid) //it is treated as decimal value but not octal double d=0x123.456; //C. E: malformed floating point literal(invalid) 11ASHUTOSH TRIVEDI
  • 12. Which of the following floating point declarations are valid? float f=123.456; //C.E:possible loss of precision(invalid) float f=123.456D; //C.E:possible loss of precision(invalid) double d=0x123.456; //C.E:malformed floating point literal(invalid) double d=0xFace; (valid) double d=0xBeef; (valid) 12ASHUTOSH TRIVEDI
  • 13. We can assign integral literal directly to the floating point data types and that integral literal can be specified in decimal, octal and Hexa decimal form also. Example: double d=0xBeef; System.out.println(d);//48879.0 But we can't assign floating point literal directly to the integral types. Example: int x=10.0;//C.E:possible loss of precision 13ASHUTOSH TRIVEDI
  • 14. A char literal can be represented as single character within single quotes. Example: char ch='a';(valid) char ch=a;//C.E:cannot find symbol(invalid) char ch="a";//C.E:incompatible types(invalid) char ch='ab';//C.E:unclosed character literal(invalid) Char literals:- 14ASHUTOSH TRIVEDI
  • 15.  We can specify a char literal as integral literal which represents Unicode of that character.  We can specify that integral literal either in decimal or octal or hexadecimal form but allowed values range is 0 to 65535.  Example: char ch=97; (valid) char ch=0xFace; (valid) System.out.println(ch); //? char ch=65536; //C.E: possible loss of precision(invalid) 15ASHUTOSH TRIVEDI
  • 16.  The only allowed values for the boolean type are true (or) false where case is important. i.e., lower case Example: boolean b=true; (valid) boolean b=0; //C.E:incompatible types(invalid) boolean b=True; //C.E:cannot find symbol(invalid) boolean b="true"; //C.E:incompatible types(invalid) Boolean literal:- 16ASHUTOSH TRIVEDI
  • 18. The following 2 are enhancements 1. Binary Literals 2. Usage of '_' in Numeric Literals • Binary Literals:  For the integral data types until 1.6v we can specified literal value in the following ways 1. Decimal 2. Octal 3. Hexa decimal 1.7 Version enhancements with respect to Literals: 18ASHUTOSH TRIVEDI
  • 19.  But from 1.7v onwards we can have specified literal value in binary form also.  The allowed digits are 0 to 1.  Literal value should be prefixed with Ob or OB int x = 0b111; System.out.println(x); // 7 19ASHUTOSH TRIVEDI
  • 20. Usage of _ symbol in numeric literals:  From 1.7v onwards we can use underscore (_) symbol in numeric literals. double d = 123456.789; //valid double d = 1_23_456.7_8_9; //valid double d = 123_456.7_8_9; //valid 20ASHUTOSH TRIVEDI
  • 21. The main advantage of this approach is readability of the code will be improved at the time of compilation ' _ ' symbols will be removed automatically, hence after compilation the above lines will become double d = 123456.789 We can use more than one underscore symbol also between the digits. Ex: double d = 1_23_ _456.789; We should use underscore symbol only between the digits. double d=_1_23_456.7_8_9; //invalid double d=1_23_456.7_8_9_; //invalid double d=1_23_456_.7_8_9; //invalid 21ASHUTOSH TRIVEDI