SlideShare ist ein Scribd-Unternehmen logo
1 von 21
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

Weitere ähnliche Inhalte

Was ist angesagt?

class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++PRINCE KUMAR
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java Ravi_Kant_Sahu
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Sandeep Rawat
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)Sujit Majety
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
Array in Java
Array in JavaArray in Java
Array in JavaAli shah
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in cMuthuganesh S
 
Operator Overloading & Function Overloading
Operator Overloading & Function OverloadingOperator Overloading & Function Overloading
Operator Overloading & Function OverloadingMeghaj Mallick
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statementsİbrahim Kürce
 
Primitive data types in java
Primitive data types in javaPrimitive data types in java
Primitive data types in javaUmamaheshwariv1
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variablessasi saseenthiran
 

Was ist angesagt? (20)

class and objects
class and objectsclass and objects
class and objects
 
Basic of Java
Basic of JavaBasic of Java
Basic of Java
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
polymorphism
polymorphism polymorphism
polymorphism
 
Java
JavaJava
Java
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Java notes
Java notesJava notes
Java notes
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Operator Overloading & Function Overloading
Operator Overloading & Function OverloadingOperator Overloading & Function Overloading
Operator Overloading & Function Overloading
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Primitive data types in java
Primitive data types in javaPrimitive data types in java
Primitive data types in java
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 

Andere mochten auch

Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
PandJ Final Essay .
PandJ Final Essay .PandJ Final Essay .
PandJ Final Essay .Cori Muller
 
Continues delivery - Introduction
Continues delivery - IntroductionContinues delivery - Introduction
Continues delivery - IntroductionErez 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 Fieldcraigmatthewfeigin
 
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 SenArvind 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-IngenieriasJOHNNY 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
 
фото навчальна практика
фото навчальна практикафото навчальна практика
фото навчальна практикаartischenkonatalia
 

Andere mochten auch (16)

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
 
фото навчальна практика
фото навчальна практикафото навчальна практика
фото навчальна практика
 

Ähnlich wie JAVA Literals

Ähnlich wie 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++
 

Kürzlich hochgeladen

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 

Kürzlich hochgeladen (20)

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

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