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 II<br />
http://www.patterndepot.com/put/8/<strong>Java</strong>Patterns.htm<br />
Q: Whats the difference between the two: System.err. and System.out? When<br />
should we use System.err?<br />
Answer1: System.out leads the output to the standard output stream (normally<br />
mapped to your console screen), System.err leads the output to the standard error<br />
stream (by default the console, too). the standard output should be used for regular<br />
program output, the standard error for errormessages. If you start your console<br />
program regularly both message types will appear on your screen.<br />
But you may redirect both streams to different destinations (e.g. files), e.g. if you want<br />
to create an error log file where you don't want to be the regualr output in.<br />
On an UNIX you may redirect the output as follows:<br />
java yourprog.class >output.log 2>error.log<br />
this causes your regular output (using System.out) to be stored in output.log and your<br />
error messages (using System.err) to be stored in error.log<br />
Answer2: System.err is a "special" pipe that usually is directed to the standard<br />
consolle. You can redirect the System.out with the normal pipe control (| or >), but<br />
System.err no. If you want to put both the "normal" output and the "error" output to a<br />
file you must use the special redirect 2>.<br />
This allow you to send normal messages into a file or in the /null black hole, but still<br />
receive the error messages on the console.<br />
What is the essential difference between an abstract class and an interface?<br />
What dictates the choice of one over the other?<br />
Answer: You can only extend one class (abstract or not) whereas you can always<br />
implement one or more interfaces. Interfaces are <strong>Java</strong>'s way to support multiple<br />
inheritance.<br />
Does anyone know how could I get the size of an Enumeration object? The API<br />
for Enumeration only contains getNext() and next().<br />
Answer 1: You can't. Theoretically, some classes that implement Enumeration may<br />
also provide some way to get a size, but you'd have to know about the more specific<br />
run-time type and cast to it... and none of the standard java.util Collections classes<br />
nor Vector or such provide these methods in their Enumeration implementations.<br />
Answer2:<br />
you can make your own class like this:<br />
import java.util.*;<br />
public class MyEnumeration{<br />
int size;<br />
int index = 0;<br />
Enumeration e;<br />
file:///F|/350_t/350_tips/general_java-II.htm (5 of 13) [2002-02-27 21:18:24]