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

class A{<br />

}<br />

class B{<br />

public A a;<br />

}<br />

Answer: Both the object and all the object references it contains need to belong to<br />

classes that implement Serializable.<br />

Static and transient fields are not serialized. For more, see,<br />

http://java.sun.com/docs/books/tutorial/essential/io/serialization.html<br />

I recently learned a bit about "inner classes" but this seems to be different...<br />

Q: I'm a bit new to <strong>Java</strong> programming so bear with me. My employer bought a<br />

package of java graphics library programs to support some chart applets<br />

we want to create. We have the source code. I'm trying to create a jar<br />

file with all the files I need to run the applet. When I currently run<br />

the applet, the browser java tool says that it can't find<br />

"TextComponent$1.class". I recently learned a bit about "inner classes"<br />

but this seems to be different. The "TextComponent.java" file does<br />

contain some inner classes, but not a class called "1". I'm confused.<br />

Is this an inner class? Or is it something else. Any help would be<br />

appreciated. Thanks...<br />

Answer: The TextComponent$1.class is the first anonymous class defined in<br />

TextComponent.java. Since nested (inner) classes are compiled to their own<br />

.class file, they needed unique names. The javac compiler is just creating a<br />

unique file name for an anonymous nested class.<br />

Hi there, does anybody know a good source of design patterns written in JAVA ?<br />

Answer: A pretty good (free to download) book.<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 />

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