Any good examples of using hashCode?

I am creating a simple test class of a date object using getYear, getMonth, GetDay, compareTo, equals and hashCode. Ive got everything else working fine, but im wondering if I am getting the correct output from the hashCode method. What exactly does the hashCode method do? anyone got a good example of using it and what it outputs?

the name of my date class - here's the rest of my code if you want to verify it:
package Final;
import java.util.GregorianCalendar;
import java.util.Calendar;
public class SimpleDate
/** Creates a new instance of SimpleDate
public SimpleDate()
     GregorianCalendar greg = new GregorianCalendar();
          year = greg.get(Calendar.YEAR);
          month = 1 + greg.get(Calendar.MONTH);
          day = greg.get(Calendar.DATE);
/** Creates the setDate method which allows the day, month, and year of the
* date to be specified
public SimpleDate( int year, int month, int day )
setDate( year, month, day );
/** Sets the day, month, and year variables for the date
public void setDate( int year, int month, int day )
GregorianCalendar greg = new GregorianCalendar();
greg.set(Calendar.YEAR, year);
greg.set(Calendar.MONTH, month-1);
greg.set(Calendar.DATE, day);
this.year = greg.get(Calendar.YEAR);
this.month = 1 + greg.get(Calendar.MONTH);
this.day = greg.get(Calendar.DATE);
/** Defines the method getYear which gets the integer value which represents
* the year in the date
* @returns int year
public int getYear()
return year;
/** Defines the method getMonth which gets the integer value which represents
* the month in the date
* @returns int month
public int getMonth()
return month;
/** Defines the method getDay which gets the integer value which represents
* the day in the date
* @returns int day
public int getDay()
return day;
/** Defines the boolean method equals which compares two dates to see if they
* are equal
* @returns boolean equals
public boolean equals()
return equals;
public int compareTo()
return comparable;
public int hashCode()
return hashcode;
public String toString()
String string1 = new String();
return string1;
/*************Built-in Self Test************/
public static void main(String[] args)
SimpleDate date = new SimpleDate();
SimpleDate date2 = new SimpleDate();
date.setDate(2005, 11, 4);
System.out.println("Day, Month and Year: " + day + " " + month + " " + year);
date.getYear();
System.out.println("The year selected is: " + year);
date.getMonth();
System.out.println("The month selected is: " + month);
date.getDay();
System.out.println("The day selected is: " + day);
date2.setDate(2004, 11, 4);
System.out.println("The first date selected equals the second date selected: " + date.equals(date2));
//System.out.println("The first date selected is comparable to the second date selected: " + date.compareTo(date2));
//How do I implement compareTo?
System.out.println("The hashcode for the first date selected is: " + date.hashCode());
System.out.println("The hashcode for the second date selected is: " + date2.hashCode());
// ***** Instance Variables *****
static int year;
static int month;
static int day;
boolean equals;
int comparable;
int hashcode;
}

Similar Messages

  • Any good example of IMAQ Correlation vi.

    Hello,
    I am trying to understand the use of IMAQ Correlation VI for the purpose of feature tracking among the series of images for my experiment using Normalized Cross-Correlation technique. Kindly see the attached VI, it just not making any sense to me. Kindly suggest and any good example will be very helpful. Thanks in advance.
    Attachments:
    Correlation-1.vi ‏61 KB

    It is a little hard to tell what you are trying to do from your explanation. You would have a much higher success rate if you posted on the Machine Vision board in the Most Active Hardware Boards. Also, if you post an example it is good practice to state the version of software used. It is also helpful to save it to a previous version to allow a broader audience to see the example.
    You stated that you have a "purpose of feature tracking among the series of images for my experiment using Normalized Cross-Correlation technique." Could you post this with a more detailed explanation on the Machine Vision board? Also to explain what type of suggestions or advice you are looking for from the example that you posted would allow myself and others on the forums to understand what you are looking for here.
    Vince M
    Applications Engineer

  • Any good tutorials for using jQuery and ColdFusion to build mobile apps

    Does anyone know of any good tutorials for using jQuery and ColdFusion to build mobile apps?
    Thanks!
    Lee

    I was just this moment looking at this website http://jquerymobile.com/
    Then for you a Google search on Jquerymobile and coldfusion
    http://www.google.co.uk/search?q=jquerymobile+and+coldfusion&ie=utf-8&oe=utf-8&aq=t&rls=or g.mozilla:en-GB:official&client=firefox-a
    http://jquerymobile.com/resources/
    Brings me onto this tutorial
    http://www.raymondcamden.com/index.cfm/2011/8/26/Making-jQuery-Mobile-templates-even-easie r--with-ColdFusion

  • ADF: any good examples on inserting a new record

    Hi, I'm currently developing a
    web based application (using jsp + struts on top of ADF)
    and I've seen many many demos and viewlets on
    how to create a page that reads a list of employees
    or master-detail relationship of records.
    However, when I try to make a page which can insert
    a new record (ex. new employee, new department, etc),
    I am baffled, because I couldn't find a good example
    that showed me how to do it.
    Has anyone have a good example?
    thank you.

    Did you check the tutorials page?
    For example:
    http://otn.oracle.com/products/jdev/collateral/tutorials/9050/bizcomp_jsp_tut.html

  • EPUB with video and other functionalities - any good examples?

    Dear fellows,
    I'm in search of good examples of Epubs (electronic books or publications) with embedded video and eventually other advances functionalities. Can you mail me or refer me to good examples?
    Many thanks
    Knud Lindholm Lau
    Copenhagen

    Thanks Steve.
    Still as an ignorant: What does this mean for the possibility to read EPUBs sith embedded video and audio? Is Ibook the format of Ipads and and are these the only devices capable of running embedded video right now?
    Yours Knud

  • Any good example using JSF to perform search?

    is there a good design pattern I can find somewhere
    that uses jsf to search a list of words in a database
    and returns the definiation on the same page
    for example
    mywords.jsp
    submit jsf action
    bean searches mysql
    back to the same page mywords.jsp with the results listed
    thanks

    It is a little hard to tell what you are trying to do from your explanation. You would have a much higher success rate if you posted on the Machine Vision board in the Most Active Hardware Boards. Also, if you post an example it is good practice to state the version of software used. It is also helpful to save it to a previous version to allow a broader audience to see the example.
    You stated that you have a "purpose of feature tracking among the series of images for my experiment using Normalized Cross-Correlation technique." Could you post this with a more detailed explanation on the Machine Vision board? Also to explain what type of suggestions or advice you are looking for from the example that you posted would allow myself and others on the forums to understand what you are looking for here.
    Vince M
    Applications Engineer

  • Any one found any good templates to use with BC?

    Hey all,
    just wondering if anyone has found some good templates I can use for ecommerce sites
    Thanks,
    Dan

    BC is a relativly unique CMS and the type of template depends on your skil levels with the system and HTML, CSS, Javascript etc.
    http://www.tribevita.com/ is a great source for ready to go made BC templates.
    BC itself has some pre-made templates when you make an account you can choose from. The latest ones offfer more features but are a little more complex compared to the older ones using things like jQuery for fading banners etc.
    You can obtain any sort of stand alone HTML only template from a number of sites such as Template Monster which you can then work to transition into BC converting them into templates, replacing elements with web apps, modules and content holders etc. This of course requires people to have  good to high knowledge of BC and HTML, CSS.... etc.

  • TS3090 Is there any good way for using a network account locally on the server?

    We have a bunch of macs at home. I want to be able to login to a laptop and have my account (home dir) in sync with de desktop account in a noninvasive way. 
    For achieving this I thought  promoting one imac to be a network profile server would be a good solution.
    This way we can work on any machine and sync portable home directories (phd) with our laptops.
    The server should also be usable as a workstation.
    One problem is: is possible to login on the server (locally) and work in a network account?
    I know it is possible, but this article describes issues.
    Also i am concerned about perfomance because files wil be mounted over afp rather than being on the harddisk. (one workaround would be to have a phd on the desktop, this would however not be possible on the server itsself (unless you have two copies of the home directory there))
    Does anyone have any experience with a simular situation or perhaps some other helpfull insights.

    Sorry, you must have edited your message. When I saw it, only the title showed .
    Embedded is what you want. You can change the windows apperance (e.g. hide the scroll bars) by changing the VI properties.
    Uncheck "request control" in the web publishing wizard, and it will be read only.
    Works fine here in LabVIEW 7.1. I don't remember if 6.1 had any limitations.
    LabVIEW Champion . Do more with less code and in less time .

  • Any good manual for using preview on mac?

    Where can I find a good tutorial for preview. 

    Why not use its help menu?  Or...
    Mac 101: Preview

  • Any good books on using Oracle Workflow?

    I'm trying to get my hands around the topic of workflow, specifically using Oracle Workflow Builder and was wondering if anyone knew of any decent books out there....

    Oracle documentation may be of help.
    Try these.
    http://download-west.oracle.com/docs/cd/B13789_01/workflow.101/b10284/toc.htm
    http://download-west.oracle.com/docs/cd/B13789_01/workflow.101/b10285/toc.htm

  • Any good examples of content built for the iphone?

    Hi Guys
    Just testing and re-designing our content for the iPad on the iPhone. Colin fleming has advised designing a consistent area in your layout for page swipe and navigation and designing interactivity only in the upper area of the page. Just wanted to see some examples of this?
    Cheers
    Gemma

    A quick search in the app store found this: http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=285180322&mt=8

  • Are there any good code examples for displaying preview images in the storefront?

    I can gather other info using folio.xxx, but can not find any good examples to use for preview images.  Tried folio.getPreviewImage() with no success.  Oh, I should mention it is version 2.  Plenty of examples for version 1.
    Perhaps if I get a little more specific.
    I am calling up the folios via:
           adobeDPS.libraryService.folioMap.addedSignal.add(function(folios) {
                for (var i = 0; i < folios.length; i++) {
                    addFolio(folios[i]);
            }, this);
    This eventually works into a function where I am gathering and displaying folio data:
         var productId = folio.productId;
        var html  = "<div id='" + productId + "'>";
            html +=     "<a href='#'><img class='shadow' width='120' src='' border=0 /></a>";
            html +=     "<br /><span class='bold'>" + folio.title + "</span>";
            html += "</div>";
        this.$el = $(html);
    folio.title works fine to pull up the title, but I can no longer use folio.getPreviewURL in v2.  What code should I be using to set the src to the preview image?
    Thanks

    Have you looked at the default implementations of the library?
    In FolioItemView's render function, there is a function(follow the nested functions!):
    setTimeout(function(){ scope.loadPreviewImage() }, 100);
    It references this function (this doesn't copy well):
    loadPreviewImage: function() {
    if (this.el.parentElement) {
    var transaction = this.folio.getPreviewImage(135, 180, true);
    transaction.completedSignal.addOnce(this.getPreviewImageHandler, this);
    Going deeper, into the getPreviewImageHandler function is where you see the url value..
    if (transaction.state == adobeDPS.transactionManager.transactionStates.FINISHED && transaction.previewImageURL != null) {
                                  this.$el.find(".folio-thumb").attr("src", transaction.previewImageURL);
    Within the example is also code for supplying a preview when the Adobe API is not available:
    (Within the render function)
    var json = this.model.toJSON();
    $folioThumb.attr("src", json.libraryPreviewUrl);
    If you're making any changes to where the preview is displayed, you can just swap out the class ".folio-thumb" to whatever the class (or id) is of the element you're wanting to render the preview in.

  • Any good XML over HTTP examples?

    Hi,
    Does anyone know of a good example of using a XML over HTTP web service? Especially one that would be easily graspable by someone who's new to web services (read: me)?
    Is there a way to generate stub classes from a WSDL? I tried to do it in NetBeans but it didn't work, maybe NetBeans expects SOAP web services?
    Thanks

    Hi,
    This use case seems to be best handled using a RESTful Web Service. Check the Restlet project for a supporting framework:
    http://www.restlet.org/documentation/1.0/tutorial
    Best regards,
    Jerome
    http://www.restlet.org

  • Any Digester Examples

    I am trying to use Digester to parse an XML file. I am having trouble finding complete examples on how to impliment it.
    I'm just trying to parse a simple XML file with the following syntax:
    <mappings>     
    &#160;&#160;&#160;&#160;&#160;<variable name="string"> string </variable>
    &#160;&#160;&#160;&#160;&#160;<partial match="string"     replace="string" />
    &#160;&#160;&#160;&#160;&#160;<special match="string" class="class name" />
    &#160;&#160;&#160;&#160;&#160;<complete match="string" replace="string" />
    </mappings>
    I need it to grab both the attributes and the values. Does anybody know how to do this? Are there any good examples on the web?

    Try to use a sax parser (http://www.saxproject.org/)
    the only thing you have to do is create a class (MyHandler) extending a ContentHandler and implementing the methods
    void characters(char[] ch, int start, int length)
    void endDocument()
    void endElement(String uri, String localName, String qName)
    void startDocument()
    void startElement(String uri, String localName, String qName, Attributes atts)
    then,
    XMLReader r = XMLReaderFactory.createXMLReader();
    r.setContentHandler(new MyHandler());
    try {
    r.parse("http://www.foo.com/mydoc.xml");
    } catch (IOException e) {
    System.err.println("I/O exception reading XML document");
    } catch (SAXException e) {
    System.err.println("XML exception reading document.");
    any element begin/end/characters events will call the methods defined into MyHandler class...

  • Good Ex for Using Transformation Op in JDev BPEL PM (beta)

    Hello,
    I am looking for some good examples for using the transfomation/mapper capability in the Beta 3 version of BPEL PM. Any suggestions?
    Thanks,
    Sean

    Go through the following sample :
    $ORACLE_HOME\integration\orabpel\samples\demos\XSLMapper
    This will give you the high level functionalities. If you have any specific requirement please let us know.
    Thanks,
    Rakesh

Maybe you are looking for