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"!.

Easy Learn Java: Programming Articles, Examples and Tips - Page 150


Previous 1060 Stories (530 Pages, 2 Per Page) Next

Java Newsletters: Java Newsletters Archive: 152

Go to all tips in Java Newsletters
Issue No: 152 6 March 2003
11823 subscriber

"...if you have no mentors around in the initial stages."
"This book has saved me hours of research...""


Foreword: Excuse me for possible mistakes. English is not native language for me.

In this issue:
  • 1. When should I use notify() and when notifyAll() methods on threads?
  • 2. The clear-Method in the java.util.Calendar-Class doesnt behave like I suggest.
  • 3. Latest posts on our message board
  • 4. Link to Java FAQ

  • Hello dear friends!

    Have you entered yet?

    JavaFAQ.nu is proud to announce that we are a sponsor of the March 6 Amber Taylor IT Give-Away promotion. We do not do this very often but thought you would be interested in the products and services for IT Professionals being awarded. There is something for everyone! What is the cost? Not a thing! Enter here. You could win a free 500 Java Tips eBook.


    Tip 1

    Question: When should I use notify() and when notifyAll() methods on threads?

    Answer: Generally it is more reliable to use notifyAll() method. Notify() method wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods. Since it is internally implemented we do not know exactly which thread will be chosen.

    This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
    By executing a synchronized instance method of that object.

    By executing the body of a synchronized statement that synchronizes on the object.
    For objects of type Class, by executing a synchronized static method of that class.
    Only one thread at a time can own an object's monitor.

    It is much safer to use from the beginning notifyAll() method and later trying to optimize your program you can try to switch to notify(). You have no idea which thread will be awakened. You must be sure that every waiting thread will be able to continue if you use notify() method. The behavior of your program will be more predictable.
    From another hand using notify() method will decrease CPU and memory consumption since just one of multiple thread is awaken and rest are in waiting mode.


    50%-75% OFF Ink jet cartridges!. Please save money...(click here)


    Tip 2

    Question: The clear-Method in the java.util.Calendar-Class doesnt behave like I suggest. I want to clear the hour-field in a Date. If I use Calendar.clear(Calendar.HOUR) the hour is not reset. If I use Calendar.clear(Calendar.HOUR_OF_DATE) the hour is not reset also. Only if I invoke both methods the hour is reset. (java version "1.2.2")

    Answer: It is known Java bug.
    Call cal.clear(cal.HOUR) as well as cal.clear(cal.HOUR_OF_DAY).
    Or
    Call Calendar.set(Calendar.HOUR_OF_DAY,0) instead of Calendar.clear
    (Calendar.HOUR_OF_DAY).
    This bug is not fixed yet...


    Latest posts on our message board

    gzip file
    Hi!

    I need help again, how no! I'm writing an application which generate SVG files. I want to compress this files to use the .svgz extension. I know that it possible use gzip to compress the file, but I wonder if I can use some Java class to do it.

    I have tried this code...


    Please Help!!!!
    I have to design a simple prototype interface that performs a simple control function. The function is to control a robot which moves up, down, left and right. It only has to be a simple interface which operates from the command window but it needs functionality as people have to test it work. Can you offer me any suggestions on coding for this as I'm really stuck, thank you.
    Please answer here


    Save an image-object as image on the web server..
    For a little kids-homepage I have written an applet, within you can "paint" with the mouse. But now I want to store the image on the server. There is a cgi-script I can call to upload a file (i.e. http://domain.com/cgi-bin/store.cgi?file=image.jpg). How can I do this from the applet? The problem is that I haven't a file "image.jpg" that I could send. In the applet there is only an Image-object. Is it possible to save the file via the cgi-script? Can anybody point me in the right direction?


    Problem while trying to make an executable with Jexegen
    Hi,

    If have downloaded MS SDK for Java 4.0 and I wanted to make an executable. After reading some documents about Jexegen I have to typed this:

    jexegen /main:Studieresultaten /out:Sresult.exe /w /v *.class

    Looking at the details I can see that all the classes has been added. But I always get the following error:

    Warning: Main class specified but main class file was not found.

    Weird, because Studieresultaten.class has been added!!!!

    I have searched on Google for this error, but I can only find either a post that has not been replied or a Chinese post.
    Can anyone help me???


    Importing .swf Flash file into Java Application
    AS far as I understood there is a Java package that is for supporting Java and flash collaboration ))
    For example how can I import flash file into Java application(standalone) or sending information from Java to Flash and opposite.
    Please tell what the package is and where can I download it from.


    movable disks
    Hi,

    I would like to make a JFileChooser that finds the directory to the movable disk. How shall I do?

    JFileChooser chooser = new JFileChooser( new File(xxxxxxxxxx) );

    Please answer here...


    Please ask your questions and help each other at our Java Forum:
    http://javafaq.nu/forum/


    The Java FAQ Daily Tips is a newsletter that is only sent to those who have specifically subscribed to it (double opt-in).

    To subscribe/unsubscribe to "The Java FAQ Daily Tips" weekly edition newsletter visit our page here:
    http://www.javafaq.nu/plm2html/my_subscription.shtml

    If you have troubles please contact us: subscription@javafaq.nu


    Link to Java FAQ

    If you have added a link to http://javafaq.nu on your WEB-site, please let us know and you will get listed on our
    "pages linking to us" pages! If your page is a programming is programming relates you will of course get listed in the WEB-directory as well. Also, if you link to us, you have a chance to be listed in this newsletter as well.

    More information and graphics artworks can be found here
    http://javafaq.nu/other/linktous.shtml


    Advertising

    For information on advertising on the Java FAQ's Daily Tips Newsletter, send an email to: adv@javafaq.nu
    You will get the answer immediately from autoresponder!


    Send your comments, questions, praise and complaints to us: comments@javafaq.nu

    Copyright (c) 2000 - 2003 John Andersson, All rights reserved.



    1 comment | Printer Friendly Page  Send to a Friend | Java Newsletters | Score: 0
    Posted by jalex on Monday, February 02, 2004 (15:38:36) (2865 reads)

    News: Java Newsletters Archive: 151

    Go to all tips in Java Newsletters

    === [ The Java FAQ Daily Tips, weekly publication ] ===

    Issue No: 151 4 March 2003
    11823 subscriber

    Please read our "500 Java Tips" 387 pages e-Book, first update "100+ Java Tips!" (100+500=600 tips!),

    + set of free Java Tools:
    IDE, decompiler, Java to exe (make .exe!)

    Recommend us to your friends and colleagues!

    "...if you have no mentors around in the initial stages."
    "This book has saved me hours of research...""


    Foreword: Excuse me for possible mistakes. English is not native language for me.

    In this issue:
  • 1. Is there a Java class or component or something like to browse the web inside java Application?
  • 2. I have a piece of code (thread) which runs every x seconds and causes high CPU load.
  • 3. My program wants the capability to place the file physically on to the client machine. Can I use FTP?
  • 4. Latest posts on our message board
  • 5. Link to Java FAQ

  • Hello dear friends!

    Have you entered yet?

    JavaFAQ.nu is proud to announce that we are a sponsor of the March 6 Amber Taylor IT Give-Away promotion. We do not do this very often but thought you would be interested in the products and services for IT Professionals being awarded. There is something for everyone! What is the cost? Not a thing! Enter here. You could win a free 500 Java Tips eBook.


    Tip 1

    Question: Is there a Java class or component or something like to browse the web inside java Application?

    Answer: I know two and they are not free... If you know free component please send me info and I will publish it here.
    HotJava browser from SUN is no longer supported and end date is April 2003.

    1. Clue Web Browser Components:
    Clue Web Browser is the only browser solution designed to realize this new web browser concept. With its modular and scalable architecture, Clue Web Browser can be integrated with any application and run on a wide range of devices, such as PDAs and set-top boxes. Through our relentless pursuit of perfection, Clue Web Browser exhibits a solid implementation of the latest web technologies with excellent performance. It offers rich functionality and flexibility for a wide variety of web-related applications. To meet the specific requirements of different devices, we offer various editions for desktop and embedded devices.

    2. WebWindow 2.0 is a scalable Java browser component. With the WebWindow you can take advantage of Java's "write once, run anywhere" design and run your application on multiple operating systems and device platforms with a wide range of resource limitations. With a small core footprint, WebWindow can be used on devices ranging from PDAs, settop boxes, enterprise servers, and native web browsers all with little or no code changes to the core browser technology.

    By using the WebWindow in your application, you can avoid compatibility issues between different browsers and you can have a truly "100% Java" product. WebWindow can be utilitized in a number of ways in an application ranging from a simple help file displayer to a full fledge UI framework for building dynamic GUIs.

    Java wimps please close your ears ... For the Java programmer who
    thought he knew everything there was to know about Java, have a
    look at the most advanced Java newsletter archived on the website
    http://www.smotricz.com/kabutz Guess what, it won't even cost you
    anything! Subscribe today - you won't be disappointed.


    Tip 2

    Question: I have a piece of code (thread) which runs every x seconds and causes high CPU load. How could I decrease it?

    Answer: You can use static method yield() in the Thread. This method causes the currently executing thread object to temporarily pause and allow other threads (in OS and other programs) to execute.


    50%-75% OFF Ink jet cartridges!. Please save money...(click here)


    Tip 3

    Question: My program wants the capability to place the file physically on to the client machine. Can I use FTP? How? Do I need to read protocol description and implement it from scratch?

    Answer: You can use open source NetComponents package. NetComponents TM provides easy access to FTP, NNTP, SMTP, POP3, Telnet, TFTP, Finger, Whois, and other frequently used Internet protocols. Version 1.3 features newly added BSD R command support.

    NetComponents TM provides one-stop shopping for all your IETF protocol Java programming needs. Access FTP servers from your Java applications, send email from your Java applets, or automate access to Telnet accessible resources. You can do it all with NetComponents!
    You will find it here:
    http://www.savarese.org/oro/software/NetComponents.html
    Please feel free to examine the online API documentation and to download the latest version.

    FREE Your PC From Corrupt Files Now!
    Have the peace of mind knowing your computer is automatically kept
    error-free, 24 hours a day! Safe. Simple. Secure. Silent. This proven,
    automated, and easy-to-use PC health check tool is guaranteed to
    instantly expose harmful files lurking on your computer.

    Get your FREE PC Health Check today at:
    http://mocda4.com/1/c/52983/80159/248520/248520


    Latest posts on our message board

    gzip file
    Hi!

    I need help again, how no! I'm writing an application which generate SVG files. I want to compress this files to use the .svgz extension. I know that it possible use gzip to compress the file, but I wonder if I can use some Java class to do it.

    I have tried this code...


    Please Help!!!!
    I have to design a simple prototype interface that performs a simple control function. The function is to control a robot which moves up, down, left and right. It only has to be a simple interface which operates from the command window but it needs functionality as people have to test it work. Can you offer me any suggestions on coding for this as I'm really stuck, thank you.
    Please answer here


    Save an image-object as image on the web server..
    For a little kids-homepage I have written an applet, within you can "paint" with the mouse. But now I want to store the image on the server. There is a cgi-script I can call to upload a file (i.e. http://domain.com/cgi-bin/store.cgi?file=image.jpg). How can I do this from the applet? The problem is that I haven't a file "image.jpg" that I could send. In the applet there is only an Image-object. Is it possible to save the file via the cgi-script? Can anybody point me in the right direction?


    Problem while trying to make an executable with Jexegen
    Hi,

    If have downloaded MS SDK for Java 4.0 and I wanted to make an executable. After reading some documents about Jexegen I have to typed this:

    jexegen /main:Studieresultaten /out:Sresult.exe /w /v *.class

    Looking at the details I can see that all the classes has been added. But I always get the following error:

    Warning: Main class specified but main class file was not found.

    Weird, because Studieresultaten.class has been added!!!!

    I have searched on Google for this error, but I can only find either a post that has not been replied or a Chinese post.
    Can anyone help me???


    Importing .swf Flash file into Java Application
    AS far as I understood there is a Java package that is for supporting Java and flash collaboration ))
    For example how can I import flash file into Java application(standalone) or sending information from Java to Flash and opposite.
    Please tell what the package is and where can I download it from.


    movable disks
    Hi,

    I would like to make a JFileChooser that finds the directory to the movable disk. How shall I do?

    JFileChooser chooser = new JFileChooser( new File(xxxxxxxxxx) );

    Please answer here...


    Please ask your questions and help each other at our Java Forum:
    http://javafaq.nu/forum/


    The Java FAQ Daily Tips is a newsletter that is only sent to those who have specifically subscribed to it (double opt-in).

    To subscribe/unsubscribe to "The Java FAQ Daily Tips" weekly edition newsletter visit our page here:
    http://www.javafaq.nu/plm2html/my_subscription.shtml

    If you have troubles please contact us: subscription@javafaq.nu


    Link to Java FAQ

    If you have added a link to http://javafaq.nu on your WEB-site, please let us know and you will get listed on our
    "pages linking to us" pages! If your page is a programming is programming relates you will of course get listed in the WEB-directory as well. Also, if you link to us, you have a chance to be listed in this newsletter as well.

    More information and graphics artworks can be found here
    http://javafaq.nu/other/linktous.shtml


    Advertising

    For information on advertising on the Java FAQ's Daily Tips Newsletter, send an email to: adv@javafaq.nu
    You will get the answer immediately from autoresponder!


    Send your comments, questions, praise and complaints to us: comments@javafaq.nu

    Copyright (c) 2000 - 2003 John Andersson, All rights reserved.



    30 comments | Printer Friendly Page  Send to a Friend | News | Score: 0
    Posted by jalex on Monday, February 02, 2004 (15:31:39) (2680 reads)

    Previous 1060 Stories (530 Pages, 2 Per Page) Next

    530| 529| 528| 527| 526| 525| 524| 523| 522| 521| 520| 519| 518| 517| 516| 515| 514| 513| 512| 511| 510| 509| 508| 507| 506| 505| 504| 503| 502| 501| 500| 499| 498| 497| 496| 495| 494| 493| 492| 491| 490| 489| 488| 487| 486| 485| 484| 483| 482| 481| 480| 479| 478| 477| 476| 475| 474| 473| 472| 471| 470| 469| 468| 467| 466| 465| 464| 463| 462| 461| 460| 459| 458| 457| 456| 455| 454| 453| 452| 451| 450| 449| 448| 447| 446| 445| 444| 443| 442| 441| 440| 439| 438| 437| 436| 435| 434| 433| 432| 431| 430| 429| 428| 427| 426| 425| 424| 423| 422| 421| 420| 419| 418| 417| 416| 415| 414| 413| 412| 411| 410| 409| 408| 407| 406| 405| 404| 403| 402| 401| 400| 399| 398| 397| 396| 395| 394| 393| 392| 391| 390| 389| 388| 387| 386| 385| 384| 383| 382| 381| 380| 379| 378| 377| 376| 375| 374| 373| 372| 371| 370| 369| 368| 367| 366| 365| 364| 363| 362| 361| 360| 359| 358| 357| 356| 355| 354| 353| 352| 351| 350| 349| 348| 347| 346| 345| 344| 343| 342| 341| 340| 339| 338| 337| 336| 335| 334| 333| 332| 331| 330| 329| 328| 327| 326| 325| 324| 323| 322| 321| 320| 319| 318| 317| 316| 315| 314| 313| 312| 311| 310| 309| 308| 307| 306| 305| 304| 303| 302| 301| 300| 299| 298| 297| 296| 295| 294| 293| 292| 291| 290| 289| 288| 287| 286| 285| 284| 283| 282| 281| 280| 279| 278| 277| 276| 275| 274| 273| 272| 271| 270| 269| 268| 267| 266| 265| 264| 263| 262| 261| 260| 259| 258| 257| 256| 255| 254| 253| 252| 251| 250| 249| 248| 247| 246| 245| 244| 243| 242| 241| 240| 239| 238| 237| 236| 235| 234| 233| 232| 231| 230| 229| 228| 227| 226| 225| 224| 223| 222| 221| 220| 219| 218| 217| 216| 215| 214| 213| 212| 211| 210| 209| 208| 207| 206| 205| 204| 203| 202| 201| 200| 199| 198| 197| 196| 195| 194| 193| 192| 191| 190| 189| 188| 187| 186| 185| 184| 183| 182| 181| 180| 179| 178| 177| 176| 175| 174| 173| 172| 171| 170| 169| 168| 167| 166| 165| 164| 163| 162| 161| 160| 159| 158| 157| 156| 155| 154| 153| 152| 151|
    150
    | 149| 148| 147| 146| 145| 144| 143| 142| 141| 140| 139| 138| 137| 136| 135| 134| 133| 132| 131| 130| 129| 128| 127| 126| 125| 124| 123| 122| 121| 120| 119| 118| 117| 116| 115| 114| 113| 112| 111| 110| 109| 108| 107| 106| 105| 104| 103| 102| 101| 100| 99| 98| 97| 96| 95| 94| 93| 92| 91| 90| 89| 88| 87| 86| 85| 84| 83| 82| 81| 80| 79| 78| 77| 76| 75| 74| 73| 72| 71| 70| 69| 68| 67| 66| 65| 64| 63| 62| 61| 60| 59| 58| 57| 56| 55| 54| 53| 52| 51| 50| 49| 48| 47| 46| 45| 44| 43| 42| 41| 40| 39| 38| 37| 36| 35| 34| 33| 32| 31| 30| 29| 28| 27| 26| 25| 24| 23| 22| 21| 20| 19| 18| 17| 16| 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1|


    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