Java - Introduction To Programming: 1. Variables
Java - Introduction To Programming: 1. Variables
Lecture 2
1. Variables
A variable is a container (storage area) used to hold data.
Each variable should be given a unique name (identifier).
package com.apnacollege;
2. Data Types
Data types are declarations for variables. This determines the type and size of
data associated with variables which is essential to know since different data
types occupy different sizes of memory.
Apna College
Data Type Meaning Size Range
(in Bytes)
char Character 2 a, b, c ..
A, B, C ..
@, #, $ ..
Eg : String, Arrays
3. Constants
A constant is a variable in Java which has a fixed value i.e. it cannot be assigned
a different value once assigned.
Apna College
package com.apnacollege;
Homework Problems
1. Try to declare meaningful variables of each type. Eg - a variable
named age should be a numeric type (int or float) not byte.
(HINT - You will have to write 10 lines for this but as we proceed in
the course you will be studying about ‘LOOPS’ that will simplify your
work A LOT!)
Apna College