| Distinct ID Number Per Object? |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- JDBC javax.sql.RowSetListener API QuestionI'm implementing a TableModel for my Java Swing application that
listens for the changes in a javax.sql.RowSet object so they can be
displayed in a JTable. It seems there is a limitation in the
RowSetListener API preventing my program from obtaining the information
it needs to keep the JTable in sync with the RowSet.
I can register a RowSetListener with the RowSet object. Whenever a row
is updated, inserted or deleted, it's rowChanged(RowSetEvent event)
method is called.
The problem is that I am unable to distinguish between the three events
(insertRow, updateRow or deleteRow) or obtain the relevant row number
in my implementation of rowChanged(RowSetEvent event).
The only thing the RowSetEvent object that gets passed into rowChanged
seems to tell me is the source RowSet object of the event. I need to
be able to tell which of the three events occured and the relevant row
number so I can so I can notify the JTable by calling the appropriate
fireTableRowsInserted(), fireTableRowsUpdated(), or
fireTablesRowsDeleted() method.
How do I obtain this information from the API? If there is a better
group I should post this question to, please let me know.
Thanks,
Bruce
- 3
- SQL Server 2000 -> JDBC Date TimeSeems to me that the problems is in the translation. I recommend that you
do a cast in the request. I.E. Cast '15/07/2005 AS DATETIME)
mlb
- 5
- Design tool for "multi-thread"I am looking for a tool to design/describe the relation/sequence/interaction
amount threads.
What kind of diagram do poeple normally use to do the analysis/design/model
on multi-thread application?
Any suggestion for a design tool?
thanks
- 5
- java regular expression problemHi,
I want to replace mulitple occurances of a string one after the another
with a single string
for eg .
input : a hello b world c java abcabcabc
output: a hello b world c java def
I mean multiple occurances of pattern 'abc' with a single string 'def'.
how can do this with JAVA regular expressions ?
I tried replaceAll method in string class, but I dont know how to
format regular expression.
thanks
Ranu
- 6
- 7
- JAVAMAIL SMTP error 421Hi all,
I've been looking at this problem for a while, browsing all possible
resources for a possible explanation but no way.
My problem is the following :
I've got a JAVA application listening to messages falling on a
MQSeries queue. The message falling on the queue contains all required
information to compose a mail intended for some recipients. The
application is connected to a mail server and is supposed to send the
mail.
In our development environment everything is fine and works properly.
We are using Exchange server. I made several tests with some 3000
messages falling on the queue and we got 3000 mails in our mail boxes.
The program has been installed at a client site and there we run into
trouble.
After the fifth message has been sent, the program ends with an
exception. It looks like the SMTP server had closed the connection
with no apparent reason.
The log looks like this :
Wed Jun 23 14:59:49 CEST 2004 - spy3 - 5 tasks done.
Wed Jun 23 14:59:50 CEST 2004 - alerter - MailError - Mail server
error in execu
ting a process.
Error when sending a mail through Java Mail API.Can't send command to
SMTP host;
nested exception is:
java.net.SocketException: Software caused connection abort:
socket write error
null
com.misys.alerter.Spy$MailError: Error when sending a mail through
Java Mail API
.Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Software caused connection abort:
socket write
error
at com.misys.alerter.SpyMasterQ.doAction(SpyMasterQ.java:497)
at com.misys.alerter.Spy.run(Spy.java:112)
The line 497 is : try {mailer.sendMail(tmptitle, tmpbody,
recipientTo,recipientDummy, recipientDummy);
The class mailer fills in a mimeMessage and calls
transport.sendMessage(message, message.getAllRecipients() ) ;
which is where I loose control.
The connection to the mail server is made through this method :
public boolean connectSrv( String host, String user, String password)
throws NoSuchProviderException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.connectiontimeout", "0" );
props.put("mail.smtp.timeout", "0" );
props.put("mail.debug", "true");
session = Session.getDefaultInstance(props, null);
transport = session.getTransport("smtp");
transport.connect(host, user, password);
/* store date time when connection occurs */
dtconnected = new GregorianCalendar();
return transport.isConnected();
}
I added the debug property to get more information. It shows an SMTP
error 421.
Here are some bits of output :
DEBUG SMTP SENT: NOOP
DEBUG SMTP RCVD: 250 2.0.0 OK
DEBUG SMTP SENT: NOOP
DEBUG SMTP RCVD: 250 2.0.0 OK
DEBUG SMTP SENT: NOOP
DEBUG SMTP RCVD: 421 Too many errors on this connection---closing
DEBUG SMTP SENT: NOOP
I have the feeling that something goes wrong on the server side but
have no idea what.
Has any of you already experienced such problem ?
Thanks for your time reading this. Any help or suggestion will be
highly appreciated.
JC
- 7
- does not opening websites: double loading pictures, helpHello
My internet explorer does not explore some websites. It looks like it
download pictures 2 times. In majority it works - j can see website after
double downloading but sometimes it shows me the web for a moment and then
everything dissapeares and j see white surface. J think it is sure it has
opened it.
HELP ME
How to eliminate this double loading and not showing websites?
And how to install java? it is imposible for it too. ?
Maciej
- 10
- XML tags in JSPHi,
I need to parse and transform xml in a jps. I have un variable that is
an InputStream that contains the XML.
I tried standard library and xtags library with no luck.
<c:out value="${eo.repositoryItem.dataSource.inputStream}" /> show me
that it is an inputStream
anf I tried
<xtags:parse reader="${eo.repositoryItem.dataSource.inputStream}" />
xtags version
<x:parse xml="${eo.repositoryItem.dataSource.inputStream}" /> jstl version
What's wrong ?
thanks
Frederic
- 10
- 11
- 11
- Conditional CompileTor Iver Wilhelmsen <email***@***.com> wrote:
> Graham Matthews <email***@***.com> writes:
>
> > Try compiling the above code on a non OS-X platform. It will complain
> > that it can't find classes referenced in the "use_an_apple_extension"
> > bit.
>
> Unless it's a lot of code, use reflection (though you lose the
> compile-time checks). Or invoke a class you compile once on the Mac
> and ship as a .class for inclusion when building later.
I have been waiting for someone to suggest reflection. The cost of
using reflection is that I lose static typing. Moreover its a heavy
weight way of getting conditional compilation don't you think. To
my mind a simple conditional compilation scheme would be far
more desirable.
graham
- 12
- 12
- New Mobile Phone forumHello Guys,
This is an awsome place, its nice to be here
Thanks,
Rajen
http://www.mobileuserforum.info
Ps. i run this generic mobile site called
http://www.mobileuserforum.info, we are looking for moderators, please
get in touch with me if any one of you is interested.
- 12
- Message IDsRoedy Green wrote:
> Java mail generates message ids like this:
> <25116828.1067897095828.JavaMail.Administrator@roedy>
>
> Eudora like this:
> <email***@***.com>
>
> Just what are these?
>
> 1. are they a hash?
>
> 2. are they supposed to be globally unique.
>
> 3. are they supposed to be the same if you send the same mail twice?
>
> 4. are they a timestamp?
>
From the RFC822 (http://www.faqs.org/rfcs/rfc822.html) is says that:
1) Message-ID is part of the optional-field.
2) chapter 4.6.1:
>>>
4.6.1. MESSAGE-ID / RESENT-MESSAGE-ID
This field contains a unique identifier (the local-part
address unit) which refers to THIS version of THIS message.
The uniqueness of the message identifier is guaranteed by the
host which generates it. This identifier is intended to be
machine readable and not necessarily meaningful to humans. A
message identifier pertains to exactly one instantiation of a
particular message; subsequent revisions to the message should
each receive new message identifiers.
<<<
And each mail client I have used generate a some what unique version
(content and formatting) of this field. I have only seen it used for
thread display as no one seems to heavily rely on it.
You can look into the JavaMail source (part of J2E source) for the
JavaMail generated one.
Minh Tran-Le.
- 13
- "Compiler" variablesHi,
Is there in java a possibility to define "compiler"-variables, for
example to except some code parts from the compilation?
If so, how does it work?
--
Oliver Hirschi
http://www.FamilyHirschi.ch
|
| Author |
Message |
Hal Vaughan

|
Posted: 2007-6-16 13:13:00 |
Top |
java-programmer, Distinct ID Number Per Object?
I have a case where I'll need distinct and printable names to use in a
reference table. I'd like to make it so each object, whether it's of the
same class as any other object or not, can produce a distinct number. It
looks like if I get the hashcode for any object, the JVM attempts to give
each object a unique hashcode, but it doesn't seem to guarantee it.
Is there any way to get a unique string or number for each object that is
created by a particular JVM?
Thanks!
Hal
|
| |
|
| |
 |
ram

|
Posted: 2007-6-16 13:35:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Hal Vaughan <email***@***.com> writes:
>Is there any way to get a unique string or number for each
>object that is created by a particular JVM?
The size of a string is bounded by the finite memory the JVM
can allocate. With, for example, 4 GB of memory, a string
might be at most 2^32 Bytes long, so there are at most
2^(2^40) unique strings of this length.
On the other hand, the loop
while( true )new java.lang.Object();
can run for more than 2^(2^40) iterations, as memory is
reclaimed by the garbage collector. Thus it can create an
unlimited number of new objects, especially 2^(2^40)+1.
In this case, there are not enough distinct strings
possible in this JVM to give each of these 2^(2^40)+1 objects
a unique string.
|
| |
|
| |
 |
Hal Vaughan

|
Posted: 2007-6-16 14:14:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Stefan Ram wrote:
> Hal Vaughan <email***@***.com> writes:
>>Is there any way to get a unique string or number for each
>>object that is created by a particular JVM?
>
> The size of a string is bounded by the finite memory the JVM
> can allocate. With, for example, 4 GB of memory, a string
> might be at most 2^32 Bytes long, so there are at most
> 2^(2^40) unique strings of this length.
>
> On the other hand, the loop
>
> while( true )new java.lang.Object();
>
> can run for more than 2^(2^40) iterations, as memory is
> reclaimed by the garbage collector. Thus it can create an
> unlimited number of new objects, especially 2^(2^40)+1.
>
> In this case, there are not enough distinct strings
> possible in this JVM to give each of these 2^(2^40)+1 objects
> a unique string.
So is it only in extreme cases like this where hashcodes would be
duplicated?
Hal
|
| |
|
| |
 |
Twisted

|
Posted: 2007-6-16 14:52:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
On Jun 16, 2:13 am, Hal Vaughan <email***@***.com> wrote:
> So is it only in extreme cases like this where hashcodes would be
> duplicated?
Not necessarily, but it's unlikely you'll run out of unique ones in a
production environment.
I suggest you use System.identityHashCode(Object) to get these
numbers. It should be a) fixed for an object's lifetime in one session
(it will change when the object is serialized and later deserialized);
b) globally unique (within the one JVM anyway) as the usual
implementation of the default hash code for Object is the memory
address of that object, which is necessarily globally unique in that
scope; and c) not subject to being overridden unlike calling
hashCode() on the object. This of course works if you need a globally
unique ID per object, even to the point of two copies of a single
object (so equals()) have distinct such IDs. Try to just use hashCode
otherwise.
A second option is to create an IdentityHashMap<Object, Integer> and
stuff objects into that. Distinct objects act as distinct keys (even
if equals()) and you'd assign a new higher integer to each one. Use
Long if you run out of Integers (unlikely). Use BigDecimal if you run
out of Longs (unlikely until we have converted most of the visible
universe into computronium). This has the benefit of giving out ever-
higher numbers even to objects that use the memory space where an
earlier object was before being garbage collected. You can't twiddle
the Object constructor to put everything in automatically, but you can
fake it by having the get-ID method you plan to use actually assign an
ID to objects that don't already have one lazily when it's first
requested. Of course, the objects won't get garbage collected unless
you use a WeakReference, in which case you may as well use an ordinary
HashMap<WeakReference<Object>, Integer> as the WeakReference hashCode
is the default one if I recall correctly. (WeakHashMap would cause
distinct objects that compare equal to have the same ID.) This is
complicated because you need to carry the WeakReference around with
you to look up in the HashMap (you can't just make a new one to the
same object and expect it to work). Perhaps a better option is to wrap
objects that will need IDs in a dummy object that has a single public
Object field, the default equals and hashCode, and make a
WeakHashMap<Dummy, Integer>. The wrapper object has to be used in
place of the original object on any path that leads to getting its ID.
Finally, if this ID is only needed for objects of classes you control,
you can make the base classes you control generate unique ID numbers
to put in a public final field. This is easiest if you can derive all
the classes for which you have this requirement from a single base.
Otherwise, the ID can be a long with 32 bits a sequentially-assigned
int and 32 bits the hashCode of the particular base class.
|
| |
|
| |
 |
Hal Vaughan

|
Posted: 2007-6-16 15:10:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Wow! Thanks for such a complete answer. I learned a LOT from your post!
Hal
Twisted wrote:
> On Jun 16, 2:13 am, Hal Vaughan <email***@***.com> wrote:
>> So is it only in extreme cases like this where hashcodes would be
>> duplicated?
>
> Not necessarily, but it's unlikely you'll run out of unique ones in a
> production environment.
>
> I suggest you use System.identityHashCode(Object) to get these
> numbers. It should be a) fixed for an object's lifetime in one session
> (it will change when the object is serialized and later deserialized);
> b) globally unique (within the one JVM anyway) as the usual
> implementation of the default hash code for Object is the memory
> address of that object, which is necessarily globally unique in that
> scope; and c) not subject to being overridden unlike calling
> hashCode() on the object. This of course works if you need a globally
> unique ID per object, even to the point of two copies of a single
> object (so equals()) have distinct such IDs. Try to just use hashCode
> otherwise.
>
> A second option is to create an IdentityHashMap<Object, Integer> and
> stuff objects into that. Distinct objects act as distinct keys (even
> if equals()) and you'd assign a new higher integer to each one. Use
> Long if you run out of Integers (unlikely). Use BigDecimal if you run
> out of Longs (unlikely until we have converted most of the visible
> universe into computronium). This has the benefit of giving out ever-
> higher numbers even to objects that use the memory space where an
> earlier object was before being garbage collected. You can't twiddle
> the Object constructor to put everything in automatically, but you can
> fake it by having the get-ID method you plan to use actually assign an
> ID to objects that don't already have one lazily when it's first
> requested. Of course, the objects won't get garbage collected unless
> you use a WeakReference, in which case you may as well use an ordinary
> HashMap<WeakReference<Object>, Integer> as the WeakReference hashCode
> is the default one if I recall correctly. (WeakHashMap would cause
> distinct objects that compare equal to have the same ID.) This is
> complicated because you need to carry the WeakReference around with
> you to look up in the HashMap (you can't just make a new one to the
> same object and expect it to work). Perhaps a better option is to wrap
> objects that will need IDs in a dummy object that has a single public
> Object field, the default equals and hashCode, and make a
> WeakHashMap<Dummy, Integer>. The wrapper object has to be used in
> place of the original object on any path that leads to getting its ID.
>
> Finally, if this ID is only needed for objects of classes you control,
> you can make the base classes you control generate unique ID numbers
> to put in a public final field. This is easiest if you can derive all
> the classes for which you have this requirement from a single base.
> Otherwise, the ID can be a long with 32 bits a sequentially-assigned
> int and 32 bits the hashCode of the particular base class.
|
| |
|
| |
 |
Lew

|
Posted: 2007-6-16 23:51:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Hal Vaughan wrote:
>>> So is it only in extreme cases like this where hashcodes would be
>>> duplicated?
Hash codes have even fewer values than Strings. That means there must be
proportionately more collisions. Have you read the Javadocs on the hashCode()
method? You should. Also read the Javadocs on Map, HashMap and IdentityHashMap.
As Twisted pointed out, the "Identity", i.e., the internal "address" of an
object, is unique for the lifetime of that object. Even without
IdentityHashMap, any Map can use an object that doesn't override equals()
(most custom objects, for example) as a unique key into a lookup. It is
sufficient to use a regular Map (e.g., HashMap) when equals() and == define
the same relation. IdentityHashMap is for when they differ and you want the
key selection to be based on ==.
Twisted said:
> as the usual implementation of the default hash code for Object is the memory address of that object,
"converted to an integer".
<http://java.sun.com/javase/6/docs/api/java/lang/Object.html#hashCode()>
> (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
You certainly cannot rely on a correspondence. That is what Sun's
implementation of Object.hashCode() does, but many, many subclasses override
it. It is a best practice (see /Effective Java/ by Josh Bloch) to override
hashCode() in any class that overrides equals(). Since most of the objects in
an application likely are of subtypes of Object, it is common that their
hashCode() will not return the "address" of the object.
Javadocs rule.
--
Lew
|
| |
|
| |
 |
ram

|
Posted: 2007-6-17 0:13:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Hal Vaughan <email***@***.com> writes:
>So is it only in extreme cases like this where hashcodes would
>be duplicated?
The hashcode only needs to fulfill the requirements of
http://download.java.net/jdk7/docs/api/java/lang/Object.html#hashCode()
These requirements are compatible with an implementation
that always returns the same value for each object.
The hashcode of an object depends on the class.
Therefore, if the class of an object is not known,
one can not assert more than the above requirements.
|
| |
|
| |
 |
Karl Uppiano

|
Posted: 2007-6-17 0:23:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
"Hal Vaughan" <email***@***.com> wrote in message
news:email***@***.com...
>I have a case where I'll need distinct and printable names to use in a
> reference table. I'd like to make it so each object, whether it's of the
> same class as any other object or not, can produce a distinct number. It
> looks like if I get the hashcode for any object, the JVM attempts to give
> each object a unique hashcode, but it doesn't seem to guarantee it.
>
> Is there any way to get a unique string or number for each object that is
> created by a particular JVM?
UUIDs are sometimes used for applications like this, as long as you remain
cognizant of the possible dynamic range and/or performance limitations.
However, it represents a 128-bit value, and java.util.UUID.randomUUID has
been fast enough for my needs.
http://en.wikipedia.org/wiki/UUID
http://java.sun.com/javase/6/docs/api/index.html
|
| |
|
| |
 |
Hal Vaughan

|
Posted: 2007-6-17 0:35:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Lew wrote:
> Hal Vaughan wrote:
>>>> So is it only in extreme cases like this where hashcodes would be
>>>> duplicated?
>
> Hash codes have even fewer values than Strings. That means there must be
> proportionately more collisions. Have you read the Javadocs on the
> hashCode()
> method? You should. Also read the Javadocs on Map, HashMap and
> IdentityHashMap.
I did. The part that concerned me was this: "It is not required that if two
objects are unequal according to the equals(java.lang.Object) method, then
calling the hashCode method on each of the two objects must produce
distinct integer results."
That's why I was asking about whether they were unique within a particular
runtime.
> As Twisted pointed out, the "Identity", i.e., the internal "address" of an
> object, is unique for the lifetime of that object. Even without
> IdentityHashMap, any Map can use an object that doesn't override equals()
> (most custom objects, for example) as a unique key into a lookup. It is
> sufficient to use a regular Map (e.g., HashMap) when equals() and ==
> define
> the same relation. IdentityHashMap is for when they differ and you want
> the key selection to be based on ==.
>
> Twisted said:
>> as the usual implementation of the default hash code for Object is the
>> memory address of that object,
>
> "converted to an integer".
> <http://java.sun.com/javase/6/docs/api/java/lang/Object.html#hashCode()>
>> (This is typically implemented by converting the internal address of the
>> object into an integer, but this implementation technique is not required
>> by the JavaTM programming language.)
>
> You certainly cannot rely on a correspondence. That is what Sun's
> implementation of Object.hashCode() does, but many, many subclasses
> override
> it.
It's in one of my own classes, so I'm not concerned about it being
overridden.
> It is a best practice (see /Effective Java/ by Josh Bloch) to
> override
> hashCode() in any class that overrides equals().
That part I did find, but I won't be overridding either one.
> Since most of the
> objects in an application likely are of subtypes of Object, it is common
> that their hashCode() will not return the "address" of the object.
I don't need to separate all objects. I have a set of data tables that all
have a master table, but then they have sub tables that are tracked subsets
of the master tables. I need to make sure that if I create a tracked
table, it has a different name from all the other tracked tables. I have
one particular class that will be generating names for those tracked tables
on its own and I want to make sure that if I create, say, 5 instances of
that class, that each separate instance will create names that are
different than the names created by the other instances.
I don't need an object's address or anything, I just want to be sure that
each instance of this one class has some kind of unique ID I can use to
specify unique names for the tracked tables.
Hal
|
| |
|
| |
 |
ram

|
Posted: 2007-6-17 0:46:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Twisted <email***@***.com> writes:
>I suggest you use System.identityHashCode(Object) to get these
>numbers. It should be a) fixed for an object's lifetime in one
>session (it will change when the object is serialized and later
>deserialized); b) globally unique (within the one JVM anyway)
>as the usual implementation of the default hash code for Object
>is the memory
http://download.java.net/jdk7/docs/api/java/lang/System.html#identityHashCode(java.lang.Object)
is not guaranteed to be ç±¾nique?by the documentation, this is
only a property of some implementations (as you have written
yourself).
On a 32-bit-system, two objects with non-overlapping lifetime
might share the same address.
On a 64-bit-system, even two objects with overlapping lifetime
might need to share the same 32-bit identity hash code.
The original poster might explain, what it is that he wants to
accomplish with the unique ID, as this might provide better
answers.
|
| |
|
| |
 |
ram

|
Posted: 2007-6-17 0:52:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Hal Vaughan <email***@***.com> writes:
>I don't need an object's address or anything, I just want to be
>sure that each instance of this one class has some kind of
>unique ID I can use to specify unique names for the tracked
>tables.
This could also be solved by a counter singleton invoked
upon creation of such an instance. The instance then
uses its unique counter value as a prefix for its IDs.
|
| |
|
| |
 |
Hal Vaughan

|
Posted: 2007-6-17 1:13:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Stefan Ram wrote:
> Hal Vaughan <email***@***.com> writes:
>>I don't need an object's address or anything, I just want to be
>>sure that each instance of this one class has some kind of
>>unique ID I can use to specify unique names for the tracked
>>tables.
>
> This could also be solved by a counter singleton invoked
> upon creation of such an instance. The instance then
> uses its unique counter value as a prefix for its IDs.
It took me a bit to think through this. Do you mean making a static int and
each instance uses it as an ID, then increments it for the next one?
That's what I got, or rather, worked out.
Thanks!
Hal
|
| |
|
| |
 |
ram

|
Posted: 2007-6-17 1:19:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Twisted <email***@***.com> writes:
>implementation of the default hash code for Object is the memory
>address of that object, which is necessarily globally unique in that
Readers are encouraged to run the following program (and be
prepared to wait several minutes, but not more than 15, for
the output) and then report the outcome here.
public class Main
{ final static java.lang.String lineSeparator =
java.lang.System.getProperty( "line.separator" );
public static void main( final java.lang.String[] args )
{ final java.lang.Object object = new java.lang.Object();
final int code = object.hashCode();
java.lang.Object object1;
int code1;
do
{ code1 =( object1 = new java.lang.Object() ).hashCode(); }
while( code1 != code );
java.lang.System.out.print
(( object == object1 )+ lineSeparator +
code + lineSeparator +
code1 + lineSeparator ); }}
|
| |
|
| |
 |
Hal Vaughan

|
Posted: 2007-6-17 1:27:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Stefan Ram wrote:
> public class Main
> { final static java.lang.String lineSeparator =
> java.lang.System.getProperty( "line.separator" );
> public static void main( final java.lang.String[] args )
> { final java.lang.Object object = new java.lang.Object();
> final int code = object.hashCode();
> java.lang.Object object1;
> int code1;
> do
> { code1 =( object1 = new java.lang.Object() ).hashCode(); }
> while( code1 != code );
> java.lang.System.out.print
> (( object == object1 )+ lineSeparator +
> code + lineSeparator +
> code1 + lineSeparator ); }}
What kind of safeguards does Java have in place so this doesn't overload my
CPU or RAM?
Hal
|
| |
|
| |
 |
ram

|
Posted: 2007-6-17 1:31:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Hal Vaughan <email***@***.com> writes:
>It took me a bit to think through this. Do you mean making a
>static int and each instance uses it as an ID, then increments
>it for the next one? That's what I got, or rather, worked out.
class globalCounter { private static int value = 0;
public static int getValue(){ return value++; }}
class Identifier
{ final private java.lang.String prefix;
private int count;
public Identifier()
{ this.prefix = java.lang.String.valueOf( globalCounter.getValue() );
this.count = 0; }
public java.lang.String get()
{ return prefix + "-" + java.lang.String.valueOf( count++ ); }}
public class Main
{ final static java.lang.String lineSeparator =
java.lang.System.getProperty( "line.separator" );
public static void main( final java.lang.String[] args )
{ final Identifier identifier0 = new Identifier();
final Identifier identifier1 = new Identifier();
java.lang.System.out.println
( identifier0.get() + lineSeparator +
identifier0.get() + lineSeparator +
identifier0.get() + lineSeparator +
identifier1.get() + lineSeparator +
identifier1.get() + lineSeparator +
identifier1.get() + lineSeparator ); }}
0-0
0-1
0-2
1-0
1-1
1-2
|
| |
|
| |
 |
Lew

|
Posted: 2007-6-17 2:06:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Hal Vaughan wrote:
Lew wrote:
Hal Vaughan wrote:
> The part that concerned me was this: "It is not required that if two
> objects are unequal according to the equals(java.lang.Object) method, then
> calling the hashCode method on each of the two objects must produce
> distinct integer results."
>
> That's why I was asking about whether they were unique within a particular
> runtime.
They aren't, necessarily. It depends on the hashCode() method of the object
in question.
>> You certainly cannot rely on a correspondence. That is what Sun's
>> implementation of Object.hashCode() does, but many, many subclasses
>> override
>> it.
>
> It's in one of my own classes, so I'm not concerned about it being
> overridden.
I don't understand. If you control the hashCode() then you know what it does.
Where does the question come from?
>> It is a best practice (see /Effective Java/ by Josh Bloch) to
>> override
>> hashCode() in any class that overrides equals().
>
> That part I did find, but I won't be overridding either one.
>
>> Since most of the
>> objects in an application likely are of subtypes of Object, it is common
>> that their hashCode() will not return the "address" of the object.
>
> I don't need to separate all objects. I have a set of data tables that all
> have a master table, but then they have sub tables that are tracked subsets
> of the master tables. I need to make sure that if I create a tracked
> table, it has a different name from all the other tracked tables. I have
> one particular class that will be generating names for those tracked tables
> on its own and I want to make sure that if I create, say, 5 instances of
> that class, that each separate instance will create names that are
> different than the names created by the other instances.
But names aren't hash codes. By definition, a hash reduces the size of the
value set from the domain to the range.
> I don't need an object's address or anything, I just want to be sure that
> each instance of this one class has some kind of unique ID I can use to
> specify unique names for the tracked tables.
So create unique names. Your issue has nothing to do with hashCode().
If you override equals, let's say to guarantee that two objects with the same
name are considered equal, i.e., to "mean" the same real-world object (in your
case, a "table"), then also override hashCode().
Why not just override those methods so that any time two objects with the same
name, which may be different objects in the JVM, are understood to refer to
the same table? This is a more normal idiom and should do everything you
need. Then you can use normal Maps to map the name to the object that models
the table.
class TableModel
{
private final String name;
public TableModel( String n )
{
name = n;
}
public final String getName() { return name; }
// other attributes
}
then in some other code
Map <String, TableModel> tables = new HashMap <String, TableModel> ();
public TableModel put( TableModel table )
{
return tables.put( table.getName(), table );
}
If you need a table object at a later time in your code, obtain
tables.get( name )
given the name of the table you want. (If you get null, create a TableModel
and put() it into the Map.)
This idiom might save you the trouble of UUID generation.
--
Lew
|
| |
|
| |
 |
Hal Vaughan

|
Posted: 2007-6-17 2:21:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Stefan Ram wrote:
> Hal Vaughan <email***@***.com> writes:
>
>>It took me a bit to think through this. Do you mean making a
>>static int and each instance uses it as an ID, then increments
>>it for the next one? That's what I got, or rather, worked out.
>
> class globalCounter { private static int value = 0;
> public static int getValue(){ return value++; }}
>
> class Identifier
> { final private java.lang.String prefix;
> private int count;
> public Identifier()
> { this.prefix = java.lang.String.valueOf( globalCounter.getValue() );
> this.count = 0; }
> public java.lang.String get()
> { return prefix + "-" + java.lang.String.valueOf( count++ ); }}
>
> public class Main
> { final static java.lang.String lineSeparator =
> java.lang.System.getProperty( "line.separator" );
> public static void main( final java.lang.String[] args )
> { final Identifier identifier0 = new Identifier();
> final Identifier identifier1 = new Identifier();
> java.lang.System.out.println
> ( identifier0.get() + lineSeparator +
> identifier0.get() + lineSeparator +
> identifier0.get() + lineSeparator +
> identifier1.get() + lineSeparator +
> identifier1.get() + lineSeparator +
> identifier1.get() + lineSeparator ); }}
>
> 0-0
> 0-1
> 0-2
> 1-0
> 1-1
> 1-2
Okay, I got one working. Thanks!
Hal
|
| |
|
| |
 |
Hal Vaughan

|
Posted: 2007-6-17 2:28:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Lew wrote:
> Hal Vaughan wrote:
> Lew wrote:
>
> Hal Vaughan wrote:
>> The part that concerned me was this: "It is not required that if two
>> objects are unequal according to the equals(java.lang.Object) method,
>> then calling the hashCode method on each of the two objects must produce
>> distinct integer results."
>>
>> That's why I was asking about whether they were unique within a
>> particular runtime.
>
> They aren't, necessarily. It depends on the hashCode() method of the
> object in question.
>
>
>>> You certainly cannot rely on a correspondence. That is what Sun's
>>> implementation of Object.hashCode() does, but many, many subclasses
>>> override
>>> it.
>>
>> It's in one of my own classes, so I'm not concerned about it being
>> overridden.
>
> I don't understand. If you control the hashCode() then you know what it
> does.
> Where does the question come from?
I need a unique ID for each instance of the class. Yes, I can control the
hashCode() method, but I wanted to know if it would be unique. At this
point, I've taken Stefan Ram's suggestion and used a static int and each
time an instance is created this int is used as the ID number and the
static int is incremented for the next one.
...
>> I don't need an object's address or anything, I just want to be sure that
>> each instance of this one class has some kind of unique ID I can use to
>> specify unique names for the tracked tables.
>
> So create unique names. Your issue has nothing to do with hashCode().
Now I see there are other ways to do this. When I looked through the
Javadocs, the hashCode() function was the only thing I found that I thought
would give a unique id for each class created.
> If you override equals, let's say to guarantee that two objects with the
> same name are considered equal, i.e., to "mean" the same real-world object
> (in your case, a "table"), then also override hashCode().
>
> Why not just override those methods so that any time two objects with the
> same name, which may be different objects in the JVM, are understood to
> refer to
> the same table?
Each table could contain a different subset, so if two objects with the same
name were created, they would use the same table, but they might need
separate tables.
> This is a more normal idiom and should do everything you
> need. Then you can use normal Maps to map the name to the object that
> models the table.
>
> class TableModel
> {
> private final String name;
> public TableModel( String n )
> {
> name = n;
> }
> public final String getName() { return name; }
> // other attributes
> }
>
> then in some other code
> Map <String, TableModel> tables = new HashMap <String, TableModel> ();
> public TableModel put( TableModel table )
> {
> return tables.put( table.getName(), table );
> }
If I follow this correctly, then one issue is that I have to be sure that
each time an instance of this class is used, I have to make sure it is
passed a unique number as an ID. That means keeping track of those
numbers. I'm using a number of different modules, some I know I'll be
adding months or years from now, so I'm doing as much as possible inside
the classes I'm doing now so later I can create them and use them without
the need to go through much in docs. When I do use them, I will likely
have only a short time to put them in place in a new module, so I'm making
them them as easy as possible to use. Essentially, I'm frontloading the
work. More work now isn't fun, but it means when I have to quickly put
together a new module using these classes, I'll hardly have to remember a
thing or look up much in the Javadocs I create.
Hal
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2007-6-17 2:28:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Lew wrote:
> Hal Vaughan wrote:
>>>> So is it only in extreme cases like this where hashcodes would be
>>>> duplicated?
>
> Hash codes have even fewer values than Strings. That means there must
> be proportionately more collisions. Have you read the Javadocs on the
> hashCode() method? You should. Also read the Javadocs on Map, HashMap
> and IdentityHashMap.
>
> As Twisted pointed out, the "Identity", i.e., the internal "address" of
> an object, is unique for the lifetime of that object. [...]
Can you find this guarantee in the Javadoc or other
authoritative place? Does this rule out 64-bit JVM's?
--
Eric Sosman
email***@***.com
|
| |
|
| |
 |
Lew

|
Posted: 2007-6-17 3:17:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
Eric Sosman wrote:
> Lew wrote:
>> Hal Vaughan wrote:
>>>>> So is it only in extreme cases like this where hashcodes would be
>>>>> duplicated?
>>
>> Hash codes have even fewer values than Strings. That means there must
>> be proportionately more collisions. Have you read the Javadocs on the
>> hashCode() method? You should. Also read the Javadocs on Map,
>> HashMap and IdentityHashMap.
>>
>> As Twisted pointed out, the "Identity", i.e., the internal "address"
>> of an object, is unique for the lifetime of that object. [...]
>
> Can you find this guarantee in the Javadoc or other
> authoritative place? Does this rule out 64-bit JVM's?
You mean the guarantee that an object's "address" is unique during its
lifetime? How else would the JVM find a particular instance? In other words,
how could it possibly not be?
If two objects had the same "address", then a reference using that "address"
would not reference a single object, which contradicts the very definition of
an object reference.
<http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.5>
> a reference to the newly created object is returned as the result [of] the indicated constructor
There is no way for one "address" to point to two objects simultaneously.
This question has nothing to do with bit width, AFAICS. I'm not really sure
how there could even be a question here.
--
Lew
|
| |
|
| |
 |
Daniel Dyer

|
Posted: 2007-6-17 3:39:00 |
Top |
java-programmer >> Distinct ID Number Per Object?
On Sat, 16 Jun 2007 20:17:28 +0100, Lew <email***@***.com> wrote:
> Eric Sosman wrote:
>> Lew wrote:
>>> Hal Vaughan wrote:
>>>>>> So is it only in extreme cases like this where hashcodes would be
>>>>>> duplicated?
>>>
>>> Hash codes have even fewer values than Strings. That means there must
>>> be proportionately more collisions. Have you read the Javadocs on the
>>> hashCode() method? You should. Also read the Javadocs on Map,
>>> HashMap and IdentityHashMap.
>>>
>>> As Twisted pointed out, the "Identity", i.e., the internal "address"
>>> of an object, is unique for the lifetime of that object. [...]
>> Can you find this guarantee in the Javadoc or other
>> authoritative place? Does this rule out 64-bit JVM's?
>
> You mean the guarantee that an object's "address" is unique during its
> lifetime? How else would the JVM find a particular instance? In other
> words, how could it possibly not be?
>
> If two objects had the same "address", then a reference using that
> "address" would not reference a single object, which contradicts the
> very definition of an object reference.
> <http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.5>
>> a reference to the newly created object is returned as the result [of]
>> the indicated constructor
>
> There is no way for one "address" to point to two objects simultaneously.
>
> This question has nothing to do with bit width, AFAICS. I'm not really
> sure how there could even be a question here.
I think Eric's point is that the number of possible hash codes is smaller
than the number of objects that can be addressed in a 64-bit JVM.
Therefore System.identityHashCode(Object) cannot, in a 64-bit VM at least,
guarantee to return unique values for all objects on the heap.
Dan.
--
Daniel Dyer
http//www.uncommons.org
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Packaging/version controlI'm developing a Swing program which I periodically update (change or
add classes or data files), weekly, to currently 2 people. The number of
people will eventually grow but the update frequency should decrease.
Currently, I'm putting the sources, classes, data files and a readme
file into a zip and sending it. The readme tells the users to either
compile or copy the classes over. There are ~25 .java files, ~75 .class
files and ~20 data files. This is time consuming, inconsistent and error
prone. I'm not using package statement or jars (currently). What are
people using and / or what would you recommend. - Thanks - Lou
- 2
- Java 5.0 Flood!Since J2SE 5.0 has just come out, I'd thought I'd post a some links and
highlights as written by the media around the internet.
---
** Sun ships Java upgrade, focuses on ease of use **
The next release is due out by early 2006
Highlights:
- "J2SE 5.0 is an important step for Java in its ongoing battle against
Microsoft Corp.'s .Net development environment", said Stephen O'Grady, an
analyst at RedMonk Inc. in Bath, Maine. "The streamlined start-up times and
a friendlier graphical user interface should be especially welcome additions
to Java users", he said.
"Particularly for Java applications on the client, it has taken a while for
them to start up," O'Grady said. "That has been a problem. Also, from a
user's perspective, [Sun] has updated the look and feel. It looks good. It's
cleaner, and it's more modern."
http://www.computerworld.com/developmenttopics/development/java/story/0,1080
1,96346,00.html?nas=APP-96346
---
** Sun Releases New Version of Java for Servers, Desktops **
Highlights:
- In addition, Austin said J2SE 5.0 will spark the creation of new tools for
developers, particularly new profiling and analysis tools. "We have a cool
technology called byte code insertion, so now you can profile in real-time."
J2SE 5.0 also enables developers to "pre-template" code, "so other analyzing
tools can read the metadata," he said.
http://www.eweek.com/article2/0,1759,1664580,00.asp
---
** A New Direction for Java **
Highlights:
- The result: "Java's beginning to wend its way into some pretty interesting
places," such as automobiles, said Schwartz. "I asked an automobile
manufacturer, 'What's the price at which, if you could sell online services
to the automobile, you could give away the automobile for free?' Without
batting an eye, that auto company's CFO said, '$220,'" Schwartz told his
JavaOne audience. "Now think about that. "Do you know a 17-year old who
would pay $5 to download a custom horn tone to his car? I do," he said.
- "It's not Sun thinking about putting services into an automobile, it's
Siemens and BMW," Schwartz said, returning to center stage after a
presentation in which a new BMW rolled out with an advanced Java-based
navigation and entertainment system.
http://www.eweek.com/article2/0,1759,1624150,00.asp
---
** Screenshots of J2SE 5.0 Look&Feels **
Windows XP File Chooser Dialog (from j5.0 beta)
http://java.sun.com/developer/technicalArticles/releases/j2se15/15art2.jpg
Redhat Linux File Open Dialog (from j5.0 beta)
http://java.sun.com/developer/technicalArticles/releases/j2se15/15art1.jpg
The new Ocean Theme
http://www.dubh.org/jdevimages/jdev_ocean_large.png
---
Comments on Synth
Synth is apparently a 'bare-bones' L&F designed specifically to allow
non-programmers to turn it into a custom L&F using simple XML. The article
"The Synth Look and Feel" in the next section gets more into the details.
An example XML file is also presented below. For an overview of the idea
behind Swing 5.0 see this article:
** Tiger on the Desktop **
http://weblogs.java.net/blog/chet/archive/2004/09/tiger_on_the_de_1.
** The Synth Look and Feel **
Highlights:
For the anxious, here's a quick example. The following XML code, taken from
example1.xml, defines a style named textfield and binds it to all text
fields in Synth. The result is that text fields look like the one in the
Motivation section.
<synth>
<style id="textfield">
<state>
<color value="white" type="BACKGROUND"/>
</state>
<imagePainter method="textFieldBorder" path="textfieldborder.png"
sourceInsets="5 6 6 7" paintCenter="false"/>
<insets top="5" left="6" bottom="6" right="7"/>
</style>
<bind style="textfield" type="region" key="TextField"/>
</synth>
Here's some code that loads the XML file into Synth and sets the current
look and feel to Synth:
SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(Example1.class.getResourceAsStream("example1.xml"),
Example1.class);
UIManager.setLookAndFeel(laf);
http://www.javadesktop.org/articles/synth/index.html )
---
l8r, Mike N. Christoff
- 3
- Print via Command LineHello NG.
I'm trying to write a tool which is able to print a PostScript documents via
the command line. The call I'm making is the following:
String s = "copy /b " + filename + " lpt1:";
rt.exec(s);
This is commented by the interpreter as follows:
java.io.IOException: CreateProcess: copy /b
J:\Tmp\KyoceraMita\PostScript\Philipp.prn.tmp lpt1: error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)
at PrintPostScript.print(PrintPostScript.java:82)
at PrintPostScript.main(PrintPostScript.java:38)
Error = 2 means, that the file or something else is missing. The problem is:
The same command typed into my command line (I'm using W2k3) produces the
desired result. What am I doing wrong? Thanks in advance,
Philipp Ciechanowicz
- 4
- What is a type error?Marshall <email***@***.com> wrote:
+---------------
| Joachim Durchholz wrote:
| > Actually SQL has references - they are called "primary keys", but they
| > are references nevertheless.
|
| I strongly object; this is quite incorrect. I grant you that from the
| 50,000 foot level they appear identical, but they are not.
+---------------
Agreed. The only thing different about "primary" keys from any other
key is uniqueness -- a selection by primary key will return only one
record. Other than that constraint, many databases treat them exactly
the same as non-primary keys [e.g., can form indexes on them, etc.].
+---------------
| To qualify as a reference, there need to be reference and dereference
| operations on the reference datatype; there is no such operation is SQL.
+---------------
Not in "ANSI SQL92", say, but there might be in most SQL databases!
[See below re OIDs. Also, SQL:1999 had a "REF" type that was essentially
and OID.]
+---------------
| Would you say the relational algebra has references?
+---------------
Don't confuse "SQL" & "relational algebra"!! You'll get real
relational algebraists *way* bent out of shape if you do that!
+---------------
| > (Some SQL dialects also offer synthetic "ID" fields that are
| > guaranteed to remain stable over the lifetime of a record.
|
| Primary keys are updatable; there is nothing special about them.
+---------------
I think he's probably talking about "OIDs" (object IDs). Most
current SQL-based databases provide them, usually as a normally-
invisible "system column" that doesn't show up when you say
"SELECT * FROM", but that *does* appear if you say "SELECT oid, *",
and may be used as a "primary" key even on tables with no actual
primary key:
rpw3=# select * from toy limit 4;
c1 | c2 | c3 | upd
--------+-------+--------------------------------+-----
fall | tape | My Favorite Thanksgiving | 16
xmas | book | My Favorite Christmas | 2
xmas | video | The Grinch who Stole Christmas | 4
summer | book | Unusual 4ths of July | 17
(4 rows)
rpw3=# select oid, * from toy limit 4;
oid | c1 | c2 | c3 | upd
-------+--------+-------+--------------------------------+-----
19997 | fall | tape | My Favorite Thanksgiving | 16
19998 | xmas | book | My Favorite Christmas | 2
19999 | xmas | video | The Grinch who Stole Christmas | 4
20000 | summer | book | Unusual 4ths of July | 17
(4 rows)
rpw3=# select * from toy where oid = 19998;
c1 | c2 | c3 | upd
------+------+-----------------------+-----
xmas | book | My Favorite Christmas | 2
(1 row)
rpw3=# insert into toy values ('fall','book','Glory Road');
INSERT 32785 1
rpw3=# select oid, * from toy where oid = 32785;
oid | c1 | c2 | c3 | upd
-------+------+------+------------+-----
32785 | fall | book | Glory Road | 21
(1 row)
rpw3=#
See <http://www.postgresql.org/docs/8.1/static/datatype-oid.html>
for how PostgreSQL treats OIDs [including some critical limitations].
-Rob
-----
Rob Warnock <email***@***.com>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
- 5
- SWT&JFaceHi,
is there any method to add WizardDialog to windows taskbar?
In general, dialogs don't appear on taskbar, but maybe anyone knows
some trick.
yarecki
- 6
- JTable selectHello,
Can anybody explain me how I can retrieve the value of a certain
clicked cell of a JTable?
thx
pat
- 7
- native method performance puzzleJust to be clear, I'm afraid that I can't do more than sketch my problem out
here, since it's customer-specific, but I'm hoping for some direction.
I'm testing two implementations of a data-processing API, one in pure Java,
one in native methods (windows dll). The process I am testing is disk I/O
intensive.
Running the same performance test over and over again I've found that the
pure Java implementation gives very consistent results, while the native
method version gives results that steadily get better over about a dozen
runs, finally ending up about the same at the pure Java implementation
(probably ultimately limited by disk thruput).
For example, test 1 might look like:
pure Java method : 12 sec
native method: 20 sec
test 5 like:
pure Java method: 11 sec
native method: 15 sec
test 10 like:
pure Java method: 12 sec
native method: 10 sec
What could be going on here? It sure feels like something is being cached,
but I'm not sure what.
Thanks,
--arne
- 8
- IBM Java 6 pre-release on LinuxFor those who are interested to try the new IBM Linux JDK 6 (pre-release),
here's a direct link:
https://www14.software.ibm.com/iwm/web/cc/earlyprograms/ibm/java6/
Haven't tried it on FreeBSD myself.
Cheers,
Ernst
- 9
- [ANN] Luxor XUL Standard Widget Toolkit (SWT) Layout Pack Now LiveHi,
I've uploaded the Luxor *Standard* Widget Toolkit (SWT) Layout
package that shows you how to turn SWT layout managers such as
FillLayout, GridLayout and others into easy-to-use XUL tags that you
can use in addition to the built-in XUL box layout system.
This preview includes XUL tags for
* FillLayout
* RowLayout
* GridLayout
* SashForm
Here are some examples to see what's it all about:
FillLayout In Action
--------------------
The FillLayout is mapped to the <fillbox> tag and you can use it like
any other XUL box. Example:
<fillbox>
<label value="Instructions:" />
<label value="1. Fill in your name" />
<label value="2. Fill in your age" />
<label value="3. Fill in your gender" />
<label value="4. Check the box for employment" />
<label value="5. Click on OK" />
</fillbox>
GridLayout In Action
--------------------
The GridLayout is mapped to the <gridbag> tag and the GridData is
mapped to the <griddata> tag. Example:
<gridbag columns="3">
<button label="B1" />
<button label="Wide Button 2" />
<griddata rowspan="2" fill="MAX">
<button label="Button 3" />
</griddata>
<button label="B4" />
<button label="Button 5" />
</gridbag>
SashForm In Action
------------------
The SashForm is mapped to the <splitbox> tag. Example:
<splitbox id="splitbox3">
<button label="One" />
<button label="Two" />
<splitbox orient="vert">
<button label="One" />
<button label="Two" />
<button label="Three" />
</splitbox>
</splitbox>
and so on and so forth
You can grab a copy a the luxor-contrib site @
http://sourceforge.net/project/showfiles.php?group_id=64067 (look for
the swt-layout) package.
Enjoy.
- Gerald
PS: For more info check out the Luxor Website @
http://luxor-xul.sourceforge.net
If you want to discuss the Luxor SWT package please join the
luxor-xul-user mailinglist @
http://lists.sourceforge.net/lists/listinfo/luxor-xul-user
For more info about SWT (Standard Widget Toolkit) check out the
website @ http://www.eclipse.org/swt
- 10
- 11
- [OT] eruditionOn 2008-02-12 03:12 +0100, Lew allegedly wrote:
> Daniele Futtorovic wrote:
>> confer:
>> "About Documents"
>> <http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#document>
>
> etc.
>
> That usage of "confer" is marvelous, simply delightful. I was just
> looking up that usage of the word the other day, coincidentally, in the
> context of the abbreviation "cf.". Sheer poetry to see it spelled out.
> Thank you.
>
You're most welcome.
- 12
- java e-booksPlease suggest a good e-book for a java beginner. Thanks.
- 13
- cglib/asm NoClassDefFoundErrorI'm having trouble running the cglib sample KeySample
http://cglib.sourceforge.net/xref/samples/KeySample.html. It compiles
fine, but when I try to run it, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/
objectweb/asm/Type
at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:180)
at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:66)
at Test.main(Test.java:8)
To ensure asm.jar is definitely in the classpath, I'm running it as:
java -classpath .;$JAVA_HOME/lib;$CGLIB_LIB/cglib-2.1_3.jar;$CGLIB_LIB/
asm.jar;$CGLIB_LIB/aspectwerkz-core-0.10.RC1.jar;$CGLIB_LIB/ant.jar;
$CGLIB_LIB/asm-attrs.jar;$CGLIB_LIB/asm-util.jar;$CGLIB_LIB/jarjar.jar;
$CGLIB_LIB/junit.jar KeySample
The call in net.sf.cglib.core.KeyFactory which is triggering this is:
private static final Type KEY_FACTORY =
TypeUtils.parseType("net.sf.cglib.core.KeyFactory");
The call at net.sf.cglib.core.TypeUtils.parseType is:
public static Type parseType(String s) {
return Type.getType(map(s));
}
map is a private method which effectively transforms the input into
"L"+s.replace('.', '/'))+";" (i.e. "Lnet/sf/cglib/core/KeyFactory;").
I've traced through this with Eclipse, so I'm absolutely certain that
this is what's being passed to Type.getType. Based on the exception
and my trace, I don't think it's getting as far as calling
Type.getType, though.
If I add the lines:
org.objectweb.asm.Type t = Type.getType("Lnet/sf/cglib/core/
KeyFactory;");
System.out.println(t.getClassName());
to the sample code, those lines execute properly (i.e. it prints
"net.sf.cglib.core.KeyFactory"), but then it throws the exception
above.
The fun part is that I get the same result if I re-compile the
original sample code and run with the no-dependency version of cglib:
java -classpath .:$JAVA_HOME/lib:$CGLIB_LIB/cglib-nodep-2.1_3.jar
KeySample
I suspect that there's something truly screwed up with my environment,
but I haven't seen any other overt misbehavior like this. Any ideas?
- 14
- Printing Frames With JavascriptI apologize if this is the wrong group for this but I have looked for
an answer with no luck. I have the following frame setup on a site I
am working on:
http://img98.imageshack.us/img98/6238/frameprint1lr.jpg
I want to add a java print button in frame 3 that will then print
frames 3, 4, and 5 when clicked (preferably as laid out on screen in
landscape mode). Is something like this possible?
Thanks.
- 15
- JSP <jsp:useBean ... /> tag: Difference between 'class' and 'type'Hello,
I'm trying to gain a better understanding of the included tag libraries
with JSP. The <jsp:useBean tag seems farily straightforward, in that it
sets a page variable from an object in any scope, with a variety of options.
I see examples listed that interchange the 'class' and 'type' attribute,
but to me it's not real clear as to their distinction. Can anyone
explain their difference?
One thing I have noticed is that if I don't yet have a variable declared
in the given scope, using the 'type' attribute causes an exception to be
thrown, whereas the 'class' attribute does not. It seems that when I
specify "class", it actually creates a new instance of the specified
variable / bean.
Thanks!!
-Sean
|
|
|