JavaFAQ Home » Java Newsletters
[ The Java FAQ Daily Tips, weekly publication ]
Foreword: Excuse me for
possible mistakes. English is not native language for me.
In this issue:
Hello dear friends!
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 =
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)
Question: Could you tell me what is advantage of Spinner over Combo
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
Latest posts on our message
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
// The "Threads" class.
public class Threads extends Applet
My question is simple:
I have a Frame (Frame1) with a textfield component on it and a
another Frame (Frame2). When i push a jbutton on Frame1, Frame2
well so long. The problem is here: I have another textfield
Frame2 and a jbutton. I want to get the text of textfield on Frame2
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
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.
GUI - refresh ..it
will not end
Since a very long time I'm stuck in the same problem again &
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
Problem: The content of the frame does not refresh, until the window
is resized etc.
private JFrame myFrame = new JFrame();
on Java 2?
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.
centering applet on
I have an applet that I want to position in the top center of my
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
Send to a Friend
Search here again if you need more info!