SlideShare a Scribd company logo
 java programming basics - part ii
 java programming basics - part ii
 java programming basics - part ii
Variables are nothing but reserved memory locations to store values
A Variable has –
Memory Address
Name

a
10
10110

Value

int a=10;
There are two data types available in Java:
•Primitive Data Types
•Reference/Non Primitive/ Derived Data Types
 java programming basics - part ii
There are eight primitive data types supported by Java.
Primitive data types are predefined by the language and named
by a keyword
Byte data type is an 8-bit signed 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 int
Example: byte a = 100 , byte b = -50
Short data type is a 16-bit signed integer
Minimum value is -32,768 (-2^15)
Maximum value is 32,767 (inclusive) (2^15 -1)
Short data type can also be used to save memory as byte data type
A short is 2 times smaller than an int

Default value is 0
Example: short s = 10000, short r = -20000
Int data type is a 32-bit signed integer
Minimum value is - 2,147,483,648.(-2^31)

Maximum value is 2,147,483,647(inclusive).(2^31 -1)
Int 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 = 100000, int b = -200000
Long data type is a 64-bit signed integer
Minimum value is -9,223,372,036,854,775,808.(-2^63)

Maximum value is 9,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.
Example: long a = 100000L, int b = -200000L
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
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
Example: double d1 = 123.4
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
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 ='A'
Reference variables are created using defined constructors of the
classes
They are used to access objects. These variables are declared to be of a
specific type that cannot be changed. For example, Employee, Puppy
etc.
Class objects, and various type of array variables come under reference
data type
Default value of any reference variable is null
A reference variable can be used to refer to any object of the declared
type or any compatible type
Example: Animal animal = new Animal("giraffe");
 java programming basics - part ii
In Java, all variables must be declared before they can be used. The basic form
of a variable declaration is shown here:

type identifier [ = value][, identifier [= value] ...] ;
The type is one of Java's datatypes. The identifier is the name of the variable. To
declare more than one variable of the specified type, use a comma-separated list.

Here are several examples of variable declarations of various types. Note that
some include an initialization
int a, b, c;

// declares three ints, a, b, and c

int d = 3, e, f = 5; // declares three more ints, initializing d and f
byte z = 22;

// initializes z

double pi = 3.14159; // declares an approximation of pi
char x = 'x';

// the variable x has the value 'x'
 java programming basics - part ii
 java programming basics - part ii
Program
Class-object

Method

Method

X

Y

A
 java programming basics - part ii
 java programming basics - part ii
 java programming basics - part ii
Program

Class-object

A

Method

X

Y
 java programming basics - part ii
ClassName.VariableName
Program

Class-object

A

Method

X

Y
 java programming basics - part ii
 java programming basics - part ii
 java programming basics - part ii
 java programming basics - part ii

More Related Content

PDF
Operators in java
Muthukumaran Subramanian
 
PPTX
Java - Collections framework
Riccardo Cardin
 
PPS
Wrapper class
kamal kotecha
 
PPT
How to execute a C program
Leela Koneru
 
PDF
Contravariant functors in scala
Piotr Paradziński
 
PDF
Operator overloading C++
Lahiru Dilshan
 
PPTX
Polymorphism in c++(ppt)
Sanjit Shaw
 
PPTX
Array in c programming
Mazharul Islam
 
Operators in java
Muthukumaran Subramanian
 
Java - Collections framework
Riccardo Cardin
 
Wrapper class
kamal kotecha
 
How to execute a C program
Leela Koneru
 
Contravariant functors in scala
Piotr Paradziński
 
Operator overloading C++
Lahiru Dilshan
 
Polymorphism in c++(ppt)
Sanjit Shaw
 
Array in c programming
Mazharul Islam
 

What's hot (20)

PPTX
Polymorphism presentation in java
Ahsan Raja
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPTX
Control structures in java
VINOTH R
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPT
Enumerated data types in C
Arpana shree
 
PPTX
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
PPT
Final keyword in java
Lovely Professional University
 
PPTX
This keyword in java
Hitesh Kumar
 
PDF
Python-03| Data types
Mohd Sajjad
 
PPTX
Programming in c Arrays
janani thirupathi
 
PPT
Wrapper class (130240116056)
Akshay soni
 
PPTX
Introduction to OOP in Python
Aleksander Fabijan
 
PPT
Data types
myrajendra
 
PPTX
Standard Template Library
GauravPatil318
 
PPSX
Function in c
savitamhaske
 
PPT
Introduction to Python - Part Three
amiable_indian
 
PPTX
Java class,object,method introduction
Sohanur63
 
PDF
Java variable types
Soba Arjun
 
PDF
Strings in java
Kuppusamy P
 
PPTX
Data types in python
RaginiJain21
 
Polymorphism presentation in java
Ahsan Raja
 
Data Types & Variables in JAVA
Ankita Totala
 
Control structures in java
VINOTH R
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Enumerated data types in C
Arpana shree
 
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Final keyword in java
Lovely Professional University
 
This keyword in java
Hitesh Kumar
 
Python-03| Data types
Mohd Sajjad
 
Programming in c Arrays
janani thirupathi
 
Wrapper class (130240116056)
Akshay soni
 
Introduction to OOP in Python
Aleksander Fabijan
 
Data types
myrajendra
 
Standard Template Library
GauravPatil318
 
Function in c
savitamhaske
 
Introduction to Python - Part Three
amiable_indian
 
Java class,object,method introduction
Sohanur63
 
Java variable types
Soba Arjun
 
Strings in java
Kuppusamy P
 
Data types in python
RaginiJain21
 
Ad

Viewers also liked (11)

KEY
From Prospect To Production In 30 Days
E Carter
 
KEY
Python Is Rad
E Carter
 
PPTX
Teaching Kids Programming using Agile Practices
Lynn Langit
 
PDF
Intro to Python
OSU Open Source Lab
 
PDF
Kids liketocode
mcd_boulanger
 
PDF
CON 3431 - Introducing Java Programming to Kids
Arun Gupta
 
ODP
Introduction to Python - Training for Kids
Aimee Maree
 
PDF
Teach your kids how to program with Python and the Raspberry Pi
Juan Gomez
 
PDF
Intro to Python
Daniel Greenfeld
 
PDF
Kids computer-programming
Edward Burns
 
PPTX
Coding for Teachers and Kids Workshop Presentation
Joanne Villis
 
From Prospect To Production In 30 Days
E Carter
 
Python Is Rad
E Carter
 
Teaching Kids Programming using Agile Practices
Lynn Langit
 
Intro to Python
OSU Open Source Lab
 
Kids liketocode
mcd_boulanger
 
CON 3431 - Introducing Java Programming to Kids
Arun Gupta
 
Introduction to Python - Training for Kids
Aimee Maree
 
Teach your kids how to program with Python and the Raspberry Pi
Juan Gomez
 
Intro to Python
Daniel Greenfeld
 
Kids computer-programming
Edward Burns
 
Coding for Teachers and Kids Workshop Presentation
Joanne Villis
 
Ad

Similar to java programming basics - part ii (20)

PPTX
5. variables & data types
M H Buddhika Ariyaratne
 
PPSX
Java session3
Jigarthacker
 
PPTX
L2 datatypes and variables
teach4uin
 
PPTX
JAVA LESSON-01.pptx
StephenOczon1
 
DOC
Week2 dq3
amaxwell2012
 
PPTX
Computer programming 2 Lesson 5
MLG College of Learning, Inc
 
DOCX
data types in java will help to clear the base
ashwinibhosale27
 
PPTX
java Basic Programming Needs
Raja Sekhar
 
PPTX
Advanced java programming - DATA TYPES, VARIABLES, ARRAYS
vijayalakshmis184431
 
PPTX
Java - Basic Datatypes.pptx
Nagaraju Pamarthi
 
PDF
Java data types, variables and jvm
Madishetty Prathibha
 
PPTX
Java data types
AbhishekMondal42
 
PPTX
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
PPTX
DATA TYPES in Python done by Sanajai of MCA
JPrince9
 
PPT
Md03 - part3
Rakesh Madugula
 
PPTX
OOP-java-variables.pptx
ssuserb1a18d
 
PDF
Sdtl manual
qaz8989
 
PPTX
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
AhmedMehmood35
 
5. variables & data types
M H Buddhika Ariyaratne
 
Java session3
Jigarthacker
 
L2 datatypes and variables
teach4uin
 
JAVA LESSON-01.pptx
StephenOczon1
 
Week2 dq3
amaxwell2012
 
Computer programming 2 Lesson 5
MLG College of Learning, Inc
 
data types in java will help to clear the base
ashwinibhosale27
 
java Basic Programming Needs
Raja Sekhar
 
Advanced java programming - DATA TYPES, VARIABLES, ARRAYS
vijayalakshmis184431
 
Java - Basic Datatypes.pptx
Nagaraju Pamarthi
 
Java data types, variables and jvm
Madishetty Prathibha
 
Java data types
AbhishekMondal42
 
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
DATA TYPES in Python done by Sanajai of MCA
JPrince9
 
Md03 - part3
Rakesh Madugula
 
OOP-java-variables.pptx
ssuserb1a18d
 
Sdtl manual
qaz8989
 
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
AhmedMehmood35
 

More from jyoti_lakhani (20)

PPSX
CG02 Computer Graphic Systems.ppsx
jyoti_lakhani
 
PPTX
Projections.pptx
jyoti_lakhani
 
PPSX
CG04 Color Models.ppsx
jyoti_lakhani
 
PPSX
CG03 Random Raster Scan displays and Color CRTs.ppsx
jyoti_lakhani
 
PPTX
CG02 Computer Graphic Systems.pptx
jyoti_lakhani
 
PPSX
CG01 introduction.ppsx
jyoti_lakhani
 
PDF
Doubly linked list
jyoti_lakhani
 
PDF
Double ended queue
jyoti_lakhani
 
PDF
Tree terminology and introduction to binary tree
jyoti_lakhani
 
PDF
Priority queue
jyoti_lakhani
 
PDF
Ds006 linked list- delete from front
jyoti_lakhani
 
PPSX
Ds06 linked list- insert a node after a given node
jyoti_lakhani
 
PPSX
Ds06 linked list- insert a node at end
jyoti_lakhani
 
PPSX
Ds06 linked list- insert a node at beginning
jyoti_lakhani
 
PPSX
Ds06 linked list- intro and create a node
jyoti_lakhani
 
PPSX
Ds04 abstract data types (adt) jyoti lakhani
jyoti_lakhani
 
PPSX
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 
PPSX
Ds03 algorithms jyoti lakhani
jyoti_lakhani
 
PPSX
Ds02 flow chart and pseudo code
jyoti_lakhani
 
PPSX
Ds01 data structure introduction - by jyoti lakhani
jyoti_lakhani
 
CG02 Computer Graphic Systems.ppsx
jyoti_lakhani
 
Projections.pptx
jyoti_lakhani
 
CG04 Color Models.ppsx
jyoti_lakhani
 
CG03 Random Raster Scan displays and Color CRTs.ppsx
jyoti_lakhani
 
CG02 Computer Graphic Systems.pptx
jyoti_lakhani
 
CG01 introduction.ppsx
jyoti_lakhani
 
Doubly linked list
jyoti_lakhani
 
Double ended queue
jyoti_lakhani
 
Tree terminology and introduction to binary tree
jyoti_lakhani
 
Priority queue
jyoti_lakhani
 
Ds006 linked list- delete from front
jyoti_lakhani
 
Ds06 linked list- insert a node after a given node
jyoti_lakhani
 
Ds06 linked list- insert a node at end
jyoti_lakhani
 
Ds06 linked list- insert a node at beginning
jyoti_lakhani
 
Ds06 linked list- intro and create a node
jyoti_lakhani
 
Ds04 abstract data types (adt) jyoti lakhani
jyoti_lakhani
 
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 
Ds03 algorithms jyoti lakhani
jyoti_lakhani
 
Ds02 flow chart and pseudo code
jyoti_lakhani
 
Ds01 data structure introduction - by jyoti lakhani
jyoti_lakhani
 

Recently uploaded (20)

PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Software Development Methodologies in 2025
KodekX
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Software Development Company | KodekX
KodekX
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Software Development Methodologies in 2025
KodekX
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Software Development Company | KodekX
KodekX
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 

java programming basics - part ii

  • 4. Variables are nothing but reserved memory locations to store values A Variable has – Memory Address Name a 10 10110 Value int a=10;
  • 5. There are two data types available in Java: •Primitive Data Types •Reference/Non Primitive/ Derived Data Types
  • 7. There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a keyword
  • 8. Byte data type is an 8-bit signed 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 int Example: byte a = 100 , byte b = -50
  • 9. Short data type is a 16-bit signed integer Minimum value is -32,768 (-2^15) Maximum value is 32,767 (inclusive) (2^15 -1) Short data type can also be used to save memory as byte data type A short is 2 times smaller than an int Default value is 0 Example: short s = 10000, short r = -20000
  • 10. Int data type is a 32-bit signed integer Minimum value is - 2,147,483,648.(-2^31) Maximum value is 2,147,483,647(inclusive).(2^31 -1) Int 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 = 100000, int b = -200000
  • 11. Long data type is a 64-bit signed integer Minimum value is -9,223,372,036,854,775,808.(-2^63) Maximum value is 9,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. Example: long a = 100000L, int b = -200000L
  • 12. 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
  • 13. 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 Example: double d1 = 123.4
  • 14. 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
  • 15. 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 ='A'
  • 16. Reference variables are created using defined constructors of the classes They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy etc. Class objects, and various type of array variables come under reference data type Default value of any reference variable is null A reference variable can be used to refer to any object of the declared type or any compatible type Example: Animal animal = new Animal("giraffe");
  • 18. In Java, all variables must be declared before they can be used. The basic form of a variable declaration is shown here: type identifier [ = value][, identifier [= value] ...] ; The type is one of Java's datatypes. The identifier is the name of the variable. To declare more than one variable of the specified type, use a comma-separated list. Here are several examples of variable declarations of various types. Note that some include an initialization int a, b, c; // declares three ints, a, b, and c int d = 3, e, f = 5; // declares three more ints, initializing d and f byte z = 22; // initializes z double pi = 3.14159; // declares an approximation of pi char x = 'x'; // the variable x has the value 'x'