SlideShare a Scribd company logo
JAVA
"WRITE ONCE, RUN ANYWHERE”
Lec--3
By: Zubair Khalid
Java
£ What is variable
£ Data Types in Java
£ Comments in Java
£ Operators and their types
Variable is location/place where we can put/store some data.
Data can be of different types. E.g. Strings, Numbers etc.
Data Types and Variables
Variable:
Data Types and Variables
Data type is the type of data which can be stored in a
variable.
Data Type:
There are 2 types of built in data types in java
Built in Data Types in Java
£ Primitive (Non Object Oriented)
£ Non-Primitive (Classes, Arrays, Interface)
Primitive Types
Primitive
Numeric Non-Numeric
Integer
Floating
Point
Character Boolean
£ These Data Types are elemental or simple data types
£ Java has 8 primitive types which are following
Primitive Types
i. Byte
ii. Int
iii. Short
iv. long
v. Float
vi. Double
vii. Boolean
viii. char
Primitive Types
Type Meaning Size in bits(Byte) Range
Byte 8 bit integer 8(1) -128 to 127
Short Short integer 16(2) -32,768 to 32,767
Int Integer 32(4) -2,147,483,648 to 2,147,483,647
Long Long integer 64(8)
-9,223,372,036,854,775,508
to
9,223,372,036,854,775,508
Float Single precision floating point 32(4)
Double Double precision floating point 64(8)
Boolean True or False value 1
Char Character 16(2) 'u0000' (or 0)-'uffff' (or 65,535
inclusive)
Java Comments
Comments are ignored by compiler and are used to provide summery of code
in plain English or any other language.
Java defines three types of comments
£ Single-Line Comments (//This is Single-line comments)
£ Multi-Line Comments (/*This is Multi-line comments*/)
£ Documentation Comments (/**This is documentation comment**/)
Operators
An operator is a symbol, which tells the compiler to perform a specific operation
There are following types of operators in java
Operator:
i. Assignment Operator
ii. Arithmetic Operators
iii. Relational/Conditional Operators
iv. Logical Operators
Assignment Operator
Assignment Operator is used to assign a value to a variable
E.g. a=10 , b=false , c=‘X’
Arithmetic Operators
Arithmetic Operators perform mathematical operations on
variables.
Such as Addition, Subtraction, Multiplication, Division, Remainder,
Increment and Decrement
Arithmetic Operators
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement
Relational/Conditional Operators
Operator Meaning Example
== Equal to a==b
!= Not Equal to a!=b
> Greater than a>b
< Less than a<b
>= Greater than or equal to a>=b
<= Less than or equal to a<=b
Logical Operators
Operator Meaning Example
& AND x>1 & y<1
| OR x>1 | y<1
^ XOR(exclusive OR) x ^ y
&& Short-circuit AND x>1 && y<1
|| Short-circuit OR X>1 || y<1
! NOT x!=1 & y<1
AND Logic (&)
First Value(A) Second Value(B) Result(C)
True True True
True False False
False True False
False False False
OR Logic (|)
First Value(A) Second Value(B) Result(C)
True True True
True False True
False True True
False False False
Short-Circuit AND (&&)
First Value(A) Second Value(B) Result(C)
True True True
True False False
False True False
False False False
Checks the first condition
if first condition == False
Not check second condition
elseif first condition == True
Check second condition
Short-Circuit OR (&&)
First Value(A) Second Value(B) Result(C)
True True True
True False True
False True True
False False False
Checks the first condition
if first condition == True
Not check second condition
elseif first condition == False
Check second condition
Ternary Operator
Used to replace if-else statement
The general form of ternary ? operator is
condition ? exp1 : exp2;
If (x>10) y=50;
else y=20;
Example:
x=(x>10) ? y=50 : y=20;In to
In computer programming, ?: is a ternary operator that is part of the syntax for basic conditional expressions in
several programming languages. It is commonly referred to as the conditional operator, inline if (if), or ternary if.
An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c.

More Related Content

What's hot (20)

PPTX
java programming basics - part ii
jyoti_lakhani
 
PPT
Ap Power Point Chpt6
dplunkett
 
PPTX
Object oriented modeling
Pooja Dixit
 
PPTX
Entity relationship diagram
Talesun Solar USA Ltd.
 
PPSX
Java session3
Jigarthacker
 
PPTX
Jarrar: Final Check & Schema Engineering Issues
Mustafa Jarrar
 
PPTX
Functional dependencies in Database Management System
Kevin Jadiya
 
PDF
Database management system session 5
Infinity Tech Solutions
 
PPTX
Relational algebra ppt
GirdharRatne
 
PPT
Pemrograman komputer 4 (ekspresi)
jayamartha
 
PDF
Introduction to database-ER Model
Ajit Nayak
 
PPTX
A simple presentation on Relational Algebra
Arman Hossain
 
PPTX
Jarrar: Subtype Relations and Constraints
Mustafa Jarrar
 
PPTX
02 data types in java
রাকিন রাকিন
 
PPTX
This keyword and final keyword
kinjalbirare
 
PPTX
Database - Entity Relationship Diagram (ERD)
Mudasir Qazi
 
PPT
Sql Patterns
phanleson
 
PPTX
Fundamentals of C Programming Language
RamaBoya2
 
PPTX
Chapter 4
Nazir Ahmed
 
java programming basics - part ii
jyoti_lakhani
 
Ap Power Point Chpt6
dplunkett
 
Object oriented modeling
Pooja Dixit
 
Entity relationship diagram
Talesun Solar USA Ltd.
 
Java session3
Jigarthacker
 
Jarrar: Final Check & Schema Engineering Issues
Mustafa Jarrar
 
Functional dependencies in Database Management System
Kevin Jadiya
 
Database management system session 5
Infinity Tech Solutions
 
Relational algebra ppt
GirdharRatne
 
Pemrograman komputer 4 (ekspresi)
jayamartha
 
Introduction to database-ER Model
Ajit Nayak
 
A simple presentation on Relational Algebra
Arman Hossain
 
Jarrar: Subtype Relations and Constraints
Mustafa Jarrar
 
02 data types in java
রাকিন রাকিন
 
This keyword and final keyword
kinjalbirare
 
Database - Entity Relationship Diagram (ERD)
Mudasir Qazi
 
Sql Patterns
phanleson
 
Fundamentals of C Programming Language
RamaBoya2
 
Chapter 4
Nazir Ahmed
 

Similar to Java -lec-3 (20)

PPTX
java-tokens-data-types.pptx ciiiidddidifif
sayedshaad02
 
PDF
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
PPT
Data types and Operators
raksharao
 
PPTX
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
GANESHBABUVelu
 
PPTX
Lecture - 3 Variables-data type_operators_oops concept
manish kumar
 
PPTX
Basic_Java_02.pptx
Kajal Kashyap
 
PPTX
Java unit1 b- Java Operators to Methods
SivaSankari36
 
PPT
lecture2 (1).ppt variable s and operators
ChittyAvula
 
PDF
data types.pdf
HarshithaGowda914171
 
PPT
object oriented programming java lectures
MSohaib24
 
PPTX
Operators in java
Then Murugeshwari
 
PDF
Java basic operators
Emmanuel Alimpolos
 
PDF
Java basic operators
Emmanuel Alimpolos
 
PPTX
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
PPTX
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
merabapudc
 
PPTX
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
PPTX
Pj01 4-operators and control flow
SasidharaRaoMarrapu
 
PPTX
05 operators
dhrubo kayal
 
PPT
4_A1208223655_21789_2_2018_04. Operators.ppt
RithwikRanjan
 
PPTX
OCA Java SE 8 Exam Chapter 2 Operators & Statements
İbrahim Kürce
 
java-tokens-data-types.pptx ciiiidddidifif
sayedshaad02
 
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
Data types and Operators
raksharao
 
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
GANESHBABUVelu
 
Lecture - 3 Variables-data type_operators_oops concept
manish kumar
 
Basic_Java_02.pptx
Kajal Kashyap
 
Java unit1 b- Java Operators to Methods
SivaSankari36
 
lecture2 (1).ppt variable s and operators
ChittyAvula
 
data types.pdf
HarshithaGowda914171
 
object oriented programming java lectures
MSohaib24
 
Operators in java
Then Murugeshwari
 
Java basic operators
Emmanuel Alimpolos
 
Java basic operators
Emmanuel Alimpolos
 
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
merabapudc
 
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
Pj01 4-operators and control flow
SasidharaRaoMarrapu
 
05 operators
dhrubo kayal
 
4_A1208223655_21789_2_2018_04. Operators.ppt
RithwikRanjan
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
İbrahim Kürce
 
Ad

Recently uploaded (20)

PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Python basic programing language for automation
DanialHabibi2
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Ad

Java -lec-3

  • 1. JAVA "WRITE ONCE, RUN ANYWHERE” Lec--3 By: Zubair Khalid
  • 2. Java £ What is variable £ Data Types in Java £ Comments in Java £ Operators and their types
  • 3. Variable is location/place where we can put/store some data. Data can be of different types. E.g. Strings, Numbers etc. Data Types and Variables Variable:
  • 4. Data Types and Variables Data type is the type of data which can be stored in a variable. Data Type:
  • 5. There are 2 types of built in data types in java Built in Data Types in Java £ Primitive (Non Object Oriented) £ Non-Primitive (Classes, Arrays, Interface)
  • 7. £ These Data Types are elemental or simple data types £ Java has 8 primitive types which are following Primitive Types i. Byte ii. Int iii. Short iv. long v. Float vi. Double vii. Boolean viii. char
  • 8. Primitive Types Type Meaning Size in bits(Byte) Range Byte 8 bit integer 8(1) -128 to 127 Short Short integer 16(2) -32,768 to 32,767 Int Integer 32(4) -2,147,483,648 to 2,147,483,647 Long Long integer 64(8) -9,223,372,036,854,775,508 to 9,223,372,036,854,775,508 Float Single precision floating point 32(4) Double Double precision floating point 64(8) Boolean True or False value 1 Char Character 16(2) 'u0000' (or 0)-'uffff' (or 65,535 inclusive)
  • 9. Java Comments Comments are ignored by compiler and are used to provide summery of code in plain English or any other language. Java defines three types of comments £ Single-Line Comments (//This is Single-line comments) £ Multi-Line Comments (/*This is Multi-line comments*/) £ Documentation Comments (/**This is documentation comment**/)
  • 10. Operators An operator is a symbol, which tells the compiler to perform a specific operation There are following types of operators in java Operator: i. Assignment Operator ii. Arithmetic Operators iii. Relational/Conditional Operators iv. Logical Operators
  • 11. Assignment Operator Assignment Operator is used to assign a value to a variable E.g. a=10 , b=false , c=‘X’
  • 12. Arithmetic Operators Arithmetic Operators perform mathematical operations on variables. Such as Addition, Subtraction, Multiplication, Division, Remainder, Increment and Decrement
  • 13. Arithmetic Operators Operator Meaning + Addition - Subtraction * Multiplication / Division % Modulus ++ Increment -- Decrement
  • 14. Relational/Conditional Operators Operator Meaning Example == Equal to a==b != Not Equal to a!=b > Greater than a>b < Less than a<b >= Greater than or equal to a>=b <= Less than or equal to a<=b
  • 15. Logical Operators Operator Meaning Example & AND x>1 & y<1 | OR x>1 | y<1 ^ XOR(exclusive OR) x ^ y && Short-circuit AND x>1 && y<1 || Short-circuit OR X>1 || y<1 ! NOT x!=1 & y<1
  • 16. AND Logic (&) First Value(A) Second Value(B) Result(C) True True True True False False False True False False False False
  • 17. OR Logic (|) First Value(A) Second Value(B) Result(C) True True True True False True False True True False False False
  • 18. Short-Circuit AND (&&) First Value(A) Second Value(B) Result(C) True True True True False False False True False False False False Checks the first condition if first condition == False Not check second condition elseif first condition == True Check second condition
  • 19. Short-Circuit OR (&&) First Value(A) Second Value(B) Result(C) True True True True False True False True True False False False Checks the first condition if first condition == True Not check second condition elseif first condition == False Check second condition
  • 20. Ternary Operator Used to replace if-else statement The general form of ternary ? operator is condition ? exp1 : exp2; If (x>10) y=50; else y=20; Example: x=(x>10) ? y=50 : y=20;In to In computer programming, ?: is a ternary operator that is part of the syntax for basic conditional expressions in several programming languages. It is commonly referred to as the conditional operator, inline if (if), or ternary if. An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c.