SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVAAnkita Totala
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++Vraj Patel
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
 
Data types in C language
Data types in C languageData types in C language
Data types in C languagekashyap399
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20myrajendra
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonPriyankaC44
 

Tendances (20)

Files in java
Files in javaFiles in java
Files in java
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Python functions
Python functionsPython functions
Python functions
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
JAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdfJAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdf
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
 

En vedette

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
 

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

Similaire à JAVA Literals

Similaire à 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++
 

Dernier

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 

Dernier (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 

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