SlideShare a Scribd company logo
16
Most read
19
Most read
20
Most read
JAVA
VARIABLES- TYPES
DATA TYPES
1Prepared by
P.PRATHIBHA
Topics for Today’s Session
About JAVA
JVM
DATA TYPES
Variables
Type Casting
Types of Variables
AboutJava
 Java is a computing platform for application
development and an object-oriented,
 Java is Class-based and Concurrent programming
language 
 It means the code can be executed by multiple
processes at the same time.
 Java can run on all platforms and free to access.
 Java is Simple, Secure, Robust, Complete Object
oriented and Platform Independent High level
Language
 It is Portable and Multi-thread technology gives
High Performance.
 JAVA VIRTUAL MACHINE    (JVM)
vJava compiler produce an intermediatry code known as
byte code for a machine.
vThis machine is called the JVM, it exist only inside the
computer memory.
v The process of compiling a java program into byte code is
referred to as Virtual Machine code.
v The virtual machine code is not machine specific.
v The machine code is generated by the Java Interpreter,
by acting as an intermediary between the virtual
machine and the real machine.
Variables
v Variable is an identifier, which denotes a storage location used to store a
data value
v A variable is a container which holds the value while the Java program is
executed.
v A variable is assigned with a data type.
v Variable is a name of memory location.
v It is a combination of vary + able that means its value can be changed.
v Declaring (Creating) Variables
Syntax: type variable = value;
Where type is one of Java's types (such as int or String), and 
variable is the name of the variable (such as x or name).
The equal sign is used to assign values to the variable.
Example: String name = John;
char ch = 'A';
int number = 100;
Variable Naming conventions
1) Variable names may consists letters, digits, _(underscore) 
 dollar ($).
2)  Variables naming cannot contain white spaces, 
  for example: int num ber = 100; // is invalid
      because the variable name has space in it.
3) Variable name can begin with special characters such as $ 
and _
4)  As per the java coding standards the variable name should 
begin with a lower case letter, 
for example: int num; 
5) Variable names are case sensitive in Java.
6) It should not be a Keyword.
7)  Variable names can be of any length.
LocalVariables
InstanceVariables
StaticVariables
Types / Scope of Variables
v There are three types of variables in java:
1. Local Variable
 A variable defined within a block or method or constructor 
is called local variable.
 The scope of these variables exists only within the block in 
which the variable is declared. i.e. we can access these 
variable only within that block.
 A local variable cannot be defined with static keyword.
 These variable are created when the block in entered or the 
function is called and destroyed after exiting from the block 
or when the call returns from the function.
 Initialization of Local Variable is Mandatory.
2. Instance Variable
v Instance variables are non-static variables.
v A variable declared inside the class but outside the body of 
the method, Constructor or Block. 
v These  variables are created when an  object  of  the  class  is 
created and destroyed when the object is destroyed.
v Each instance(objects) of class has its own copy of instance 
variable.
v It  is  called  instance  variable  because  its  value  is  instance 
specific and is not shared among instances.
v Initialization  of  Instance  Variable  is  not  Mandatory.  Its 
default value is 0.
v Instance Variable can be accessed only by creating objects.
3. Static Variables:
Ø Static variables are also known as Class variables.
Ø Static variables are declared using the static keyword within a
class, outside any method constructor or block.
Ø It cannot be local.
Ø You can create a single copy of static variable and share among
all the instances of the class.
Ø Memory allocation for static variable happens only once when
the class is loaded in the memory.
 Static variables are created at the start of program execution
and destroyed automatically when execution ends.
 Initialization of Static Variable is not Mandatory. Its default
value is zero (0).
 Static variables can be accessed by class name, not by object.
For example, If I create 4 objects of a class and access this static
variable, it would be common for all, the changes made to the
variable using one of the object would reflect when you access
it through other objects.
Example: Using variables
class A
{  
int  d=30; //instance variable  
static int m=100; //static variable  
void method()
{  
int  m=20; //local variable  
}  
} //end of class  
Type Casting
Ø Type casting is nothing but assigning a value of one primitive
data type to another.
Ø When you assign the value of one data type to another, you
should be aware of the compatibility of the data type.
Ø If they are compatible, then Java will perform the conversion
automatically known as Automatic Type Conversion 
Ø And if not, then they need to be casted or converted explicitly.
Syntax:
Ø Four integer types can be cast to any other type except Boolean.
Ø Casting into a smaller type may result in a loss of data.
Ø Similarly, the float  double can be cast to any other type except
Boolean.
Ø There are two types of casting in Java :
type variable1= (type) variable
1. Widening Casting (automatically) – converting a smaller type
to a larger type size, this type of conversion is called Implicit
conversion.
2. Narrowing Casting (manually) – converting a larger type to a
smaller size type, this type of conversion is Explicit conversion.
From To
byte short, char, int, long, float, double
short int, long, float, double
char int, long, float, double
int long, float, double
long float, double
float double
Example:
int i = 258;
 long l = i; //automatic type conversion
float f = l; //automatic type conversion
double d = 345.06;
  long l = (long)d; //explicit type casting
int i = (int)l; //explicit type casting
Data Types in Java
 Data type defines the values that a variable can take
 Data types specify the different sizes and values that can be
stored in the variable.
 In java, data types are classified into 2 categories :
1. Primitive Data type
2. Non-Primitive Data type
Primitive data types
 Primitive data types are the building blocks of data manipulation.
 These are the most basic data types available in Java.
 Java developers included these data types to maintain the portability of
java as the size of these primitive data types do not change from one
operating system to another.
 There are 8 types of primitive data types:
1. boolean data type
2. byte data type
3. char data type
4. short data type
5. int data type
6. long data type
7. float data type
8. double data type
Data Type Size Description Default
byte 1 byte Stores whole numbers from -128 
to 127
0
short 2 bytes Stores whole numbers from -
32,768 to 32,767
0
int 4 bytes Stores whole numbers from -
2,147,483,648 to 2,147,483,647
0
long 8 bytes Stores whole numbers from -
9,223,372,036,854,775,808 to 
9,223,372,036,854,775,807
0L
float 4 bytes Stores fractional numbers. 
Sufficient for storing 6 to 7 
decimal digits
0.0f
double 8 bytes Stores fractional numbers. 
Sufficient for storing 15 decimal 
digits
0.0d
boolean 1 bit Stores true or false values false
char 2 bytes Stores a single character/letter 
or ASCII values
‘u0000’
Non-Primitive Data Types
 Non-Primitive data types refer to objects and hence they
are called reference types.
 Non-primitive types include Strings, Arrays, Classes,
Interface, etc.
Strings
Arrays
Interfaces
Classes
Non-
Primitive
Data types
Strings: String is a sequence of characters.
 used to store consecutive characters or proper 
sentences 
 But in Java, a string is an object that represents a 
sequence of characters. 
 The java.lang.String class is used to create a string 
object. 
Example:  String abc = “Satwika likes music;
Arrays:  Arrays in Java are homogeneous data structures
implemented in Java as objects.
Ø Arrays store one or more values o f a specific data type
and provide indexed access to store the same. A specific
element in an array is accessed by its index.
 It can store any type of data as the size of the array
is also declared by the programmer.
Classes:  Classes are used to create objects
 A class in Java is a blueprint which includes all your 
data.  
 A class contains fields(variables) and methods to 
describe the behavior of an object.
Interface:  An interface is like a dashboard or control 
panel for a class. 
Ø It has buttons/functions for the data types 
defined, but the implementation is somewhere 
else.
Ø  Like a class, an interface can have methods and 
variables, but the methods declared 
in interface are by default abstract (only method 
signature, no body).
Difference between primitive and non-primitive data types
 Primitive  types  are  predefined.  Non-primitive  types  are 
created by the programmer and is not defined by Java (except 
for String).
 Non-primitive types  can  be  used  to  call  methods  to  perform 
certain operations, while primitive types cannot.
 A primitive type has always a value, while non-primitive types 
can be null.
 A  primitive  type  starts  with  a  lowercase  letter,  while  non-
primitive types starts with an uppercase letter.
 The size of a primitive type depends on the data type, while 
non-primitive types have all the same size.
Summary
 In this lesson you learnt about
 About Java?
 Java Virtual Machine
 Variables
 Types / Scope of variables
 Type Casting
 Data Types
Java data types, variables and jvm

More Related Content

PPT
Data types
myrajendra
 
PDF
Java variable types
Soba Arjun
 
PPTX
Java Methods
OXUS 20
 
PPS
Wrapper class
kamal kotecha
 
PPS
Introduction to class in java
kamal kotecha
 
PPTX
Java Foundations: Methods
Svetlin Nakov
 
PDF
Command line-arguments-in-java-tutorial
Kuntal Bhowmick
 
PPTX
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Data types
myrajendra
 
Java variable types
Soba Arjun
 
Java Methods
OXUS 20
 
Wrapper class
kamal kotecha
 
Introduction to class in java
kamal kotecha
 
Java Foundations: Methods
Svetlin Nakov
 
Command line-arguments-in-java-tutorial
Kuntal Bhowmick
 
Data Types, Variables, and Operators
Marwa Ali Eissa
 

What's hot (20)

PPTX
Control statements in java
Madishetty Prathibha
 
PPTX
Java Method, Static Block
Infoviaan Technologies
 
PPTX
Arrays in java
Arzath Areeff
 
PPTX
Java constructors
QUONTRASOLUTIONS
 
PPTX
Java Tokens
Madishetty Prathibha
 
PPS
String and string buffer
kamal kotecha
 
PPTX
Core java complete ppt(note)
arvind pandey
 
PPTX
Java package
CS_GDRCST
 
PPTX
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
PDF
Strings in java
Kuppusamy P
 
PPTX
Java Data Types
Spotle.ai
 
PDF
Arrays in Java
Naz Abdalla
 
PPTX
Java Strings
RaBiya Chaudhry
 
PPTX
Type casting in java
Farooq Baloch
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPTX
Classes objects in java
Madishetty Prathibha
 
PPTX
Union in c language
tanmaymodi4
 
PPTX
Introduction to Java Strings, By Kavita Ganesan
Kavita Ganesan
 
PPTX
Python programming
Ashwin Kumar Ramasamy
 
PPTX
Java basics and java variables
Pushpendra Tyagi
 
Control statements in java
Madishetty Prathibha
 
Java Method, Static Block
Infoviaan Technologies
 
Arrays in java
Arzath Areeff
 
Java constructors
QUONTRASOLUTIONS
 
String and string buffer
kamal kotecha
 
Core java complete ppt(note)
arvind pandey
 
Java package
CS_GDRCST
 
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
Strings in java
Kuppusamy P
 
Java Data Types
Spotle.ai
 
Arrays in Java
Naz Abdalla
 
Java Strings
RaBiya Chaudhry
 
Type casting in java
Farooq Baloch
 
Data Types & Variables in JAVA
Ankita Totala
 
Classes objects in java
Madishetty Prathibha
 
Union in c language
tanmaymodi4
 
Introduction to Java Strings, By Kavita Ganesan
Kavita Ganesan
 
Python programming
Ashwin Kumar Ramasamy
 
Java basics and java variables
Pushpendra Tyagi
 
Ad

Similar to Java data types, variables and jvm (20)

PPTX
OOP-java-variables.pptx
ssuserb1a18d
 
PPTX
L2 datatypes and variables
teach4uin
 
PDF
7-Java Language Basics Part1
Amr Elghadban (AmrAngry)
 
PPTX
Core java
Shivaraj R
 
PPTX
Core java
Sun Technlogies
 
PPTX
JAVA LESSON-01.pptx
StephenOczon1
 
PPTX
Java data types
AbhishekMondal42
 
PPTX
Unit-1 Data Types and Operators.pptx to computers
csangani1
 
PPTX
a variable in Java must be a specified data type
Kavitha S
 
PPTX
Java Data Types and Variables
sasi saseenthiran
 
PPTX
Advanced java programming - DATA TYPES, VARIABLES, ARRAYS
vijayalakshmis184431
 
PPTX
Identifiers, keywords and types
Daman Toor
 
PPSX
Java session3
Jigarthacker
 
PPTX
Java fundamentals
Jayfee Ramos
 
PPTX
This is a python data types ppt it is used for bca student also
sandhiyamaliga2005
 
PDF
2._Java_Syntax_and_Data_Type.pptx.pdf
luxasuhi
 
PPTX
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
PPTX
Computer Programming Java Data Types.pptx
MarianneIsid
 
PPTX
Java Basic
Mahmudul Hasan
 
PPTX
Data types ^J variables and arrays in Java.pptx
sksumayasumaya5
 
OOP-java-variables.pptx
ssuserb1a18d
 
L2 datatypes and variables
teach4uin
 
7-Java Language Basics Part1
Amr Elghadban (AmrAngry)
 
Core java
Shivaraj R
 
Core java
Sun Technlogies
 
JAVA LESSON-01.pptx
StephenOczon1
 
Java data types
AbhishekMondal42
 
Unit-1 Data Types and Operators.pptx to computers
csangani1
 
a variable in Java must be a specified data type
Kavitha S
 
Java Data Types and Variables
sasi saseenthiran
 
Advanced java programming - DATA TYPES, VARIABLES, ARRAYS
vijayalakshmis184431
 
Identifiers, keywords and types
Daman Toor
 
Java session3
Jigarthacker
 
Java fundamentals
Jayfee Ramos
 
This is a python data types ppt it is used for bca student also
sandhiyamaliga2005
 
2._Java_Syntax_and_Data_Type.pptx.pdf
luxasuhi
 
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
Computer Programming Java Data Types.pptx
MarianneIsid
 
Java Basic
Mahmudul Hasan
 
Data types ^J variables and arrays in Java.pptx
sksumayasumaya5
 
Ad

More from Madishetty Prathibha (11)

PPTX
Object Oriented programming - Introduction
Madishetty Prathibha
 
PPTX
Access modifiers in java
Madishetty Prathibha
 
PPTX
Constructor in java
Madishetty Prathibha
 
PPTX
Structure of java program diff c- cpp and java
Madishetty Prathibha
 
PPTX
Operators in java
Madishetty Prathibha
 
PPTX
Types of datastructures
Madishetty Prathibha
 
PPTX
Introduction to algorithms
Madishetty Prathibha
 
PPTX
Introduction to data structures (ss)
Madishetty Prathibha
 
PDF
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
PPT
Java features
Madishetty Prathibha
 
PPSX
Introduction of java
Madishetty Prathibha
 
Object Oriented programming - Introduction
Madishetty Prathibha
 
Access modifiers in java
Madishetty Prathibha
 
Constructor in java
Madishetty Prathibha
 
Structure of java program diff c- cpp and java
Madishetty Prathibha
 
Operators in java
Madishetty Prathibha
 
Types of datastructures
Madishetty Prathibha
 
Introduction to algorithms
Madishetty Prathibha
 
Introduction to data structures (ss)
Madishetty Prathibha
 
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Java features
Madishetty Prathibha
 
Introduction of java
Madishetty Prathibha
 

Recently uploaded (20)

PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Landforms and landscapes data surprise preview
jpinnuck
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 

Java data types, variables and jvm