This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable static for a counter session active

 
Anais Aponte
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I am preparing for SCWCD,
I have a doubt in HFSJ book page 259, where give this example:



Is really necesary to declare the variable activeSessions static?
how many objects of this class create the Container for app web?
I think just one, so why to declare static??? :roll:

Thanks
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ACAC

You are right, there will be only one instance of this class.
Even if you don't declare it static.
It's not going to make any difference here.
As the variable is private too.

But suppose had it not been a private variable.
Then you can access this variable from anywhere just by using it's class name, BeerSessionCounter (being a static varible), and feed that data in your log file or somewhere else to keep record of number of sessions at that instance of time.

Regards,
Khushhal
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, what's your name, Mr. ACAC?

Write your full name.
That will look good and sound to you and to others too..

Regards,
Khushhal
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ACAC", we don't have many rules here at the Ranch but we do have a Naming Policy. Please update your display name accordingly.
 
Anais Aponte
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers. ACAC = Anais Cristina Aponte Castillo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic