ing these transactions, the business logic holds data in some variables. That means these
data are in computer memory.
Once the business transaction gets completed and data has been written into the database
then all the values which variables were holding in the business logic are reset. Now the
variables should not keep any values and should be ready for next transactions.
This kind of behavior of variables and their associated programs is known as stateless vari-
ables and programs. This is the default behavior of all computer programs. All computer
programs are written this way. All computer programs are written such that after doing
transactions in the database, all variables are reset and hold no values.
On the other hand if data persist in variables and computer programs even after doing trans-
action in the database then these variables and programs are known as statefull variables
In most cases, stateless programs should be used. But in some cases, statefull programs are
Let us consider a web application. The user clicks on a link on a web page. This link leads
to another web page. The information about the user will be lost as the old web page has
closed. How the user information should be stored so that it is available on the new page?
One way is to use a session object which keeps user data. As long as the user is browsing
on a website (including its web pages), the user data is available in the session object.
Data on a web page is stateless. It is because HTTP protocol used by web pages are always
stateless. That means user data on a web page only exists as long as the user is on a web
page. The moment the user leaves that web page, the user data is lost. A web page is a
DOM object and when a page is closed then the object is destroyed. The data with this
object is also gets destroyed. To tackle this problem techniques like session variables are
used. A session object is created when the user first visits a website. This object is kept
alive as long as the user is on the website.
When you create objects you can make them either stateless or statefull. Objects when cre-
ated occupy some memory space. When any object is no longer used then it is garbage col-
lected and destroyed. When an object is destroyed then all the values it holds also get lost.
But during the period when an object is live, it will have values inside its structure of data.
This data is manipulated by other programs which interact with it or through user inputs.
At any given point of time, many users or other programs (objects) may be accessing it and