Java Lecture 2
Java Lecture 2
Lab 2
1. Variables
A variable is a container (storage area) used to hold data.
Each variable should be given a unique name (identifier).
Import java.utils.*;
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.
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.
imports java.utils.*;
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.
2. Make a program that takes the radius of a circle as input, calculates its
radius and area and prints it as output to the user.
3. Make a program that prints the table of a number that is input by the user.
(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!)