Romeo Kienzler

Greenhorn
+ Follow
since Aug 15, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Romeo Kienzler

Rob Prime wrote:When you access an object, the set uses the hashCode of the object to determine the bucket. It then goes through the linked list using equals.

If you use the default hashCode implementation of Object, then it will most likely look in the wrong bucket. It there will not find an object that is equal, so nothing is found.



Hi Rob, I wasn't completely aware of that. I thought if hashCode isn't overwritten all objects are ending up in the same bucket and the data structure will degenerate to a simple list. But since the default implementation of java.lang.Object#hashCode returns the heap address it definitely will end up in a different bucket. Some logical reasoning about that fact would have given me the answer. So thanks a lot!

Cheers,
Romeo
14 years ago

Campbell Ritchie wrote:I am afraid it might not help; she was asking last November. Please look at this FAQ.



Hi Ritchie,

sometimes I'm searching for a particular solution to a problem and after I've found the solution I paste it to the forums where it hasn't been answered. Just for letting future searchers be more successful. But if this is undesired, I won't do it on JavaRanch in future.

Cheers,
Romeo
14 years ago

Rob Prime wrote:
Those Java statements won't compile; the bulk methods do not return a set but a boolean. The statements should be as followed (of course the Set implementation can change):



You're right! Next time I'll paste it to my compiler first.

Rob Prime wrote:
Almost right. With HashSet and LinkedHashSet, you need to override both equals and hashCode. For TreeSet, you can go two ways:
- have your classes implement Comparable
- use a custom Comparator



With HashSet and LinkedHashSet you don't need necessarily overwrite hashCode. But data access will be a bit slower.
Since TreeSet is sorted, and this feature isn't needed for determining the cardinality of a Set, I consider the implementation of a comparator as unnecessary overhead.


14 years ago
I think what Nina is talking about are the common mathematical set operations like intersection, difference, ...





Fortunately, the all implementers of the Set interface in Java are taking care of the uniqueness of all items (in their mathematical sence).
But this works only for basic Java types (int, String, ...) and not for custom types.
So if you use custom types you must override the equals(Object o) - Method from the Object class.


So for Nina's problem the following mathematical formula is used:



The corresponding Java implementation is very simple:





Hope this helps.




Regards,

Romeo Kienzler
romeo (#) ormium.de
14 years ago
Hi!

Try to add the following two jars to the classpath of your client application:

c/Program Files/IBM/SDP70/runtimes/base_v6/lib/jtaPrivate.jar
c/Program Files/IBM/SDP70/runtimes/base_v6/lib/jtsPrivate.jar

That should help!

Regards

Romeo
15 years ago
Hi

Now I got my results, I passed

To verify your results got to https://www.certmanager.net/sun_assignment/assignment.html
, log in and go to "Test History". Here the SCJD should apear, if you have more than 320 points, congrats!!!

Greetings

Romeo
Hi Jay,

I thinks enrolled means only, that you passed the SCJP Certification and you are now able to do other exams like the SCJD, SCBCD, SCWCD, ...

I haven't found a way to see the actual status of my SCJD yet unless I submitted it on 12/1/07 wich is already 5 weeks ago.

I'll wait two weeks more and after that I'll contact SUN

Kind Regards,

Romeo
[ January 03, 2008: Message edited by: Romeo Kienzler ]
Hi!

I've implemented the singleton pattern for a data access object. Do I have to synchronize the "getInstance()" method of that singleton? Please have a look at the provided code and tell me if two threads accessing that method simultaneously can create two instances of that class.



So what can happen is that two threads are entering line "X" and creating an instance of X. An even worse case is that thead A creates an instance of X and returnes it and after that thread B creates an instance of X and returns it. B and all following threads are working with the instance of X which thread B created, but thread A works with his own instance.

Are you sharing my opinion?

If yes, I think there are two solutions of that problem:

1. Synchronize on the class instance of X


2. Creating the singleton instance in a static constructor

So the instance is created while the classloader loads the class. Would this prevent a second thread loading the same class at the same time from overwriting the reference to the first instance?


A even worse feeling you can get if you decompile such singletons and have a look at the byte code because here you can see that the Java commands used are far away from beeing atomic Here the examples from above:



So I hope you have some suggestions to the solutions 1 and 2.

Thanks a lot

Greetings

Romeo
[ November 15, 2007: Message edited by: Romeo Kienzler ]
Hi Marc,
some suggestions:

a room cannot be uniquely identified

Use the "position" / recNo of the record in the file as primary key,
see https://coderanch.com/t/189413/java-developer-SCJD/certification/search-update


a customer cannot book a room for certain periods, eg. in advance 10/5/2007 to 10/10/2007

This is not a requirement

cannot check when a room is booked(ie. between certain date) only when its available

This is not a requirement


Greetings
Romeo
Hi Archana,

1. I think it is ablolutely ok to use the "position" of the record in the database file as a primary key since there is no other option. Don't forget to document it in choises.txt

2. Google for optimistic locking vs. pessimistic locking. You can achieve optimistic locking by the following update scenario:

- db.lock(recNo)
- db.read(recNo) (check if there is the record is already booked, if so, throw an exception)
- db.update(rechno,.....)
- db.unlock(recNo)

Greetings
Romeo
Hi,
10 months ago my company bought the two vouchers for me (Admission and Essay). Now I'm neary finished but the voucher for the Essay is only valid through 1st of december 07.

Does anybody know how much time SUN takes between the Submission and the first possible date for the essay?

In other word, when should I sumbit my jar latest when my voucher is valid to 1st of december 07?

Thanks a lot,
greetings,
Romeo
Hi Pedro,
please see this thread.

So I think you have to validate. The only question ist WHERE to validate. In the DTOs or in the database itself.

Greetings,
Romeo
[ August 15, 2007: Message edited by: Romeo Kienzler ]
Hi,
please take care, you are not allowed to use classes from the java.nio.*-Package.

This only as a hint

Greetings,
Romeo
[ August 15, 2007: Message edited by: Romeo Kienzler ]
Hi,
I think data validation is necessary !

A simple exmple:
You update a Record like Palace, Smallville, .... with an String-Array containing "A cool and fancy name with a length of over 64 characters....",null,....

Depending on your design you are overwriting existing data in your database!

My requirements say that we have to implement "database functionality". So if you have a relational database you define the type of every field while creating a table. (Length and type using varchar(length),date, decimal,..). So thats exactly what you have to do here.

I implemented the following validations in the database-layer:
1. Length of every field doesn't exeed the maximum size
2. "rate" is parsable to float
3. "size" is parsable to int
4. "smoking" is indirectly parsable to boolean (is element of {"y","Y","n","N"}
5. "date" is parsable to java.util.Date using "DateFormat"

Otherwise I throw a RuntimeException (like JDBC is doing also)
[ August 15, 2007: Message edited by: Romeo Kienzler ]