SlideShare a Scribd company logo
1 of 18
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

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 variablesSohanur63
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variablesPushpendra 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 PHPRick Ogden
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
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 ConceptsAashish Jain
 
Exercises for ja se
Exercises for ja seExercises for ja se
Exercises for ja sesshhzap
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in javaHitesh Kumar
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJSSumanth krishna
 
Ch. 3 classes and objects
Ch. 3 classes and objectsCh. 3 classes and objects
Ch. 3 classes and objectsdkohreidze
 

What's hot (16)

Chap4java5th
Chap4java5thChap4java5th
Chap4java5th
 
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
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
 
Chap1java5th
Chap1java5thChap1java5th
Chap1java5th
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
 
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
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
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
 
Exercises for ja se
Exercises for ja seExercises for ja se
Exercises for ja se
 
Variable
VariableVariable
Variable
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Java 8
Java 8Java 8
Java 8
 
Java
JavaJava
Java
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
 
Ch. 3 classes and objects
Ch. 3 classes and objectsCh. 3 classes and objects
Ch. 3 classes and objects
 

Similar to Lec 1.3 Object Oriented Programming

L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesteach4uin
 
Java platform
Java platformJava platform
Java platformVisithan
 
Learning core java
Learning core javaLearning core java
Learning core javaAbhay 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 typesSasidharaRaoMarrapu
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptxSrizan 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.pptxSofiaArquero2
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 CertificationsGiacomo 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.pptxMurali M
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptxSmitNikumbh
 
5variables in c#
5variables in c#5variables in c#
5variables in c#Sireesh K
 
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptxAlgorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptxRobertCarreonBula
 

Similar to Lec 1.3 Object Oriented Programming (20)

L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Java platform
Java platformJava platform
Java platform
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Java ce241
Java ce241Java ce241
Java ce241
 
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)
 
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
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
java token
java tokenjava token
java token
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptx
 
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)
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
COMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptxCOMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptx
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
 
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
 
8. data types
8. data types8. data types
8. data types
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptx
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptxAlgorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
 
Java session3
Java session3Java session3
Java session3
 

More from Badar Waseer

Ch 03 s.e agile development
Ch 03 s.e agile developmentCh 03 s.e agile development
Ch 03 s.e agile developmentBadar 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 1Badar Waseer
 
Ch 01 s.e introduction
Ch 01 s.e introductionCh 01 s.e introduction
Ch 01 s.e introductionBadar 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 diagramsBadar Waseer
 
Lec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingLec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingBadar Waseer
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingBadar 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 skillsBadar Waseer
 
Multimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationMultimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationBadar Waseer
 
Multimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoMultimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoBadar Waseer
 
Multimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioMultimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioBadar 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 MultimediaBadar Waseer
 
Multimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringMultimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringBadar 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 FsdBadar Waseer
 

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
 
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
 
Ch 01 s.e introduction
Ch 01 s.e introductionCh 01 s.e introduction
Ch 01 s.e introduction
 
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
 
Ch 13 s.e cmmi
Ch 13 s.e cmmiCh 13 s.e cmmi
Ch 13 s.e cmmi
 
Lec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingLec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented Programming
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented Programming
 
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
 
Multimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationMultimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animation
 
Multimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoMultimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 video
 
Multimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioMultimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 Audio
 
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
 
Multimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringMultimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 delivering
 
Agriculture Information System (AIS)
Agriculture Information System (AIS)Agriculture Information System (AIS)
Agriculture Information System (AIS)
 
Output Devices UoS Fsd
Output Devices UoS FsdOutput Devices UoS Fsd
Output Devices UoS Fsd
 

Recently uploaded

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
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
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
_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
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
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
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
_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
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

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