Stateless - There's no memory (state) that's maintained by the program
Stateful - The program has a memory (state)
To illustrate the concept of state I'll define a function which is stateful and one which is stateless
Stateless
//The state is derived by what is passed into the function
function int addOne(int number)
{
return number + 1;
}
Stateful
//The state is maintained by the function
private int _number = 0; //initially zero
function int addOne()
{
_number++;
return _number;
}
As others have said http is inherently stateless. So state must be built into your applications.
Imagine a request over the web where you have a client browser communicating to a server process. To maintain state over the stateless http protocol the browser will send typically send a session identifier to the server on each request. For each request the server will be like "ah, its this guy". State information can then be looked up in server side memory or in a database based on this session id.
In a purely stateless environment you wouldn't need this session id. Each request would contain all the information the server would need to process. But many applications need to maintain state to keep track of whether or not a session is authenticated to view certain content or to keep track of what a user is doing. You wouldn't want to send user credentials over the wire for each request.