SlideShare a Scribd company logo
1 of 14
Data types, keywords, identifiers
in java
•What are identifiers in java.
•What are keywords how & why they are used?
•What are data types in java.
4/10/2019 1Jamsher Bhanbhro(F16CS11)
Identifiers
• Names required for java classes, variables, methods
are called identifiers.
• Can be A-Z or a-z or in mixture(Alphabets).
• Currency character($) can be used as identifier.
• _ underscore can be used.
• Keywords cannot be used as identifier.
• Eg: HelloWorld, Jamsher (may be class names).
• A=3; a=5; z=c; x=y, can be the variables.
• Sum, Sub, Div can be methods.
4/10/2019 Jamsher Bhanbhro(F16CS11) 2
Java Keywords
• Keywords are reserved names for java.
• These can’t be used as identifiers, variables name
etc.
• Abstract: used for class
• Boolean: 0 or 1 true or false
• Break: use to break the statement or the condition
• Char: for data type
• Import, class, switch, case, if else, try, this, throw,
void, return, package etc are the java keywords.
4/10/2019 Jamsher Bhanbhro(F16CS11) 3
Data types in java
• When a variable is assigned a memory it is
assigned by its data types.
• A variable store which type of data is known
as data type.
• There are basically two data types available in
java
1. Primitive data type
2. Non Primitive data type/ Reference data type
4/10/2019 Jamsher Bhanbhro(F16CS11) 4
Primitive data type
• Those data types which are already defined in
the java library is known as Primitive data
type.
• These are built-in or predefined data types.
• Java basically supports 8 predefined data
types.
• Which are byte, short, long, float, double,
Boolean, char, int.
4/10/2019 Jamsher Bhanbhro(F16CS11) 5
1. Integer Data type
• Integer is denoted by int and stores the integer values.
• Int data type is a 32-bit signed two's complement
integer
• Minimum value is - 2,147,483,648 (-2^31)
• Maximum value is 2,147,483,647(inclusive) (2^31 -1)
• Integer is generally used as the default data type for
integral values unless there is a concern about memory.
• The default value is 0
• Example: int a = 11, int b = 41
4/10/2019 Jamsher Bhanbhro(F16CS11) 6
2. Byte
• Byte data type is an 8-bit signed two's
complement integer
• Minimum value is -128 (-2^7).
• Maximum value is 127 (inclusive)(2^7 -1)
• Default value is 0.
• Byte data type is used to save space in large
arrays, mainly in place of integers, since a byte is
four times smaller than an integer
• For Example: byte a=11, b=41;
4/10/2019 Jamsher Bhanbhro(F16CS11) 7
3. Float
• Float data-type is a single-precision 32-bit
IEEE 754 floating point.
• Float is mainly used to save memory in large
arrays of floating point numbers.
• Default value is 0.0f.
• Float data-type is never used for precise
values such as currency.
• Example: float f1 = 234.5f(f stands for float)
4/10/2019 Jamsher Bhanbhro(F16CS11) 8
4. Short
• Short datatype is a 16-bit signed two's complement
integer
• Minimum value is -32,768 (-2^15)
• Maximum value is 32,767 (inclusive) (2^15 -1)
• Short datatype can also be used to save memory as byte
data type. A short is 2 times smaller than an integer
• Default value is 0
4/10/2019 Jamsher Bhanbhro(F16CS11) 9
5. Long
• Long datatype is a 64-bit signed two's
complement integer
• Minimum value is 9,223,372,036,854,775,808 (-
2^63)
• Maximum value is9,223,372,036,854,775,807
(inclusive) (2^63 -1)
• This type is used when a wider range than int is
needed.
• Default value is 0L(L is used for Long)
• Example: long a = 100000L, long b = -200000L
4/10/2019 Jamsher Bhanbhro(F16CS11) 10
6. Char
• char data-type is a single 16-bit Unicode
character.
• Minimum value is 'u0000' (or 0) .
• Maximum value is 'uffff' (or 65,535 inclusive)
.
• Char data-type is used to store any character
• Example: char letterA =‘J‘;
4/10/2019 Jamsher Bhanbhro(F16CS11) 11
7. Boolean
• Boolean data-type represents one bit of
information.
• There are only two possible values: true and
false.
• This data-type is used for simple flags that
track true/false conditions.
• Default value is false .
• Example: boolean one = true, 0=false;
4/10/2019 Jamsher Bhanbhro(F16CS11) 12
8. Double
• double data-type is a double-precision 64-bit
IEEE 754 floating point.
• This data-type is generally used as the default
data type for decimal values, generally the
default choice.
• Double data-type should never be used for
precise values such as currency.
• Default value is 0.0d(d for double)
4/10/2019 Jamsher Bhanbhro(F16CS11) 13
Reference data-types
• These are not predefined data-types.
• These are created using defined constructors
of the classes.
• They are used to access the objects
• These are the reference variables
• eg: Jamsher ob=new Jamsher();
4/10/2019 Jamsher Bhanbhro(F16CS11) 14

More Related Content

What's hot

What's hot (20)

Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Data types
Data typesData types
Data types
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
 
Data Types
Data TypesData Types
Data Types
 
Data types in Java
Data types in JavaData types in Java
Data types in Java
 
Computer data type and Terminologies
Computer data type and Terminologies Computer data type and Terminologies
Computer data type and Terminologies
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining
 
Data types
Data typesData types
Data types
 
5. variables & data types
5. variables & data types5. variables & data types
5. variables & data types
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 
Ijartes v1-i1-002
Ijartes v1-i1-002Ijartes v1-i1-002
Ijartes v1-i1-002
 
Data types
Data typesData types
Data types
 
Array
ArrayArray
Array
 
DATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netDATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.net
 

Similar to Lect5

01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART IHari Christian
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part iijyoti_lakhani
 
Java Tutorial Lab 2
Java Tutorial Lab 2Java Tutorial Lab 2
Java Tutorial Lab 2Berk Soysal
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypesSoba Arjun
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxlemonchoos
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingEric Chou
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITASIT
 
introduction to python
 introduction to python introduction to python
introduction to pythonJincy Nelson
 
332 ch07
332 ch07332 ch07
332 ch07YaQ10
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)guest58c84c
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)jahanullah
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variableseShikshak
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptxssuserb1a18d
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++NIDA HUSSAIN
 
Lec 1.3 Object Oriented Programming
Lec 1.3 Object Oriented ProgrammingLec 1.3 Object Oriented Programming
Lec 1.3 Object Oriented ProgrammingBadar Waseer
 

Similar to Lect5 (20)

Java session3
Java session3Java session3
Java session3
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
 
Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
 
Variable
VariableVariable
Variable
 
C language basics
C language basicsC language basics
C language basics
 
Data types
Data typesData types
Data types
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
 
Java Tutorial Lab 2
Java Tutorial Lab 2Java Tutorial Lab 2
Java Tutorial Lab 2
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
introduction to python
 introduction to python introduction to python
introduction to python
 
332 ch07
332 ch07332 ch07
332 ch07
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Lec 1.3 Object Oriented Programming
Lec 1.3 Object Oriented ProgrammingLec 1.3 Object Oriented Programming
Lec 1.3 Object Oriented Programming
 

More from Jamsher bhanbhro

Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and InterfacesJamsher bhanbhro
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In  JavaMethod, Constructor, Method Overloading, Method Overriding, Inheritance In  Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In JavaJamsher bhanbhro
 
Regular Expressions in Java.
Regular Expressions in Java.Regular Expressions in Java.
Regular Expressions in Java.Jamsher bhanbhro
 
Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJamsher bhanbhro
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in javaJamsher bhanbhro
 
Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Jamsher bhanbhro
 

More from Jamsher bhanbhro (14)

Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In  JavaMethod, Constructor, Method Overloading, Method Overriding, Inheritance In  Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
 
Regular Expressions in Java.
Regular Expressions in Java.Regular Expressions in Java.
Regular Expressions in Java.
 
Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime Functions
 
Lect10
Lect10Lect10
Lect10
 
Lect9
Lect9Lect9
Lect9
 
Lect8
Lect8Lect8
Lect8
 
Lect7
Lect7Lect7
Lect7
 
Lect6
Lect6Lect6
Lect6
 
Lect4
Lect4Lect4
Lect4
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Caap presentation by me
Caap presentation by meCaap presentation by me
Caap presentation by me
 
Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

Lect5

  • 1. Data types, keywords, identifiers in java •What are identifiers in java. •What are keywords how & why they are used? •What are data types in java. 4/10/2019 1Jamsher Bhanbhro(F16CS11)
  • 2. Identifiers • Names required for java classes, variables, methods are called identifiers. • Can be A-Z or a-z or in mixture(Alphabets). • Currency character($) can be used as identifier. • _ underscore can be used. • Keywords cannot be used as identifier. • Eg: HelloWorld, Jamsher (may be class names). • A=3; a=5; z=c; x=y, can be the variables. • Sum, Sub, Div can be methods. 4/10/2019 Jamsher Bhanbhro(F16CS11) 2
  • 3. Java Keywords • Keywords are reserved names for java. • These can’t be used as identifiers, variables name etc. • Abstract: used for class • Boolean: 0 or 1 true or false • Break: use to break the statement or the condition • Char: for data type • Import, class, switch, case, if else, try, this, throw, void, return, package etc are the java keywords. 4/10/2019 Jamsher Bhanbhro(F16CS11) 3
  • 4. Data types in java • When a variable is assigned a memory it is assigned by its data types. • A variable store which type of data is known as data type. • There are basically two data types available in java 1. Primitive data type 2. Non Primitive data type/ Reference data type 4/10/2019 Jamsher Bhanbhro(F16CS11) 4
  • 5. Primitive data type • Those data types which are already defined in the java library is known as Primitive data type. • These are built-in or predefined data types. • Java basically supports 8 predefined data types. • Which are byte, short, long, float, double, Boolean, char, int. 4/10/2019 Jamsher Bhanbhro(F16CS11) 5
  • 6. 1. Integer Data type • Integer is denoted by int and stores the integer values. • Int data type is a 32-bit signed two's complement integer • Minimum value is - 2,147,483,648 (-2^31) • Maximum value is 2,147,483,647(inclusive) (2^31 -1) • Integer is generally used as the default data type for integral values unless there is a concern about memory. • The default value is 0 • Example: int a = 11, int b = 41 4/10/2019 Jamsher Bhanbhro(F16CS11) 6
  • 7. 2. Byte • Byte data type is an 8-bit signed two's complement integer • Minimum value is -128 (-2^7). • Maximum value is 127 (inclusive)(2^7 -1) • Default value is 0. • Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an integer • For Example: byte a=11, b=41; 4/10/2019 Jamsher Bhanbhro(F16CS11) 7
  • 8. 3. Float • Float data-type is a single-precision 32-bit IEEE 754 floating point. • Float is mainly used to save memory in large arrays of floating point numbers. • Default value is 0.0f. • Float data-type is never used for precise values such as currency. • Example: float f1 = 234.5f(f stands for float) 4/10/2019 Jamsher Bhanbhro(F16CS11) 8
  • 9. 4. Short • Short datatype is a 16-bit signed two's complement integer • Minimum value is -32,768 (-2^15) • Maximum value is 32,767 (inclusive) (2^15 -1) • Short datatype can also be used to save memory as byte data type. A short is 2 times smaller than an integer • Default value is 0 4/10/2019 Jamsher Bhanbhro(F16CS11) 9
  • 10. 5. Long • Long datatype is a 64-bit signed two's complement integer • Minimum value is 9,223,372,036,854,775,808 (- 2^63) • Maximum value is9,223,372,036,854,775,807 (inclusive) (2^63 -1) • This type is used when a wider range than int is needed. • Default value is 0L(L is used for Long) • Example: long a = 100000L, long b = -200000L 4/10/2019 Jamsher Bhanbhro(F16CS11) 10
  • 11. 6. Char • char data-type is a single 16-bit Unicode character. • Minimum value is 'u0000' (or 0) . • Maximum value is 'uffff' (or 65,535 inclusive) . • Char data-type is used to store any character • Example: char letterA =‘J‘; 4/10/2019 Jamsher Bhanbhro(F16CS11) 11
  • 12. 7. Boolean • Boolean data-type represents one bit of information. • There are only two possible values: true and false. • This data-type is used for simple flags that track true/false conditions. • Default value is false . • Example: boolean one = true, 0=false; 4/10/2019 Jamsher Bhanbhro(F16CS11) 12
  • 13. 8. Double • double data-type is a double-precision 64-bit IEEE 754 floating point. • This data-type is generally used as the default data type for decimal values, generally the default choice. • Double data-type should never be used for precise values such as currency. • Default value is 0.0d(d for double) 4/10/2019 Jamsher Bhanbhro(F16CS11) 13
  • 14. Reference data-types • These are not predefined data-types. • These are created using defined constructors of the classes. • They are used to access the objects • These are the reference variables • eg: Jamsher ob=new Jamsher(); 4/10/2019 Jamsher Bhanbhro(F16CS11) 14