• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

private static methods.

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.

Can anyone explain me how this can be done?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Abhishek Reddy Chepyala:
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable...


I don't think I understand this premise.

Can you show us where this came from?
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek -

The advantage of static methods is that they're independent of any particular class instance.

The opposite of a "static" method is an "instance" method. In Java, the default is "instance method": whenever you invoke that method, it is with respect to one - and only one - object instance.

You can have static methods ... or static member data.

I'm not sure how any of this relates to your original question:

The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.
<= HUH?!?



Frankly, I'd have to say that, although there might be a kernel of truth lurking in there someplace ... the above statement is basically nonsense.

IMHO .. PSM
[ September 23, 2006: Message edited by: Paul Santa Maria ]
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.

The above words are from "java.sun.com" tutorials under "Static Initialization Blocks" section here is the link http://java.sun.com/docs/books/tutorial/java/javaOO/initial.html
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah.

You can call a static method whenever you want, but a static initialization block is called only when the class is loaded. Therefore, static methods are somewhat more flexible. If a class has static data which may need to be re-initialized at some point, then it makes more sense to put that initialization code in a static method (perhaps calling it from a static initialization block!) so that the method can be called again at some other time.

You would have got your answer sooner if you had explained your question more.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see the missing piece now...

The advantage of private static methods [over static initialization blocks] is that they can be reused later if you need to reinitialize the class variable.
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Its cool and straight forward.

1) The static init. block will be called only once, that to at the time of class loading.

2) Static methods can be called when every you want.

3) Private Static ( you can call when ever you want from your class local methods and can initialize only static data).

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!