27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

General <strong>Java</strong> Questions I<br />

--<br />

David Ehrens<br />

Q: I wonder what happened if I remove "deprecations" from my code, for example<br />

size() and put getSize().<br />

Don't the programs work any more on older browsers (e.g. IE3)?<br />

Answer: Check the docs to see whether they say "Since 1.1", "Since 1.2" or "Since<br />

1.3" - if so, they will not work in the oldest MS VM.<br />

Keep in mind that Sun's programmers haven't been very good at actually<br />

documenting this for all classes and methods.<br />

or directly here:<br />

To check your code against any version of the JRE (1.1, 1.2, 1.3), use<br />

<strong>Java</strong>PureCheck: http://java.sun.com/100percent/<br />

--<br />

Marco<br />

Q: How do we exchange data between <strong>Java</strong> and <strong>Java</strong>Script and vice-versa?<br />

Answer: Public variable and methods of <strong>Java</strong> Applet are visible to a HTML document.<br />

So using <strong>Java</strong>Script you can access the public variables and public functions.<br />

The syntax is:<br />

var some_var = document.appletname.variable_name<br />

With this you will get the value of the variable variable_name in your <strong>Java</strong>Script<br />

variable some_var.<br />

Q: Constructors and methods: are they the same?<br />

I need a little help here...I have been teaching that constructors are not methods. This<br />

is for several reasons, but mainly because JLS says "constructors are not members"<br />

and members are "classes, interfaces, fields, and methods."<br />

So, now the rest of the staff is ganging up on me and making life a little nasty. They<br />

quote Deitel and Deitel, and Core <strong>Java</strong> (which references "constructor methods") and<br />

who knows how many other books.<br />

The one we are teaching in is loaded with so many errors that even though it calls<br />

constructors methods NOBODY will quote it as an authority.<br />

How can so many people call constructors methods if they aren't.<br />

Okay. Are they or aren't they? I holding to the definition that they are not unless it is<br />

so common to call them that, that I will have to change.<br />

Comments?<br />

Answer: If you go by the JLS (<strong>Java</strong> Language Specification) and the <strong>Java</strong> API (and<br />

you should) , then no, constructors are not methods. Consider that<br />

Class.getMethods() returns an array of Method instances and<br />

Class.getConstructors() returns an array of Constructor instances, and Constructor<br />

and Method or not interchangeable (one is not derived from the other), but both<br />

implement the Member interface. Seems to me that <strong>Java</strong> is going out of its way to<br />

differentiate them.<br />

Besides, the mechanics of constructors are so different from the mechanics of<br />

file:///F|/350_t/350_tips/general_java-I.htm (4 of 31) [2002-02-27 21:18:17]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!