• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stuck in JDK 1.1.8

 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm in the process of updating hardware so I can work with the Java 2 platform. While waiting, I've tried to use the javaranch.common package.
I've been able to create a GDate object, but had no luck with a JDate object.
Is this because I'm using JDK 1.1.8? Or should I keep plugging away?
thanks,
Pauline
 
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you getting a specific error when trying to create the JDate object?
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see anything in the code that I know would create a problem, but I'll ask the author.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marilyn (enjoy vacation!).
You're right Amber, I hadn't provided a whole lot of info...

...my test code looks like this:
-------------
GDate testGDate = new GDate( ) ;
JDate testJDate = new JDate( ) ;
System.out.println( "This is a GDate: " + testGDate ) ;
System.out.println( "This is a JDate: " + testJDate ) ;
-------------
There's actually no compiler or run-time errors, but what it prints out is interesting:
This is a GDate: 2001/6/26
This is a JDate: com.javaranch.common.JDate@bfc45d
(same result several times)
thanks,
Pauline

[This message has been edited by Pauline McNamara (edited June 26, 2001).]
 
Amber Woods
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Pauline, I ran into the same problem when testing. JDate does not contain a method toString() like GDate so it seems to send back garbage in the print statement. I think you have created the JDate object correctly but you can't quite tell in the print statement. Now you just need to decide what methods in JDate to use for the assignment.
Does this make sense?
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amber is correct. You have a JDate object. To check all you have to do is use the testJDate.get() and you'll see that JDate's attribute j is zero.
Good catch Amber
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Garbage? GARBAGE?!
As Amber pointed out, JDate doesn't define a toString() method, so the toString() method of its superclass (Object) is what gets called.
According to the Java API documentation, the toString() method of Object:

...returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())



And the hashCode() method of Object:

...As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (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.)


So System.out.println( testJDate ) gives you the fully qualified class name of JDate plus an "@" plus a representation of the memory address where the object (its reference?) is stored.
[This message has been edited by Michael Matola (edited June 26, 2001).]
[This message has been edited by Michael Matola (edited June 26, 2001).]
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get to keep playing.
Hey Amber, thanks for the great tip!
And I don't even have to hunt too long for a method, thanks Richard.
Wow, Michael, I never expected to really find out what that garbage, uh, I mean, hash code address meant.
How many times do I get to say thanks in one post?
Gratefully yours,
Pauline
 
Michael Matola
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem. I think this kind of stuff can be tremendous fun to track down. The Java API documentation is a great resource, and I love poking around the source code -- it's quite amazing to me how much Java is written in Java.
If you look at the source code for Object, you'll notice that the code I quoted from the documentation for toString() is the actual real-live code for that method. Way cool. (It's only hashCode() that you can't get at because it's a native method.)
 
Destroy anything that stands in your way. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic