Friday, June 12, 2015

Variables in java

9:48 AM

VARIABLES in java

“A variable is an identifier whose value will be changed during execution of the program”.
Rules for writing variables:
i. First letter must be an alphabet.
ii. The length of the variable should not exceed more than 32 characters.
iii. No special symbols are allowed except underscore.
iv. No keywords should use as variable names.
Types of variables in JAVA:
• Whenever we develop any JAVA program that will be developed with respect to class only.
• In a class we can use ‘n’ number of data members and ‘n’ number of methods.
• Generally in JAVA, we can use two types of data members or variables. They are
instance/non-static variables and static variables.



INSTANCE/NON-STATIC VARIABLES

1) An instance variable is one whose
memory space is creating each and
every time whenever an object is
created.
2) Programmatically instance variable
declaration should not be preceded
by keyword static.
3) Data type v1, v2…vn;
4) Instance variable must be accessed
with respect to object name i.e.,
objname.varname;
5) Value of instance variable is not
sharable.
6) Instance variable are also known as
object level data members since they
are dependent on objects.

STATIC VARIABLES

1) Static variables are whose memory
space is creating only once when the
class is loaded by class loader
subsystem (a part of JVM) in the main
memory irrespective of number of
objects.
2) Programmatically static variable
declaration must be preceded by
keyword static.
3) Static data type v1, v2…vn;
4) Static variables must be accessed
with respect to class name i.e.,
classname.varname;
5) Value of static variable is always
recommended for sharable.
6) Static variable are also known as class
level data members since they are
dependent on classes.

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 Java Tutorials. All rights resevered. Designed by Templateism

Back To Top