SlideShare a Scribd company logo
CMP-2123-Object Oriented
Programming
Lecture 1.3
By
Abrar Ahmad
Abrar.ahmad14@ce.ceme.edu.pk
Today’s Topics
• Data Types
• Java Tokens
• Variables
2Badar Waseer arbabwaseergmail.com
Data Types
• Data type specifies the size and type of values that can
be stored in an identifier. The Java language is rich in
its data types. Different data types allow you to select
the type appropriate to the needs of the application.
• Data types in Java are classified into two types:
• Primitive—which include Integer, Character, Boolean, and
Floating Point.
• Non-primitive—which include Classes, Interfaces, and
Arrays.
3Badar Waseer arbabwaseergmail.com
Primitive Data Types
• Integer
•Integer types can hold whole numbers such as 123
and −96. The size of the values that can be stored
depends on the integer type that we choose.
4Badar Waseer arbabwaseergmail.com
• The range of values is calculated as −(2n−1) to (2n−1)−1; where
n is the number of bits required. For example, the byte data
type requires 1 byte = 8 bits. Therefore, the range of values
that can be stored in the byte data type is −(28−1) to (28−1)−1
= −27 to (27) -1
= −128 to 127
•Floating Point
• Floating point data types are used to represent numbers
with a fractional part. Single precision floating point
numbers occupy 4 bytes and Double precision floating
point numbers occupy 8 bytes. There are two subtypes:
5Badar Waseer arbabwaseergmail.com
• Character
• It stores character constants in the memory. It assumes a size
of 2 bytes, but basically it can hold only a single character
because char stores unicode character sets. It has a minimum
value of ‘u0000’ (or 0) and a maximum value of ‘uffff’ (or
65,535, inclusive).
•Boolean
• Boolean data types are used to store values with two states:
true or false.
6Badar Waseer arbabwaseergmail.com
Java Tokens
• A token is the smallest element in a program that is
meaningful to the compiler. These tokens define the
structure of the language. The Java token set can be divided
into five categories: Identifiers, Keywords, Literals,
Operators, and Separators.
• Identifiers
• Identifiers are names provided by you. These can be
assigned to variables, methods, functions, classes etc. to
uniquely identify them to the compiler.
7Badar Waseer arbabwaseergmail.com
• Keywords
• Keywords are reserved words that have a specific meaning
for the compiler. They cannot be used as identifiers. Java
has a rich set of keywords. Some examples are: boolean,
char, if, protected, new, this, try, catch, null, threadsafe etc.
• Literals
• Literals are variables whose values remain constant
throughout the program. They are also called Constants.
Literals can be of four types. They are:
8Badar Waseer arbabwaseergmail.com
• String Literals
• String Literals are always enclosed in double quotes and are implemented
using the java.lang.String class. Enclosing a character string within double
quotes will automatically create a new String object. For example,
• String s = “This is a string”;
• String objects are immutable, which means that once created, their values
cannot be changed.
• Character Literals
• These are enclosed in single quotes and contain only one character.
• Boolean Literals
• They can only have the values true or false. These values do not
correspond to 1 or 0 as in C or C++.
9Badar Waseer arbabwaseergmail.com
• Numeric Literals
• Numeric Literals can contain integer or floating point values.
• Operators
• An operator is a symbol that operates on one or more operands to
produce a result.
• Separators
• Separators are symbols that indicate the division and arrangement of
groups of code. The structure and function of code is generally
defined by the separators. The separators used in Java are as follows:
10Badar Waseer arbabwaseergmail.com
• parentheses ( )
• Used to define precedence in expressions, to enclose parameters
in method definitions, and enclosing cast types.
• braces { }
• Used to define a block of code and to hold the values of arrays.
• semicolon ;
• Used to separate statements.
11Badar Waseer arbabwaseergmail.com
• comma ,
• Used to separate identifiers in a variable declaration and in the
for statement.
• period .
• Used to separate package names from classes and subclasses
and to separate a variable or a method from a reference
variable.
12Badar Waseer arbabwaseergmail.com
Variables
1. Instance Variables (Non-Static Fields)
• Objects store their individual states in “non-static
fields”, that is, fields declared without the static
keyword
• Non-static fields are also known as instance variables
because their values are unique to each instance of a
class. For example, the currentSpeed of one bicycle is
independent from the currentSpeed of another.
14Badar Waseer arbabwaseergmail.com
2. Class Variables (Static Fields)
• A class variable is any field declared with the static modifier;
this tells the compiler that there is exactly one copy of this
variable in existence, regardless of how many times the class
has been instantiated. A field defining the number of gears
for a particular kind of bicycle could be marked as static
since, conceptually, the same number of gears will apply to
all instances. The code
• static int nymGears = 6
would create such a static field.
15Badar Waseer arbabwaseergmail.com
3. Local Variables
• A method stores its temporary state in local variables. The syntax for
declaring a local variable is similar to declaring a field
• (for example, int count = 0; )
• There is no special keyword designating a variable as local; that
determination comes entirely from the location in which the variable
is declared—between the opening and closing braces of a method. As
such, local variables are only visible to the methods in which they are
declared; they are not accessible from the rest of the class.
4. Parameters
• They are the variables that are passed to the methods of a class.
16Badar Waseer arbabwaseergmail.com
Variable Declaration
• Identifiers are the names of variables. They must be composed of
only letters, numbers, the underscore, and the dollar sign ($). They
cannot contain white spaces. Identifiers may only begin with a letter,
the underscore, or the dollar sign. A variable cannot begin with a
number. All variable names are case sensitive.
Syntax for variable declaration
• datatype1 variable1, datatype2 variable2, … datatypen variablen;
• For example:
• int a, char ch;
17Badar Waseer arbabwaseergmail.com
Initialization
• Variables can be assigned values in the following way:
variableName = value;
• For example
ch =‘a’;
a = 0;
18Badar Waseer arbabwaseergmail.com

More Related Content

What's hot (16)

Chap4java5th
Chap4java5thChap4java5th
Chap4java5th
Asfand Hassan
 
Local variables Instance variables Class/static variables
Local variables Instance variables Class/static variablesLocal variables Instance variables Class/static variables
Local variables Instance variables Class/static variables
Sohanur63
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
Pushpendra Tyagi
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
Archana Gopinath
 
Chap1java5th
Chap1java5thChap1java5th
Chap1java5th
Asfand Hassan
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
Shahid Rasheed
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic Concepts
Aashish Jain
 
Exercises for ja se
Exercises for ja seExercises for ja se
Exercises for ja se
sshhzap
 
Variable
VariableVariable
Variable
abdullah al mahamud rosi
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
Java 8
Java 8Java 8
Java 8
Sudipta K Paik
 
Java
JavaJava
Java
Raghu nath
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
Sumanth krishna
 
Ch. 3 classes and objects
Ch. 3 classes and objectsCh. 3 classes and objects
Ch. 3 classes and objects
dkohreidze
 
Local variables Instance variables Class/static variables
Local variables Instance variables Class/static variablesLocal variables Instance variables Class/static variables
Local variables Instance variables Class/static variables
Sohanur63
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
Pushpendra Tyagi
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic Concepts
Aashish Jain
 
Exercises for ja se
Exercises for ja seExercises for ja se
Exercises for ja se
sshhzap
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
Sumanth krishna
 
Ch. 3 classes and objects
Ch. 3 classes and objectsCh. 3 classes and objects
Ch. 3 classes and objects
dkohreidze
 

Similar to Lec 1.3 Object Oriented Programming (20)

L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
Java platform
Java platformJava platform
Java platform
Visithan
 
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
gkgupta1115
 
Learning core java
Learning core javaLearning core java
Learning core java
Abhay Bharti
 
Java ce241
Java ce241Java ce241
Java ce241
Minal Maniar
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)
Shirish Bari
 
Pj01 3-java-variable and data types
Pj01 3-java-variable and data typesPj01 3-java-variable and data types
Pj01 3-java-variable and data types
SasidharaRaoMarrapu
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
Ainuddin Yousufzai
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptx
Srizan Pokrel
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
Dilawar Khan
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
rishi ram khanal
 
COMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptxCOMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptx
SofiaArquero2
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
Giacomo Veneri
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
Murali M
 
8. data types
8. data types8. data types
8. data types
Zambales National High School
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptx
SmitNikumbh
 
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFPROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
JAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf VsjsjsnhehehJAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
Mohammed Safwat Abu Kwaik
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
Sireesh K
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
Java platform
Java platformJava platform
Java platform
Visithan
 
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
gkgupta1115
 
Learning core java
Learning core javaLearning core java
Learning core java
Abhay Bharti
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)
Shirish Bari
 
Pj01 3-java-variable and data types
Pj01 3-java-variable and data typesPj01 3-java-variable and data types
Pj01 3-java-variable and data types
SasidharaRaoMarrapu
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptx
Srizan Pokrel
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
Dilawar Khan
 
COMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptxCOMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptx
SofiaArquero2
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
Giacomo Veneri
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
Murali M
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptx
SmitNikumbh
 
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFPROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
JAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf VsjsjsnhehehJAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
Sireesh K
 

More from Badar Waseer (15)

Ch 03 s.e agile development
Ch 03 s.e agile developmentCh 03 s.e agile development
Ch 03 s.e agile development
Badar Waseer
 
Ch 02 s.e software process models 1
Ch 02 s.e software process models   1Ch 02 s.e software process models   1
Ch 02 s.e software process models 1
Badar Waseer
 
Ch 01 s.e introduction
Ch 01 s.e introductionCh 01 s.e introduction
Ch 01 s.e introduction
Badar Waseer
 
Ch 14 s.e use case diagrams
Ch 14 s.e use case diagramsCh 14 s.e use case diagrams
Ch 14 s.e use case diagrams
Badar Waseer
 
Ch 13 s.e cmmi
Ch 13 s.e cmmiCh 13 s.e cmmi
Ch 13 s.e cmmi
Badar Waseer
 
Lec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingLec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented Programming
Badar Waseer
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented Programming
Badar Waseer
 
Multimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skillsMultimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skills
Badar Waseer
 
Multimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationMultimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animation
Badar Waseer
 
Multimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoMultimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 video
Badar Waseer
 
Multimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioMultimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 Audio
Badar Waseer
 
Multimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 MultimediaMultimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 Multimedia
Badar Waseer
 
Multimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringMultimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 delivering
Badar Waseer
 
Agriculture Information System (AIS)
Agriculture Information System (AIS)Agriculture Information System (AIS)
Agriculture Information System (AIS)
Badar Waseer
 
Output Devices UoS Fsd
Output Devices UoS FsdOutput Devices UoS Fsd
Output Devices UoS Fsd
Badar Waseer
 
Ch 03 s.e agile development
Ch 03 s.e agile developmentCh 03 s.e agile development
Ch 03 s.e agile development
Badar Waseer
 
Ch 02 s.e software process models 1
Ch 02 s.e software process models   1Ch 02 s.e software process models   1
Ch 02 s.e software process models 1
Badar Waseer
 
Ch 01 s.e introduction
Ch 01 s.e introductionCh 01 s.e introduction
Ch 01 s.e introduction
Badar Waseer
 
Ch 14 s.e use case diagrams
Ch 14 s.e use case diagramsCh 14 s.e use case diagrams
Ch 14 s.e use case diagrams
Badar Waseer
 
Lec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingLec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented Programming
Badar Waseer
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented Programming
Badar Waseer
 
Multimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skillsMultimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skills
Badar Waseer
 
Multimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationMultimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animation
Badar Waseer
 
Multimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoMultimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 video
Badar Waseer
 
Multimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioMultimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 Audio
Badar Waseer
 
Multimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 MultimediaMultimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 Multimedia
Badar Waseer
 
Multimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringMultimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 delivering
Badar Waseer
 
Agriculture Information System (AIS)
Agriculture Information System (AIS)Agriculture Information System (AIS)
Agriculture Information System (AIS)
Badar Waseer
 
Output Devices UoS Fsd
Output Devices UoS FsdOutput Devices UoS Fsd
Output Devices UoS Fsd
Badar Waseer
 

Recently uploaded (20)

Debunking the Myths behind AI - v1, Carl Dalby
Debunking the Myths behind AI -  v1, Carl DalbyDebunking the Myths behind AI -  v1, Carl Dalby
Debunking the Myths behind AI - v1, Carl Dalby
Association for Project Management
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 

Lec 1.3 Object Oriented Programming

  • 2. Today’s Topics • Data Types • Java Tokens • Variables 2Badar Waseer arbabwaseergmail.com
  • 3. Data Types • Data type specifies the size and type of values that can be stored in an identifier. The Java language is rich in its data types. Different data types allow you to select the type appropriate to the needs of the application. • Data types in Java are classified into two types: • Primitive—which include Integer, Character, Boolean, and Floating Point. • Non-primitive—which include Classes, Interfaces, and Arrays. 3Badar Waseer arbabwaseergmail.com
  • 4. Primitive Data Types • Integer •Integer types can hold whole numbers such as 123 and −96. The size of the values that can be stored depends on the integer type that we choose. 4Badar Waseer arbabwaseergmail.com
  • 5. • The range of values is calculated as −(2n−1) to (2n−1)−1; where n is the number of bits required. For example, the byte data type requires 1 byte = 8 bits. Therefore, the range of values that can be stored in the byte data type is −(28−1) to (28−1)−1 = −27 to (27) -1 = −128 to 127 •Floating Point • Floating point data types are used to represent numbers with a fractional part. Single precision floating point numbers occupy 4 bytes and Double precision floating point numbers occupy 8 bytes. There are two subtypes: 5Badar Waseer arbabwaseergmail.com
  • 6. • Character • It stores character constants in the memory. It assumes a size of 2 bytes, but basically it can hold only a single character because char stores unicode character sets. It has a minimum value of ‘u0000’ (or 0) and a maximum value of ‘uffff’ (or 65,535, inclusive). •Boolean • Boolean data types are used to store values with two states: true or false. 6Badar Waseer arbabwaseergmail.com
  • 7. Java Tokens • A token is the smallest element in a program that is meaningful to the compiler. These tokens define the structure of the language. The Java token set can be divided into five categories: Identifiers, Keywords, Literals, Operators, and Separators. • Identifiers • Identifiers are names provided by you. These can be assigned to variables, methods, functions, classes etc. to uniquely identify them to the compiler. 7Badar Waseer arbabwaseergmail.com
  • 8. • Keywords • Keywords are reserved words that have a specific meaning for the compiler. They cannot be used as identifiers. Java has a rich set of keywords. Some examples are: boolean, char, if, protected, new, this, try, catch, null, threadsafe etc. • Literals • Literals are variables whose values remain constant throughout the program. They are also called Constants. Literals can be of four types. They are: 8Badar Waseer arbabwaseergmail.com
  • 9. • String Literals • String Literals are always enclosed in double quotes and are implemented using the java.lang.String class. Enclosing a character string within double quotes will automatically create a new String object. For example, • String s = “This is a string”; • String objects are immutable, which means that once created, their values cannot be changed. • Character Literals • These are enclosed in single quotes and contain only one character. • Boolean Literals • They can only have the values true or false. These values do not correspond to 1 or 0 as in C or C++. 9Badar Waseer arbabwaseergmail.com
  • 10. • Numeric Literals • Numeric Literals can contain integer or floating point values. • Operators • An operator is a symbol that operates on one or more operands to produce a result. • Separators • Separators are symbols that indicate the division and arrangement of groups of code. The structure and function of code is generally defined by the separators. The separators used in Java are as follows: 10Badar Waseer arbabwaseergmail.com
  • 11. • parentheses ( ) • Used to define precedence in expressions, to enclose parameters in method definitions, and enclosing cast types. • braces { } • Used to define a block of code and to hold the values of arrays. • semicolon ; • Used to separate statements. 11Badar Waseer arbabwaseergmail.com
  • 12. • comma , • Used to separate identifiers in a variable declaration and in the for statement. • period . • Used to separate package names from classes and subclasses and to separate a variable or a method from a reference variable. 12Badar Waseer arbabwaseergmail.com
  • 14. 1. Instance Variables (Non-Static Fields) • Objects store their individual states in “non-static fields”, that is, fields declared without the static keyword • Non-static fields are also known as instance variables because their values are unique to each instance of a class. For example, the currentSpeed of one bicycle is independent from the currentSpeed of another. 14Badar Waseer arbabwaseergmail.com
  • 15. 2. Class Variables (Static Fields) • A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since, conceptually, the same number of gears will apply to all instances. The code • static int nymGears = 6 would create such a static field. 15Badar Waseer arbabwaseergmail.com
  • 16. 3. Local Variables • A method stores its temporary state in local variables. The syntax for declaring a local variable is similar to declaring a field • (for example, int count = 0; ) • There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared—between the opening and closing braces of a method. As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class. 4. Parameters • They are the variables that are passed to the methods of a class. 16Badar Waseer arbabwaseergmail.com
  • 17. Variable Declaration • Identifiers are the names of variables. They must be composed of only letters, numbers, the underscore, and the dollar sign ($). They cannot contain white spaces. Identifiers may only begin with a letter, the underscore, or the dollar sign. A variable cannot begin with a number. All variable names are case sensitive. Syntax for variable declaration • datatype1 variable1, datatype2 variable2, … datatypen variablen; • For example: • int a, char ch; 17Badar Waseer arbabwaseergmail.com
  • 18. Initialization • Variables can be assigned values in the following way: variableName = value; • For example ch =‘a’; a = 0; 18Badar Waseer arbabwaseergmail.com