Professional Documents
Culture Documents
Lecture 7 - Get Started With Java
Lecture 7 - Get Started With Java
Lecture 7 - Get Started With Java
WITH JAVA
OUTLINE
• Variables
• Example
• Constants
• Escape Sequences
VARIABLES
• Variable is a name of memory location. There are three types of variables in java: local, instance
and static.
• Types of Variable: There are three types of variables in java:
• local variable: A variable which is declared inside the method is called local variable.
• instance variable: Instance variables in Java are non-static variables which are defined in a class
outside any method, constructor or a block. Each instantiated object of the class has a separate copy
or instance of that variable. An instance variable belongs to a class.
• static variable: A static variable is common to all the instances (or objects) of the class because it is a
class level variable. In other words you can say that only a single copy of static variable is created and
shared among all the instances of the class.
• We will have detailed learning of these variables in next lectures.
VARIABLES - EXAMPLE
• A constant is a variable whose value cannot change once it has been assigned. Java
doesn't have built-in support for constants.
• modifier final dataType variableName = value; //global constant
• For a simple floating point value (a number with a fractional part) like Pi, it would
look something like:
• private static final double PI = 3.1415926;
• The keyword 'private' indicates visibility, the keyword 'static' indicates the storage
class, and the keyword 'double' indicates the variable type. Ignore them for now,
they are beyond the scope of this lesson. The really important part is the keyword
'final'. This is what determines that the variable 'PI' is a constant. It says that for the
life of this variable, the value will not change.
ESCAPE SEQUENCES