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

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


Bookmark and Share

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

 Issue No: 167                                            5 June 2003
13103 subscribers    

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

In this issue:
  • 1. I know that Hashmap implementation is not synchronized. How can I synchronize it?
  • 2. Could you tell me what is advantage of Spinner over Combo box?
  • 3. Latest posts on our message board
  • 4. Link to Java FAQ

  • Hello dear friends!

    Tip 1

    Question: I know that Hashmap implementation is not synchronized. How can I synchronize it?

    Answer: Really good answer often can be found in API!
    "If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:

    Map m = Collections.synchronizedMap(new HashMap(...));

    The iterators returned by all of this class's "collection view methods" are fail-fast: if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

    Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs."

    From Java API (v 1.4.1)

    --
    John  


    Tip 2

    Question: Could you tell me what is advantage of Spinner over Combo box?

    Answer: Really no advantages, excluding one: spinners are sometimes preferred because they don't require a drop down list that can obscure important data. Indeed, in Spinner component you can "spin" thousands of values (for example year). Let's now imagine drop down window which contains all years of human history Smile


    Latest posts on our message board

     

    Threads

    I have developed this little program that illustrates the problem that is similar to a different one I am making. I wonder how you make the first method run through completely then go onto paint(g) which runs through the second. As of now, all three: down,first, and second appear simultaneously.

    // The "Threads" class.
    import java.applet.*;
    import java.awt.*;

    public class Threads extends Applet
    continues here


    Class question

    Hi,
    My question is simple:

    I have a Frame (Frame1) with a textfield component on it and a jbutton and
    another Frame (Frame2). When i push a jbutton on Frame1, Frame2 appears. All
    well so long. The problem is here: I have another textfield (editable) on
    Frame2 and a jbutton. I want to get the text of textfield on Frame2 when i
    push the button and have the text BACK ON FRAME 1.

    I have a .java file for each Frame: Frame1.java and Frame2.java. I 'm
    creating an object like this on Frame2.java:
    Frame1 obj=new Frame1();
    and i get Frame1's methods with obj.
    All seem good, i'm getting no error message, but it doesn't work.

    As you may have understood i'm a little bit rookie so any help would be appreciatable. I' m working on Borland JBuilder 8

    Thanks on advance.
    continues here


    GUI - refresh ..it will not end

    Hi there

    Since a very long time I'm stuck in the same problem again & again...

    Situation:
    I'm using swings JFrame where I add an instance of a Class that extends JLabel. I've overridden the paintComponent(Graphics g)-method where I do the whole draw-stuff and finally call super.paintComponent(g).

    Problem: The content of the frame does not refresh, until the window is resized etc.

    Code:

    private JFrame myFrame = new JFrame();
    continues here


    MS-Java emulation on Java 2?

    Hi,

    There is an old avatar chat applet (example: http://eagles.chatserve.com/ip.html) called InstantPalace. The applet works great, but it's pretty old, and only runs on the MS-Java and older "Java 1" JREs. So users who have upgraded to Java 2 JREs can't use it. The Applet was created by a company that is no longer in business, so chances of it ever being updated for Java 2 compatibility are, unfortunately, not very good.

    I was wondering if there was a way to emulate MS-Java inside of a Java 2 applet, so older Java2-incompatible applets such as this one could be used on systems with Java 2.
    continues here


    centering applet on screen

    Hi,
    I have an applet that I want to position in the top center of my screen,
    When I run the applet in the applet viewer it shows up in the top left corner of my screen, Dose anyone have any ideas on how I can fix this, this is the html code I am using. I also tried using a center method in this code, but then my applet didn`t appear on the screen. Any help wopuld be greatly appreciated.
     


     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