SlideShare a Scribd company logo
OOP - JAVA
Variables in Java
4/6/2022 1
Department of Computer
PRO – GRADE 5
Lecturer. OMEED M. M
Table of contents
 What is Variable?
 Allocating memory
 Types of variables
 Constructor
4/6/2022 2
Variable in Java
Variables used to store in our computer’s memory
Why called it variable?
Because the values inside the variables are changeable.
 Attributes - things that the object stores data in, generally
variables.
 Methods - Functions and Procedures attached to an Object and
allowing the object to perform actions
4/6/2022 3
Allocating memory
In order to store some data in our computer memory we have to
allocate some space so how we can do that? we will go through
allocating memory,
4/6/2022 4
Allocating memory
For this purpose we have to declare variables.
How we can declare variable we are going to using assignment
We can assign a value to a variable by using (Equal =) operator.
Ex.
String ANY_NAME = “ANY_NAME”
4/6/2022 5
Variable in Java
• Re-difine variable
4/6/2022 6
Variable in Java
• Println
4/6/2022 7
Types of variables
There are Three type of variables:-
1. Instance variables
2. Local variables
3. Class variables (Static variables)
4/6/2022 8
Instance variables
Instance variables Declared inside class but not inside method.
Ex.
Class test{
Int data=15; //instance variable
Float pi=3.114f; //instance variable
}
Cannot be reinitialized directly within class
Ex.
Class test{
Int data=15; //instance variable
data =20; //Error for correction we have to put it into a method
void testMethod(){
data=20 // correct;
} }
4/6/2022 9
Local variables
Local variables – Declared inside method or method parameters.
Ex.
Int areatest (int radius){
Int total = radius * radius;
Return total;
}
-These are not accessible outside method.
-They did not get default values.
4/6/2022 10
Class / Static variables
Class variables − are variables declared within a class, outside any
method, with the static keyword
-Static variable is shared between all objects because it belong to
the class. It does not belong to the object
-A static variable can be accessed without creating an instance of the
class.
4/6/2022 11
Constructor
A constructor in Java is similar to a method that is invoked when an
object of the class is created.
Unlike Java methods, a constructor has the same name as that of the
class and does not have any return type. For example,
class Test {
Test() {
// constructor body
}
}
4/6/2022 12
Types of variables
class A{
int date=50; //_________ variable
static int m=100; //_________ variable
void method(){
int n=90; //________ variable
}
} //end of class
4/6/2022 13
Any Questions ?
4/6/2022 14

More Related Content

PPTX
Java Chapter 04 - Writing Classes: part 3
DanWooster1
 
PPT
Chapter 5 declaring classes & oop
sshhzap
 
DOCX
Smu mscit sem 2 fall 2015 solved assignments
smumbahelp
 
PPT
3 java - variable type
vinay arora
 
PPTX
C# Basics
Binu Bhasuran
 
PPTX
Method of java
Niloy Biswas
 
PPTX
Object oriented architecture in erp
Preyanshu Saini
 
PPTX
Java Basic
Mahmudul Hasan
 
Java Chapter 04 - Writing Classes: part 3
DanWooster1
 
Chapter 5 declaring classes & oop
sshhzap
 
Smu mscit sem 2 fall 2015 solved assignments
smumbahelp
 
3 java - variable type
vinay arora
 
C# Basics
Binu Bhasuran
 
Method of java
Niloy Biswas
 
Object oriented architecture in erp
Preyanshu Saini
 
Java Basic
Mahmudul Hasan
 

Similar to OOP using java (Variable in java) (20)

PPTX
Computer programming 2 Lesson 6
MLG College of Learning, Inc
 
PPTX
Data types ^J variables and arrays in Java.pptx
sksumayasumaya5
 
PDF
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
Indu32
 
PDF
7. VARIABLEs presentation in java programming. Pdf
simukondasankananji8
 
PPTX
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
PPTX
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
PPTX
Module 4_Chapter One - Java Methods.pptx
jhesorleylaid2
 
PPTX
Learning Java 2 - Variables, Data Types and Operators
MinhNguyen1493
 
DOCX
Java sessionnotes
Lakshmi Sarvani Videla
 
PDF
Java unit 7
Shipra Swati
 
PPT
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
PPTX
javaClasses.pptx
MattMarino13
 
PPTX
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
PPT
Ppt chapter05
Richard Styner
 
PPTX
Constant a,variables and data types
mithilesh kumar
 
PPTX
Introduction to JcjfjfjfkuutyuyrsdterdfbvAVA.pptx
patilrohini0224
 
PPTX
Unit-1 Data Types and Operators.pptx to computers
csangani1
 
PPTX
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
berihun18
 
PPT
packages and interfaces
madhavi patil
 
PPTX
Classes,object and methods java
Padma Kannan
 
Computer programming 2 Lesson 6
MLG College of Learning, Inc
 
Data types ^J variables and arrays in Java.pptx
sksumayasumaya5
 
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
Indu32
 
7. VARIABLEs presentation in java programming. Pdf
simukondasankananji8
 
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Module 4_Chapter One - Java Methods.pptx
jhesorleylaid2
 
Learning Java 2 - Variables, Data Types and Operators
MinhNguyen1493
 
Java sessionnotes
Lakshmi Sarvani Videla
 
Java unit 7
Shipra Swati
 
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
javaClasses.pptx
MattMarino13
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
Ppt chapter05
Richard Styner
 
Constant a,variables and data types
mithilesh kumar
 
Introduction to JcjfjfjfkuutyuyrsdterdfbvAVA.pptx
patilrohini0224
 
Unit-1 Data Types and Operators.pptx to computers
csangani1
 
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
berihun18
 
packages and interfaces
madhavi patil
 
Classes,object and methods java
Padma Kannan
 
Ad

More from omeed (15)

PPTX
understanding of java basics
omeed
 
PPTX
Introduction to oop using java
omeed
 
PPTX
Asp.net LinkButton & imageButton controls
omeed
 
PPTX
Asp.net CheckBoxList control
omeed
 
PPTX
Asp.net CheckBox control
omeed
 
PPTX
Asp.net RadiobuttonList control
omeed
 
PPTX
Asp.net Radiobutton control
omeed
 
PPTX
Asp.net textbox control
omeed
 
PPTX
Understanding of Asp.net & page lifecycle
omeed
 
PPTX
Asp.net introduction to web development
omeed
 
PPTX
WEB DEVELOPMENT Using Python programming language
omeed
 
PDF
Apple’s AI-Powered Personal Assistant Uses DNN - siri
omeed
 
PPTX
Third and fourth generation programming language
omeed
 
DOCX
analog clock C#
omeed
 
PPTX
graphic Design
omeed
 
understanding of java basics
omeed
 
Introduction to oop using java
omeed
 
Asp.net LinkButton & imageButton controls
omeed
 
Asp.net CheckBoxList control
omeed
 
Asp.net CheckBox control
omeed
 
Asp.net RadiobuttonList control
omeed
 
Asp.net Radiobutton control
omeed
 
Asp.net textbox control
omeed
 
Understanding of Asp.net & page lifecycle
omeed
 
Asp.net introduction to web development
omeed
 
WEB DEVELOPMENT Using Python programming language
omeed
 
Apple’s AI-Powered Personal Assistant Uses DNN - siri
omeed
 
Third and fourth generation programming language
omeed
 
analog clock C#
omeed
 
graphic Design
omeed
 
Ad

Recently uploaded (20)

PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PDF
High Ground Student Revision Booklet Preview
jpinnuck
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
High Ground Student Revision Booklet Preview
jpinnuck
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
Landforms and landscapes data surprise preview
jpinnuck
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 

OOP using java (Variable in java)

  • 1. OOP - JAVA Variables in Java 4/6/2022 1 Department of Computer PRO – GRADE 5 Lecturer. OMEED M. M
  • 2. Table of contents  What is Variable?  Allocating memory  Types of variables  Constructor 4/6/2022 2
  • 3. Variable in Java Variables used to store in our computer’s memory Why called it variable? Because the values inside the variables are changeable.  Attributes - things that the object stores data in, generally variables.  Methods - Functions and Procedures attached to an Object and allowing the object to perform actions 4/6/2022 3
  • 4. Allocating memory In order to store some data in our computer memory we have to allocate some space so how we can do that? we will go through allocating memory, 4/6/2022 4
  • 5. Allocating memory For this purpose we have to declare variables. How we can declare variable we are going to using assignment We can assign a value to a variable by using (Equal =) operator. Ex. String ANY_NAME = “ANY_NAME” 4/6/2022 5
  • 6. Variable in Java • Re-difine variable 4/6/2022 6
  • 7. Variable in Java • Println 4/6/2022 7
  • 8. Types of variables There are Three type of variables:- 1. Instance variables 2. Local variables 3. Class variables (Static variables) 4/6/2022 8
  • 9. Instance variables Instance variables Declared inside class but not inside method. Ex. Class test{ Int data=15; //instance variable Float pi=3.114f; //instance variable } Cannot be reinitialized directly within class Ex. Class test{ Int data=15; //instance variable data =20; //Error for correction we have to put it into a method void testMethod(){ data=20 // correct; } } 4/6/2022 9
  • 10. Local variables Local variables – Declared inside method or method parameters. Ex. Int areatest (int radius){ Int total = radius * radius; Return total; } -These are not accessible outside method. -They did not get default values. 4/6/2022 10
  • 11. Class / Static variables Class variables − are variables declared within a class, outside any method, with the static keyword -Static variable is shared between all objects because it belong to the class. It does not belong to the object -A static variable can be accessed without creating an instance of the class. 4/6/2022 11
  • 12. Constructor A constructor in Java is similar to a method that is invoked when an object of the class is created. Unlike Java methods, a constructor has the same name as that of the class and does not have any return type. For example, class Test { Test() { // constructor body } } 4/6/2022 12
  • 13. Types of variables class A{ int date=50; //_________ variable static int m=100; //_________ variable void method(){ int n=90; //________ variable } } //end of class 4/6/2022 13