General Java Questions I
Answer: Yes, have the constructor throw an exception. Formally, an object _will_ be
created (since the constructor is a method invoked after the actual method creation),
but nothing useful will be returned to the program, and the dead object will be later
reclaimed by Garbage Collector.
But the clean way is as another reply suggests, that you leave calls to the constructor
to a static factory method which can check the parameters and return null when
needed.
Note that a constructor or any method in general throwing an exception will not
"return null", but will leave the "assign target" as it was.
Tor Iver Wilhelmsen
Q: What does mean "volatile"?
For the past couple of hours, I ve seen quite a few set of codes that has the _volatile_
keyword.
E.g.
private volatile somethingsomething....
What does it mean?
Answer: See JLS 2nd Edition, which just came out last year, still mentions it.
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#36930
"A field may be declared volatile, in which case a thread must reconcile its working
copy of the field with the master copy every time it accesses the variable. Moreover,
operations on the master copies of one or more volatile variables on behalf of a
thread are performed by the main memory in exactly the order that the thread
requested."
Seems just like the idea in C++ and appears still to me present in the language.
Synchronization certainly has it place in many applications, that doesn t mean that
volatile is not longer used or part of the language.
Paul Hill
Q: If some method is deprecated does it mean that one get a chance not to find
this method in some Java version?
Answer: It means it *may* be dropped in a future version, but chances are it s still
there. I m not sure I ve seen any deprecated features actually being removed from an
API yet often they re turned into no ops first, if they re dangerous.
Jon Skeet http://www.pobox.com/~skeet
Q: suppose I put a file a.txt in package com.xyz and the try access it like following.
Will it work?
import com.xyz.*;
public class Hello{
File f = new File("a.txt");
file:///F|/a_jsite/350_tips/general_java I.htm (18 of 33) [2001 07 08 11:24:51]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved