SlideShare a Scribd company logo
Datatypes
Datatypes
Data Type Default Value Default size
boolean false 1 bit
char 'u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte
Datatypes
Type Size in Bytes Range
byte 1 byte -128 to 127
short 2 bytes -32,768 to 32,767
int 4 bytes -2,147,483,648 to 2,147,483, 647
long 8 bytes -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
float 4 bytes Approximately ±3.40282347E+38F
(6-7 significant decimal digits)
Java implements IEEE 754 standard
double 8 bytes approximately ±1.79769313486231570E+308
(15 significant decimal digits)
char 2 byte 0 to 65,536 (unsigned)
boolean not precisely
defined*
true or false
int a;
1000
10
a
Variable Declaration:
Variable Initialization: a = 10;
int:
4 bytes
Can take both positive & negative integers
Datatypes
float b;
2000
10.456f
b
Variable Declaration:
Variable Initialization: b = 10.456f;
float:
4 bytes
Can take both positive & negative integers
Datatypes
float:
4 bytes
Precision 6 decimal places
Can take both positive &
negative integers
double:
8 bytes
Precision 15 decimal places
Can take both positive &
negative integers
Float vs Double
char a = ‘s’ // alphabets
char a = ‘?’ // special symbols
char a = ‘3’ // numeric
Datatypes
char :
2 bytes
S, ? and 3 - anything in single quotes is stored as
an character
 Byte -> Short -> Int -> Float -> Double
 Byte -> short -> int -> long
Example:
int a = 10;
float = a + 10;
Type Conversion(Implicit conversion)
Type Conversion(Explicit conversion
Double -> Float -> Long -> Int -> Short -> Byte
Example:
double d = 10;
int a = d + 10;
Error:
How will you solve?
Type Conversion(Explicit conversion)
int -> char
Example:
char ch = ‘a’;
ch = ch - 32;
Error:
How will you solve?
Type Conversion(Explicit conversion
Double -> Float -> Long -> Int -> Short -> Byte
Example:
double d = 10;
int a = d + 10;
 Not possible by the compiler to convert automatically.
 Down conversion is not possible.
 Programmer has to do conversion code in program.
Type Conversion(Explicit conversion
Double -> Float -> Long -> Int -> Short -> Byte
Example:
double d = 10;
int a = d + 10;
Syntax for conversion :
target_variable =(target_datatype)source_variable
int a=( int ) d +10
Variables
Variable is a container which is used to store some form of values
Variable declaration:
Data_type variable_name
E.g: int sum; float salary; char ch;
• NUMBER
• _num
• 93num
• num93
• first.name
• first_name
• last nam
• nUMBER
• mid.name
• 4321
Valid Variable names
int num;
int NUM;
int Num ;
num, Num, NUM - all three are
different variable names.
Rules:
1. Lower case
2. Upper case
3. Lower and Upper case
C Language is case sensitive
Variable name:
Variables
int _num;
int num_;
int Num_ber ;
int Num.ber ;
int Num ber ;
1. Underscore can be placed
anywhere
2. Except Underscore no other special
characters are allowed
(like dot, white space, etc.,)
Variables
Rules:
Variable name:
int 9num;
int num9;
int Num_7_is ;
int float;
1. First character should be
alphabet or underscore
2. Digits 0 – 9 are allowed
3. Variable name should not be a
keyword
Variables
Rules:
Variable name:
int number=‘A’;
int number=“A”;
int number=2.4 ;
int number=(int)2.4;
Variables
Output:
Variable name:
int number=(int)2.5;
65
Compiler error
Compiler error
2
2
Explanation
Assigning character will store ASCII
value of char to int
String is higher order dataytype than int
Float is higher order datatype than int
Expliict conversion + truncation
happens
Expliict conversion + truncation
happens
THANK YOU

More Related Content

Similar to Datatypes & variables in java

Datatypes
DatatypesDatatypes
Datatypes
Ram Sandeep
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptx
joachimbenedicttulau
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
jyoti_lakhani
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
Walepak Ubi
 
C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3
Rumman Ansari
 
Chapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements iiChapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements ii
allyn joy calcaben
 
A Closer Look at Data Types, Variables and Expressions
A Closer Look at Data Types, Variables and ExpressionsA Closer Look at Data Types, Variables and Expressions
A Closer Look at Data Types, Variables and Expressions
Inan Mashrur
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
StephenOczon1
 
Datatypes
DatatypesDatatypes
Datatypes
ZTE Nepal
 
Lesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptxLesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
sunila tharagaturi
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
Jaya Kumari
 
Data types
Data typesData types
Data types
SandhuSaab12
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
FatimaZafar68
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by Faixan
ٖFaiXy :)
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 

Similar to Datatypes & variables in java (20)

Datatypes
DatatypesDatatypes
Datatypes
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptx
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 
C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3
 
Chapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements iiChapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements ii
 
A Closer Look at Data Types, Variables and Expressions
A Closer Look at Data Types, Variables and ExpressionsA Closer Look at Data Types, Variables and Expressions
A Closer Look at Data Types, Variables and Expressions
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
 
Datatypes
DatatypesDatatypes
Datatypes
 
Lesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptxLesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptx
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Data types
Data typesData types
Data types
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by Faixan
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 

Recently uploaded

Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 

Recently uploaded (20)

Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 

Datatypes & variables in java

  • 1.
  • 3. Datatypes Data Type Default Value Default size boolean false 1 bit char 'u0000' 2 byte byte 0 1 byte short 0 2 byte int 0 4 byte long 0L 8 byte float 0.0f 4 byte double 0.0d 8 byte
  • 4. Datatypes Type Size in Bytes Range byte 1 byte -128 to 127 short 2 bytes -32,768 to 32,767 int 4 bytes -2,147,483,648 to 2,147,483, 647 long 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 float 4 bytes Approximately ±3.40282347E+38F (6-7 significant decimal digits) Java implements IEEE 754 standard double 8 bytes approximately ±1.79769313486231570E+308 (15 significant decimal digits) char 2 byte 0 to 65,536 (unsigned) boolean not precisely defined* true or false
  • 5. int a; 1000 10 a Variable Declaration: Variable Initialization: a = 10; int: 4 bytes Can take both positive & negative integers Datatypes
  • 6. float b; 2000 10.456f b Variable Declaration: Variable Initialization: b = 10.456f; float: 4 bytes Can take both positive & negative integers Datatypes
  • 7. float: 4 bytes Precision 6 decimal places Can take both positive & negative integers double: 8 bytes Precision 15 decimal places Can take both positive & negative integers Float vs Double
  • 8. char a = ‘s’ // alphabets char a = ‘?’ // special symbols char a = ‘3’ // numeric Datatypes char : 2 bytes S, ? and 3 - anything in single quotes is stored as an character
  • 9.
  • 10.  Byte -> Short -> Int -> Float -> Double  Byte -> short -> int -> long Example: int a = 10; float = a + 10; Type Conversion(Implicit conversion)
  • 11. Type Conversion(Explicit conversion Double -> Float -> Long -> Int -> Short -> Byte Example: double d = 10; int a = d + 10; Error: How will you solve?
  • 12. Type Conversion(Explicit conversion) int -> char Example: char ch = ‘a’; ch = ch - 32; Error: How will you solve?
  • 13. Type Conversion(Explicit conversion Double -> Float -> Long -> Int -> Short -> Byte Example: double d = 10; int a = d + 10;  Not possible by the compiler to convert automatically.  Down conversion is not possible.  Programmer has to do conversion code in program.
  • 14. Type Conversion(Explicit conversion Double -> Float -> Long -> Int -> Short -> Byte Example: double d = 10; int a = d + 10; Syntax for conversion : target_variable =(target_datatype)source_variable int a=( int ) d +10
  • 15. Variables Variable is a container which is used to store some form of values Variable declaration: Data_type variable_name E.g: int sum; float salary; char ch;
  • 16. • NUMBER • _num • 93num • num93 • first.name • first_name • last nam • nUMBER • mid.name • 4321 Valid Variable names
  • 17. int num; int NUM; int Num ; num, Num, NUM - all three are different variable names. Rules: 1. Lower case 2. Upper case 3. Lower and Upper case C Language is case sensitive Variable name: Variables
  • 18. int _num; int num_; int Num_ber ; int Num.ber ; int Num ber ; 1. Underscore can be placed anywhere 2. Except Underscore no other special characters are allowed (like dot, white space, etc.,) Variables Rules: Variable name:
  • 19. int 9num; int num9; int Num_7_is ; int float; 1. First character should be alphabet or underscore 2. Digits 0 – 9 are allowed 3. Variable name should not be a keyword Variables Rules: Variable name:
  • 20. int number=‘A’; int number=“A”; int number=2.4 ; int number=(int)2.4; Variables Output: Variable name: int number=(int)2.5; 65 Compiler error Compiler error 2 2 Explanation Assigning character will store ASCII value of char to int String is higher order dataytype than int Float is higher order datatype than int Expliict conversion + truncation happens Expliict conversion + truncation happens

Editor's Notes

  1. 1st slide (Mandatory)
  2. Title + Image + Text
  3. Title + Image + Text
  4. Title + Image + Text
  5. Float data type in Java stores a decimal value with 6-7 total digits of precision. So for example 12.12345 can be saved as a float, but 12.123456789 cannot be saved as a float. When representing a float data type in Java we should append the letter f to the end of the data type, otherwise, it will save as double. Double data type stores decimal values with 15-16 digits of precision. The default value is 0.0d, this means that if you do not append f or d to the end of the decimal, the value will be stored as a double in Java.
  6. Thank you slide