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.

Miscellaneous I<br />

use it.<br />

I want to keep my java GUI always on the top of any other desktop application.<br />

Any idea?<br />

I want to keep my java GUI always on the top of any other desktop application. Any<br />

idea?<br />

Answer: Spawn a thread that knows about the parent Window, and every X<br />

milliseconds, executes the toFront () command of that window. Just remember to<br />

execute it using SwingUtilities.invokeLater (), and don't<br />

let your users launch two apps, unless you enjoy screen lockup.<br />

Can a java application be run of a CD without installing anything (i.e. runtime, etc)<br />

on the target computer?<br />

I would like to put my application and hand it out as a demo, but I want to make it<br />

easy to view.<br />

Answer1: by Dale King The JRE was made so that it didn't need to be "installed".<br />

What I did in one case was to simply put the JRE into a jre folder in the same<br />

directory as my application then invoke it from that directory using:<br />

jre\bin\jre.exe -cp MyJar.java MyClass<br />

That was for JDK1.1 and you have to modify it slightly for <strong>Java</strong> 2. But this did not<br />

require any installation of environment variables to be set up. The JRE was smart<br />

enough to know how to get to its system classes relative to where the jre.exe file was<br />

located.<br />

Answer2: you could try a <strong>Java</strong> to native compiler.<br />

I would like to know whether it is possible to test the memory, so as to avoid the<br />

OutOfMemoryError or whether it is possible to increase the amount of memory in the<br />

JRM.<br />

Answer: You can get the total and available memory used by the VM by making two<br />

calls from the Runtime class:<br />

Runtime runtime = Runtime.getRuntime();<br />

long free = runtime.freeMemory(); //the available memory<br />

long total = runtime.totalMemory(); // the total for the JVM<br />

The amount returned be totalMemory() isn't that useful unless you specify how much<br />

memory your program will have from the beginning (if you don't, the JVM will just<br />

keep grabbing more until you run out).<br />

You can set the initial and maximum memory from the command line:<br />

java -Xms64m -Xmx64m name.of.Application<br />

This will start your appplication with 64 megs initial and maximum memory.<br />

--<br />

Corey Wineman<br />

What needs to be done to reduce size of a jar file? What optimization techniques<br />

to use on classes inside the jar file? What tools if any?<br />

Answer: A JAR file is a ZIP archive. You can influence its size by choosing the<br />

degree of compression you want to have. This is usually defined by a value between<br />

0 (no compression) and 9 (maximum compression). Although JAR tool does not list a<br />

file:///F|/350_t/350_tips/miscellaneous-I.htm (4 of 11) [2002-02-27 21:18:44]

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

Saved successfully!

Ooh no, something went wrong!