I am not able to understand this java program

What is the output of bellow code ?
public class Bean{
    private String str;
    Bean(String str ){
        this.str = str;
    public String getStr() {
        return str;
    public boolean equals(Object o){
        if (!(o instanceof Bean)) {
            return false;
        return ((Bean) o).getStr().equals(str);
    public int hashCode() {
        return 12345;
    public String toString() {
        return str;
import java.util.HashSet;
public class Test {
    public static void main(String ... sss) {
        HashSet myMap = new HashSet();
        String s1 = new String("das");
        String s2 = new String("das");
        Bean s3 = new Bean("abcdef");
        Bean s4 = new Bean("abcdef");
        myMap.add(s1);
        myMap.add(s2);
        myMap.add(s3);
        myMap.add(s4);
        System.out.println(myMap);
}(Choose correct one from multiple bellow)
1) das abcdef
2) das abcdef das abcdef
3) das das abcdef abcdef
4) das
What i understand is that the following constructor
Bean(String str ){
        this.str = str;
    }is used to initialize the instance variable
private String str;then we have overridden the equals method, in this method we first check if o is not an instance of Bean class whereby we return false
then we are calling getStr() and equals(str)
return ((Bean) o).getStr().equals(str);the getStr() method is going to return the instance variable we initialized. SO we will be having something like
str.equals(str) Here I am not clear what is going to be the output. Please explain in detail

1. [das, abcdef]
map create a pair key - value, similar to Dictionary.
"Hash map structures consist of an internal array where elements are stored. Since the internal storage is an array, clearly there must be a mechanism for determining an index into the array for an arbitrary key. In fact, the mechanism needs to give an integer index value which is smaller than the size of the array. This mechanism is called the hash function. In Java hashed based Maps, the hash function converts any object into an integer that fits into the internal array. You don't have to look hard to find an easily available hash function: every object has a hashCode() method which returns an integer value. To map that value into any array, it is sufficient to convert it to a positive value and take the remainder after dividing by the array size. "
you will get the same hashcode for the same value!

Similar Messages

  • I am not able to run the java Program

    Hi All,
    I am not able to run a java program... I am able to complie the program sucessfully when i am trying to run it i am getting a error:
    Exception  in thread "main" java.lang.NoClassFoundError : filename
    i have complie and run my programs frequently but now i am not able run my prevoius examples also ...
    Can u any body help me out...... I have also update the latest version of JRE but still my problem is not sloved.
    Thanks & Regards,
    Ravi

    Make sure you take package structure into account.
    If you have say
    package testing.things;
    public class Test
        public static void main(String[] args)
            System.out.println("World Hello");
    }in file Test.java, you compile it with (assuming your current working directory is at the folder in which the source file is located).
    javac -d . Test.javaand run it with
    java testing.things.TestThe -d . option creates the output at the current directory (with a folder structure matching your package structure).
    #

  • Am not able to run the java program - pls help

    1. I installed java in the below path
         c:\program files\java\jdk1.5.0
         c:\program files\java\jre1.5.0
    I set the path in
         User variable i. variable name: path
              ii. variable value: c:\program files\java\jdk1.5.0\bin
    when I compile it in command prompt-applying javac ? it performed successfully-shows
    options like ?g create all debug info, -g : new Generate no debug info etc.,
    But am not able to run the file. It shows error msg.
    2. I specified the same name for file name & class name.
    3. Java <class name>
         Exception in thread ?main?java.lang.NoclassDeffoundError: <class name>
    4. Java ?cp <class name>
         Unrecognized option: -cp.<classname>
         Could not create the Java Virtual Machine
    5. Java ?classpath . <classname>
         Exception in thread ?main?.java.lang.unsupported classversionError: <classname>
         <unsupported major.minor version 49.0
              at java.lang.classloader.defineclass0<native method>
              at java.lang.classloader.defineclass<unknown source>
                   --and many listed below?
    6. Java ?classpath c:\program files\java\jdk1.5.0\bin <class name>
         Exception in thread ?main?java.lang.NoclassDeffoundError: <class name>
    7. I re-installed the java, but still the problem continuing.
    pls help... its very urgent

    Is the java class you compiled/calling in the default package? If it is not, you will have to call it by the fully qualified name.
    e.g.
    package com.mycompany.myproject;
    public class MyClass {
        public static void main(String[] args) { }
    }This would be called as "Java com.mycompany.myproject.MyClass" and must contain a main method with signature as above.
    You would have to call this from folder where the compiled classes are located. If using package, you would call from directory at level of top most package so com folder in this example as Java will look at each package name in qualified name and try to traverse directories with those same names to get to .class file matching class name specified. To avoid this, your newly compiled .class files must also be in your classpath.
    Hopefully that helps.
    --Kevin                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Not Able to Run A java Program!!!!!!!!!!

    Hi Gurus
    I have Change my Previos Version of Jdk Now I am getting This Error.
    Exception in thread "main" java.lang.UnsupportedClassVersionError: test (Unsuppo
    rted major.minor version 49.0)
            at java.lang.ClassLoader.defineClass0(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)

    Hi Michael
    I did the same thing not able to get it.I am using java -version its give me
    java version "1.3.1_01"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
    Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
    CLASSPATH=.;C\j2sdk1.4.2_10\lib\rt.jar;C:\apache-ant-1.6.5\lib;C:\apache-ant-1.6.5\lib\ant.jar;C:\jboss-4.0.2\client\jbossall-client.jar;C:\strutsTutorials\jakarta-struts-1.2.4\lib\struts.jar;C:\log4j\logging-log4j-1.2.13\dist\lib\log4j-1.2.13.jar;C:\log4j\logging-log4j-1.2.13\dist\classes;C:\jakarta-tomcat-5.0.28\webapps\validator\WEB-INF\lib\struts.jar;C:\XMLSerilization\xstream-1.1.3.jar
    Path=C:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common;C:\Program Files\lotus\notes\;C:\apache-ant-1.6.5\bin;C:\j2sdk1.4.2_10\bin;

  • Not able to execute one Java program from another one via. exec()

    Hi,
    I am new to this forum, so I might be asking a very trivial quetion.
    My program Ap1 is :
    class Ap1
    public static void main(String a[]) throws Exception
    Runtime rt=Runtime.getRuntime();
    Process p=null;
    p=rt.exec("javac,Pr.java");
    Runtime.getRuntime().exec("javac,Pr.java");
    When I run the above program, I get below error at the line 7(bold one):
    D:\batchwe>javac Ap1.java
    D:\batchwe>java Ap1
    Exception in thread "main" java.io.IOException: CreateProcess: javac,Pr.java err
    or=2
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at Ap1.main(Ap1.java:7)
    Path is set as below(which seems correct):
    D:\batchwe>path
    PATH=C:\Program Files\Java\jdk1.5.0_05\bin
    I am just wondering how to call one Java program from another one?!
    Please help.
    thanks
    Rashmi

    Hi diptaPB,
    Thanks for your suggestion.
    Here is how I tried it again, but not getting the desired output:
    Class Pr looks like below -->
    class Pr
    public static void main(String a[])
    System.out.println("hi from process");
    When I run 'Pr' from command prompt, i get the desired output:
    D:\batchwe>java Pr
    hi from process
    However, when I call 'Pr' from another program Ap2.java, it seems that it does not call 'Pr':
    class Ap2
    public static void main(String a[]) throws Exception
    Runtime rt=Runtime.getRuntime();
    Process p=null;
    String[] cmd=new String[2];
    cmd[0]="javac";
    cmd[1]="Pr.java";
    p=rt.exec("cmd");
    D:\batchwe>javac Ap2.java
    D:\batchwe>java Ap2
    ************* no output appears here***********************
    Looking forward for your help.
    regards
    Rashmi

  • Not able to run a java program on Sun Solaris

    Hi All,
    I am getting following error while running a java program. Can you help.
    Thanks,
    --Srini
    Error:
    Exception in thread "main" java.lang.NoClassDefFound

    Hi Sergi,
    Thanks for the info. I couldn't able to login because of my internet connection.
    Thanks,
    --Srini                                                                                                                                                                                                                           

  • Not able to run the Java Program from jre for the ARM processor

    Hi ,
    I am try to run the jre1.4.2 for the arm core (linux 2.6kernel) which i downloaded from the sun site.
    I am created the class file from the J2SE1.4 development kit. I created the simple HelloWorld Program and complied with J2Se then i copied that class file into my IMX board which has ARM core.
    When i run the commnd java HelloWorld i am getting this error
    dl failure on line 765Error: failed /dev/shm/jvm/j2re1.4.2/lib/arm/client/libjve
    Please give me some suggestion to solve this porblem
    Thanks in Advance
    Narendra

    I JRE i have download from the sun site . But when i am trying to run the simple helloWorld program in that it is giving the below error.
    error:
    dl failure on line 765Error: failed /dev/shm/jvm/j2re1.4.2/lib/arm/client/libjvm.so because /dev/shm/jvm/j2re1.4.2/lib/arm/client/libjvm.so: symbol __divdf3, version GCC_3.0 not defined in file libgcc_s.so.1 with link time reference.
    Can anybody help me in this how to solve this problem . I also searched in the forum but did not get any answer on that problem
    Thanks in advance.
    Narendra

  • I have a problem with my Iphone 4s since I did my first update at your Itunes, the bluetooth and the WiFi it is not workinhg anymore.  It is sad that companies like apple are not able to support thier sofware and business.  I went to a apple store at Sout

    I have a problem with my Iphone 4s since I did my first update at your Itunes, the bluetooth and the WiFi it is not workinhg anymore.
    It is sad that companies like apple are not able to support thier sofware and business.
    I went to a apple store at South Park, Charlotte NC,
    and found out the worst customer service (in my case)
    They don't have answers and don't understand about  "dont let any customer go away sad or mad"
    I explain to them that I did everything they said to fix the problem, even to dounload the iOS 6.1.3
    that was supposed to fix the problem.
    they said fix the problem in other phones but not in mine.
    So here I am with no wifi and bluetooth, with apple technicians and experts that don't know what to do with the problem that the sofware they developed cause in my iphone 4s.
    and the solution is for me to pay $199.00 US dollars for a problem that I did not cause.
    wich means to buy something else from apple to fix a problem that it is not my fault.
    Great! what a convenient solution.
    I would like to have an answer from you guys and see if someone there have a better answer for me that shows support, values and integrity as a grest company with solutions for your customers.
    Dont think that I want a new phone, I want mine fixed if is possible.
    Thank you very much and God Bless you!

    Apple isnt here. this is a user based forum for technical questions. The solution is to restart, reset, and restore as new which is in the manual after that get it replaced for hard ware failure. if your within your one year warranty its replaced if it is out of the warranty then it is 199$

  • "You're not able to purchase this product in your ...

    Second time posting this, as the first apparently failed...
    I've been subscribing to the Unlimited US plan for a few years now, as all of my family and most of my friends live in various parts of the US. For some reason, today, when I went to renew my subscription (which expires in 6 days), I got the message, "You're not able to purchase this product in your region.". I've never had this problem from Prague before and I can't understand why I'm having it now.
    Is there some reason for this or is it just a glitch that will soon be corrected?

    Nevermind... Whatever the problem was, it appears to have corrected itself.
    Thanks

  • Not able to understand chekpoint completely

    Hi all,
    i have gone through oracle manuals,but i m still not able to understand completely that how does it works
    can you plz tell me in simple terms so i can understand it.
    cheers
    amit

    Checkpoint (CKPT)
    At specific times, all modified database buffers in the system global area are written to the datafiles by DBWn. This event is called a checkpoint. The checkpoint process is responsible for signalling DBWn at checkpoints and updating all the datafiles and control files of the database to indicate the most recent checkpoint.

  • Not able to understand someclass=otherclass.class.methodinotherclass

    Hello all,
    I am trying to understand one application source code, in that i came accross the following assign ment:
    someclass=otherclass.class.methodinotherclass
    I am not able to understand why they used ".class"
    could any one explain me.
    excuse my english.
    Thanks in advance.
    regards
    vamsee
    Message was edited by:
    vamseebobby
    Message was edited by:
    vamseebobby

    Every object has a member named "class" which
    gets access to the ClassWhy doesn't the Object API show that member?Wait a minute, I goofed a bit. This will probably end up as more ammo for Norweed to use against me as he tries to prove he's competent whereas I am not o_O
    Every class definition has an implicit static member named "class" is what I meant to say. Every object has a "getClass()" method to return the same thing. That method is documented in the API docs, but the "class" implicit member isn't I guess.

  • [HP Expert Day] "You are not able to restore this system with the media"

    Welcome to HP Experts day! 
    I've got a long-standing problem since last year. Let's see if you can solve this! 
     I'll get straight to the point : 
    I am unable to perform recovery on my system. This is the error message : 
    It's a USB recovery media created with the HP recovery media utility on the same laptop. Tested to work correctly before I sent it for RMA on my SSD. It initially was running on a micron SSD. When I got it back, it was a samsung SSD instead, according to some benchmark results. 
    Laptop : HP Envy Spectre XT 13-2018TU
    P.S I've already opened another thread on this last year. 
    http://h30434.www3.hp.com/t5/Notebook-Recovery/Unable-to-boot-from-USB-recovery-media/m-p/2197929#M1... 
    But they were stumped. 

    I had this exact same issue on a Spectre XT Pro Ultrabook. 
    The original SSD failed and I was sent a replacement, was fortunate enough to be able to create a Recovery USB stick using the wizard in Windows. When booting from USB I received the message "You are not able to restore this system with the media".
    SOLUTION: You must NOT use the Recovery USB stick in any USB3.0 port (labelled SS). Using another USB port prevented this exact error message from appearing and I was able to complete the system restore process.
    I hope this helps someone, I signed up and posted here especially for this reason!

  • In Windows 7 using Adobe Reader XI (11.0.07) was able to copy an item (name, number, date) and paste in another document.  In Windows 8.1 using same version of Adobe Reader XI (11.0.07) not able to do this.  Any solutions?

    In Windows 7 using Adobe Reader XI (11.0.07) was able to copy an item (name, number, date) and paste in another document.  In Windows 8.1 using same version of Adobe Reader XI (11.0.07) not able to do this.  Any solutions?

    With computer running Windows 7 using the curser can select an item, then right click and select copy.   With computer running Windows 8 there is a hand instead of a curser therefore unable to select an item, therefore unable to copy.  Is there a way to have a curser rather than the hand?
    Eureka!!!   Just found by right clicking on the hand can then select “Select Tool” and then copy.  Hurray!!!

  • Adobe error and we could not able to solve this

    If we select a single item in the comment field, multiple edits were selected in the page. Please refer the attached screenshot. Number 1 and 2 indicates the edits that highlights when we select 1 item in the comment field which is indicated by number 3. It seems Adobe error and we could not able to solve this.
    Could you please kindly do the needful and let us know your comments?
    - Mohamed Sathakathllah
    Message was edited by: uamsathak

    Read this:
    http://forums.adobe.com/thread/931829

  • Wjen i trying to activate my personal file sharing  in system 10.4.11 it's not able to start this service so my network computers can't access my computer plz help or advice ??

    wjen i trying to activate my personal file sharing  in system 10.4.11 it's not able to start this service so my network computers can't access my computer plz help or advice ??

    When was the last time you did any of the following?
    Restart your computer?
    Repaired Permission & restarted your computer?
    Run "Repair Disk" from your install DVD?
    Please detail all you have done to resolve your issue.  Need this information so that the users can avoid the "been there, done that" scenario type responses.  This is to avoid repeating the troubleshooting you may have already tried.  Thank you. 

Maybe you are looking for

  • My computer won't detect any of my devices

    Hello everyone, I've been having this issue for a long time now. In april, I got a windows 8 computer. Everything works perfectly fine. It always detected my ipod classic (despite it being old), my ipad first generation and my iphone 4. After updatin

  • SUP and WSUS on the same server.

    Hi, My SCCM environment as follows: Windows Server 2012 R2 Standard, Configuration Manager 2012 R2, SQL 2012 SP1 CU7 WSUS 6.3.9600.163.84 . All these running on the same server. SCCM SUP role is enabled, WSUS using SQL Express database. This is Centr

  • Photo Booth effects didn't work properly

    so i was using photo booth in my MBP '13 mid 12 and noticed that the pop art effect didn't work properly. it kept telling me to step out of the frame after that the frame went freeze i don't know how to fix this any idea? i have upgrade to yosemite b

  • OS X 10.4.6 - RAW Conversion

    The last I heard in the "where are RAW support fixes contained" was that because AP uses CoreImage to convert RAW, they would be contained in OS X updates, i.e. 10.4.6. Has anyone verified if the RAW conversion problems have been fixed or not (I'm pa

  • MSS working time approval by project leader

    Hello all Gurus, We are implementing ESS / MSS with ECC6. We are in the need to approve time recorded in ESS. We have completed the time entry part. The problem comes in the authorization with MSS. We need the person responsible (project lead) in Pro