Re: Singletons?

Mark Space <markspace@xxxxxxxxxxxxx> wrote in news:FEDjg.147331$F_3.107067

Hi all!

I'm trying out some new Java code. I was surprised to find that Java
doesn't allow the static keyword for classes. How was I to implement
singleton objects then? Well, a quick web search and I've got the
answer, but now I have a few other questions on the JVM and compiler.

Let's say I have a class entirely of static methods:

public class anAPI {
static void methodA {}
static void methodB {}

I don't know the answer to your questions, but you can sidestep the questions
by defining a no-argument constructor and giving it the "private" keyword.
This way, there is no way that this class can be instantiated unless one of
its own static methods does the deed. [Well, maybe there is a cheat via

Your questions are still valid, and I am interested in the answers myself.

Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *

Relevant Pages

  • Re: Singletons?
    ... but the semantics of the static keyword here have nothing to do with the Singleton design pattern. ... It takes a constructor as its single argument, and creates a new instance of the object, then calls the constructor on that instance. ...
  • Singletons?
    ... I'm trying out some new Java code. ... What happens if new is called for anAPI? ... It seems to me a smart compiler and JVM would figure out that there no memory needed on the heap for this object, but maybe things don't work that way. ...