Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java Newsletters Archive: 4

JavaFAQ Home » Java Newsletters Go to all tips in Java Newsletters


Bookmark and Share

Hello dear subsribers!

We continue to send you our daily Java tips!
********************************************
Please, if you like our tips, recommend us to your friends
and colleagues.
***********************************************
Tip1

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

A: A pretty good (free to download) book.

http://www.patterndepot.com/put/8/JavaPatterns.htm

......................................................................………………….

Tip 2
How to set the default memory limit of java virtual machine
in a java application?
Answer1: java -Xms16m -Xmx32m MainClassName
here: -Xms16m => 16meg initial memory allocation
-Xmx32m => 32meg max memory allocation

Answer2: Run your Java program with -mx switch
like this:

java -mx128m ClassName

This for example will set maximum memory allocation pool
to 128MB.
......................................................................………………….
Tip 3

Q: Currently I'm running two operating systems on one machine,
Windows 2000 and Windows ME.
Windows ME runs on default, Windows 2000 is on D drive and
ME is on C drive. I tried to add the JDK directory to the
classpath but there isn't a autoexec.bat on the D directory, but
there is one for C. Should I just create a autoexec.bat for D?

Answer: In Windows2000/ME you should do it on Control Panel.
So, go to Settings/Control Panel/System/Advanced/Environment
Variables... and edit your CLASSPATH variable if exists
or add a new one.
......................................................................………………….
Tip 4
Q: I need to be able to run a shell script from java, by doing a
host call to UNIX. I am currently trying 'Runtime.exec' to do this.
It says it runs it, but doesn't actually successfully complete the
command (which is a file delete).
A few questions I have about this:

1. Can I trace it or something to see why it isn't working?
2. How can I get the 'return code' from the shell script?
3. Will the java procedure wait for the shell script to execute,
or does it run a seperate thread concurrently?

Answer: > 1. Can I trace it or something to see why it isn't
working?

Runtime.exec() returns a Process object that you can
get information from.

If the script is written with sh or some derivative there of you
can do 'set -x' in the script to trace its behaviour. For other
scripting languages there is likely a similar mechanism. To
see the trace in your Java program, read from the error or
output streams of the process:
Process.getErrorStream() or Process.getOutputStream();
It's possible that the script is already printing a message to
its error stream that you aren't seeing, indicating why it
isn't working.

A:> 2. How can I get the 'return code' from the shell script?

Call Process.exitValue().

A:> 3. Will the java procedure wait for the shell script to execute,
or does it run a seperate thread concurrently?

The program runs concurrently in a separate *process*, not
a thread within the JVM. To wait for the process to finish, call

Process.waitFor().
......................................................................………………….
Tip 5

Do the classes in java.util.zip handle password-encrypted
zip files? I've looked through the API, and I don't see
any mention of it.

Answer: No, they don't. But Zip's built-in encryption isn't
safe anyway by today's standards. Every hacker can find
within a day (computer time)

......................................................................………………….
Tip 6

How do I make java apllication instalable?
Q: I have written a Java application and have the .class files
in one location. How do I make it installable? Is it possible
to convert it to an executable file?

Answer1: just create a batchfile or a .sc file (if on unix)
Answer2: Or check http://installshield.com/
They have special edition for Java which lets to write
additional interface for configuring of program parameters
during instalation.
And check a couple of addresses on our page here:
http://javafaq.nu/java/tools/tools.shtml
......................................................................………………….
Tip 7

An idea for validating the phone number field on a form…
Q: Does anyone have an idea for validating the phone number
field on a form. I am looking for something that will basically
check this input mask

*111*111*1111*

Where the 1's are number's and the *'s are either - . spaces,
or any other character like (). Please advise.

Answer1: You could use a regular expression package. For
example, Jakarta ORO:
http://jakarta.apache.org/oro/

Answer2: I'm thinking regular expressions. See:
http://www.cacas.org/java/gnu/regexp/

http://www.crocodile.org/~sts/Rex/


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy