This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Try the static Desktop#getDesktop() method to get an instance, then try the browse method. You are likely to have at least two checked Exceptions to handle.
Campbell Ritchie wrote:Try the static Desktop#getDesktop() method to get an instance, then try the browse method. You are likely to have at least two checked Exceptions to handle.
thanks! I also found something on the Oracle trail about this, so I am going to read up.
I have a question regarding this class. There is no constructors. now I've done in the past things like and it worked. I didn't even need to import the API it seems. Why is that? I can do the same with the Desktop class which is why I'm bringing it up. It's pretty handy, and also seems to be the only way you can call the Desktop class unless you do(I believe) Object o = new Desktop(); But even then I'm not too sure since it might need a constructor... Is there a name for these, and/or a better place to read up on this?
Campbell Ritchie wrote:Try the static Desktop#getDesktop() method to get an instance, then try the browse method. You are likely to have at least two checked Exceptions to handle.
thanks! I also found something on the Oracle trail about this, so I am going to read up.
I have a question regarding this class. There is no constructors.
It's a class with all static methods. There is no state, so we're not intended to create any instances. There would be no reason. The purpose for creating an instance of an object is to hold some state that can be manipulated and queried. These methods simply take an input and give an output with no side effects that remain around for later use.
now I've done in the past things like and it worked.
Because that's a static method.
I didn't even need to import the API it seems.
java.lang.* is implicitly imported.
Is there a name for these
They're usually called helper classes or possibly utility classes. Some people mistakenly call them static classes, but that's incorrect. The class itself isn't static. (Only nested classes can be static, not top-level classes.) It's just that all its methods are.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
4
posted
1
Jeff Verdegan wrote: . . . It's a class with all static methods. . . . we're not intended to create any instances. . . .
Are you sure? I think Desktop has got instance methods, and has got state. It only has a private constructor, and that method I quoted is a factory method. You don’t create an instance, but calling that method allows the class to create an instance and return it. Whether you get different instances from multiple calls, or whether you get the same instance which had been created and cached previously, I don’t know.