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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

getting that error, you are trying to load a file that isnt a class and so the class loader<br />

in the JVM is throwing out that exception.<br />

Make sure you transfer the class files to site in binary mode, rather than text or ASCII<br />

mode.<br />

An error from the browser saying "cannot start applet ... bad magic number" usually<br />

means that one of the class files on the server is corrupted. '<br />

Replace your class binary files on the web server; clean up the cache of your<br />

browser, and reload your applet.<br />

Q: In java, I found a lot of methods, which let you enter a line (read (), readLine ()<br />

e.c.t). They all wait until return is pressed, and then start providing you the<br />

information.<br />

Does anyone know if there is a read method available whit the desired behaviour, i.e.<br />

which doesn't wait for return being pressed?<br />

Answer: <strong>Java</strong> does not provide it, the terminal itself waits until return is pressed<br />

before sending the entered line to <strong>Java</strong>.<br />

You need to use some platform specific mechanism to change the terminal settings.<br />

Q: Can I pass a function as a parameter in <strong>Java</strong>? If so, how?<br />

Answer: No, you cannot. But you can pass an object with method and then just use<br />

this method like this:<br />

myFunction (object); // object has method useMyMethod(){ do smth here...}<br />

..<br />

..<br />

somewhere in another place where use this function..<br />

object.useMyMethod();<br />

What is difference capacity() and size() methods for vector?<br />

What is difference between<br />

public final int capacity()<br />

Returns the current capacity of this vector.<br />

and<br />

public final int size()<br />

Returns the number of components in this vector.<br />

Answer: please read this method: ensureCapacity<br />

public final synchronized void ensureCapacity(int minCapacity)<br />

Increases the capacity of this vector, if necessary, to ensure that it can hold at least<br />

the number of components specified by the minimum capacity argument.<br />

Parameters:<br />

minCapacity - the desired minimum capacity.<br />

What're the differences between classpath and import in the java application?<br />

Do I need to have the package in the classpath first before importing in a java<br />

application or need not?<br />

file:///F|/350_t/350_tips/general_java-II.htm (8 of 13) [2002-02-27 21:18:24]

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

Saved successfully!

Ooh no, something went wrong!