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: 1

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


Bookmark and Share

Congratulations dear friends!

We are starting our subscribing service and you are receiving
first 7 tips which will be published on our site just in one week (6 September)!
Later we will organise daily mailing. Unfortunatelly we have no enough
resources to solve this problem now.

And here our tips:

Tip 1
Q:
How can I get access to Cookie set at the Client?
How can I get access to Cookie set at the Client?

A: The following code should access a cookie on a client. It reads in
all the cookies on the machine. And checks there name for whichever
one you are looking for.

Cookie[] cookies = request.getCookies();
for(int i=0; i < cookies.length; i++) {
Cookie thisCookie = cookies[i];
if (thisCookie.getName().equals("Cookiename")) {
// Do whatever you want with the cookie....
} else {
// cookie doesn't exist...
}
}

The Cookie class is in package javax.servlet.http.Cookie

Tip 2
Q
: In Java, does it exist a function like sprintf in C ?

A: http://www.efd.lth.se/~d93hb/java/printf/index.html
a free Java version of fprintf(), printf() and sprintf()
- hb.format package


Tip 3
Q:
Is there free tool for automatic drawing the UML
diagram from a java source? (LINUX)

A: JVision generates UML from java source. The Linux version is
free for non-commercial use.
See http://www.object-insight.com


Tip 4
Q:
If I declare an array of objects, say Dogs, is that
memory taken when I create the array or when I create
the objects in the aray when I declare this array:

Dog[] dog = new Dog[100];

or does it take the memory when I actually create the Dogs
in the array eg.:
for(int i = 0;i


A: The statement above is actually two-fold. It is the declaration
and initialisation of the array. Dog[] dog is the declaration, and
all this does is declare a variable of type Dog[], currently
pointing to null.
You then initialise the array with new Dog[100], which will create
100 elements in the array, all of them are referencing null.
It is important to realise that the elements of an array are not
actually objects, they only reference objects which exist elsewhere
in memory. When you actually create the Dog objects with new Dog(),
these objects are created somewhere in memory and the elements in
the array now point to these objects.
Pedant point:
Nothing ever points to null. It is a constant that represents
the value of a reference variable that is not a pointer to some
object new Dog[100] creates an array of 100 null Dog references.

Tip 5.
Q:
I am trying socket level programming through firewalls. Could
somebody tell what Http tunnelling is and how to achieve
that using Java 2?

As an aside, how do you request your proxy server to
fetch a page from the net?

A: Please read it here:
http://developer.java.sun.com/developer/technicalArticles/InnerWorkings/Burrowing/index.html


Tip 6
Q:
I'm having trouble getting sleep to work properly. It seems to just
return immediately, and not sleep for the requested time.
Is there some trick I need to know about?
The docs say that sleep takes an argument in milli-seconds,
but sleep(10000) seems to return immediately.

A: It can happen if another thread interrupts your sleeping thread.
sleep(10000) says that it just can sleep 10 sec if nobody needs it.
That is reason why you do
try{
sleep(10000);
}
catch(InterruptedException x){
//do smth here
}

You just try, it is not an order. It tries but not always sleeps!


Tip 7
Q:
Does anyone know if there is an easy way to invoke UNIX shell scripts from
a Java application?
A: There is!
Execute a shell and then write the name of the shell script on the shells stdin stream.

Process child = rtime.exec("/bin/bash");
BufferedWriter outWriter = new BufferedWriter(new OutputStreamWriter(child.getOutputStream()));
outWriter.writeLine("filename");
outWriter.flush();


We hope you enjoy your reading. If you find some mistakes please reply us to:
subscribe @ javafaq.nu


 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