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 I<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 />

Answer: Classpath is an environment variable of your OS, you have to set it (or<br />

better: <strong>Java</strong> sets it) to tell <strong>Java</strong> where to search for classes.<br />

You use import in a program to let <strong>Java</strong> search for the specified classes within the<br />

classpath. This implies that the package must be in the classpath.<br />

--<br />

Stephan Effelsberg<br />

Q: What is difference between Iterator and Enumeration?<br />

First of all <strong>Java</strong> FAQ Team wish you !!!HAPPY NEW YEAR!!! and then<br />

Answer: from<br />

http://java.sun.com/docs/books/tutorial/collections/interfaces/collection.html<br />

The object returned by the iterator method deserves special mention. It is an Iterator,<br />

which is very similar to an Enumeration, but differs in two respects:<br />

Iterator allows the caller to remove elements from the underlying collection during the<br />

iteration with well-defined semantics.<br />

Method names have been improved.<br />

The first point is important: There was no safe way to remove elements from a<br />

collection while traversing it with an Enumeration. The semantics of this operation<br />

were ill-defined, and differed from implementation to implementation.<br />

The Iterator interface is shown below:<br />

file:///F|/350_t/350_tips/general_java-I.htm (11 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!