Object and reference accessing for primitives, objects and collections

Hi,
I have questions re objects, primitives and collection accessing and references
I made a simple class
public class SampleClass {
     private String attribute = "default";
     public SampleClass()
     public SampleClass(SampleClass psampleClass)
          this.setAttribute(psampleClass.getAttribute());
          if (this.getAttribute() == psampleClass.getAttribute())
               System.out.println("INSIDE CONSTRUCTOR : same object");
          if (this.getAttribute().equals(psampleClass.getAttribute()))
               System.out.println("INSIDE CONSTRUCTOR : equal values");
     public void setAttribute(String pattribute)
          this.attribute = pattribute;
          if (this.attribute == pattribute)
               System.out.println("INSIDE SETTER : same object");
          if (this.attribute.equals(pattribute))
               System.out.println("INSIDE SETTER : equal values");
     public String getAttribute()
          return this.attribute;
     public static void main(String[] args) {
...and another...
public class SampleClassUser {
     public static void main(String[] args) {
          SampleClass sc1 = new SampleClass();
          String test = "test";
          sc1.setAttribute(new String(test));
          if (sc1.getAttribute() == test)
               System.out.println("SampleClassUser MAIN : same object");
          if (sc1.getAttribute().equals(test))
               System.out.println("SampleClassUser MAIN : equal values");
          SampleClass sc2 = new SampleClass(sc1);
          sc1.setAttribute("test");
          if (sc2.getAttribute() == sc1.getAttribute())
               System.out.println("sc1 and sc2 : same object");
          if (sc2.getAttribute().equals(sc1.getAttribute()))
               System.out.println("sc1 and sc2 : equal values");
}the second class uses the first class. running the second class outputs the following...
INSIDE SETTER : same object
INSIDE SETTER : equal values
SampleClassUser MAIN : equal values
INSIDE SETTER : same object
INSIDE SETTER : equal values
INSIDE CONSTRUCTOR : same object
INSIDE CONSTRUCTOR : equal values
INSIDE SETTER : same object
INSIDE SETTER : equal values
sc1 and sc2 : equal values
...i'm just curios why the last 3 lines are the way they are.
INSIDE SETTER : same object
INSIDE SETTER : equal values
sc1 and sc2 : equal values
how come while inside the setter method, the objects are the same object, and after leaving the setter method are not the same objects?
Can anyone point a good book that shows in detail how objects, primitives and collections are referenced, especially when passed to methods. Online reference is preferred since the availability of books can be a problem for me.
Thanks very much

You are confusing references with objects.
This compares two object references:
if( obj1 == obj2 ) { // ...Whereas this compares two objects:
if( obj1.equals(obj2) ) { // ...A reference is a special value which indicates where in memory two objects happen to be. If you create two strings with the same value they won't be in the same place in memory:
String s1 = new String("MATCHING");
String s2 = new String("MATCHING");
System.out.println( s1 == s2 ); // false.But they do match:
System.out.println( s1.equals(s2) ); // trueIf you're using a primitive then you're comparing the value that you're interested in. E.g.
int x = 42;
int y = 42;
System.out.println(x == y); // trueBut if you're comparing references you're usually more interested in the objects that they represent that the references themselves.
Does that clarify matters?
Dave.

Similar Messages

  • Cross Domain User Access for Sharepoint 2013 site collection

    Hi All,
    We have three Domains , one is for client machines and  AD user access purpose and second one is production environment (only some of developers has access to this domain) and third one is SharePoint environment (Because External users needs to
    access my SharePoint sites) .
    now we need to access SharePoint site collections from my another two domain user accounts with out creating user account from SharePoint domain , how to enable this access?
    please advise.
    Thanks in Advance,
    Mani L

    Hi Mani,
    You're asking this question in the wrong forum, this forum is meant for suggestions and feedback on the forums themselves, not product support.
    I recommend reposting your question in the SharePoint forums here (or you can request that a moderator move this thread for you):
    http://social.technet.microsoft.com/Forums/en-us/home?category=sharepoint&filter=alltypes&sort=lastpostdesc
    Good luck.
    Don't retire TechNet! -
    (Don't give up yet - 12,950+ strong and growing)

  • How to find the number of references created for a given  object ??

    How to find the number of references created for a given object in a big application environment.
    That means, if i give any object name (of my application) as input, then how can i find the[b] number of references created for that particular object ??

    Please do not post the same question multiple times.
    As for your original question, there is no direct way to do it.
    Especially not the way you phrased it,
    since objects don't have "names".
    Applications also don't have "names".
    They have classes and instances.
    Also, there are 2 related issues, and I'm not sure which one is the one you asked.
    #1. Finding the number of references to the same object.
    Eg.
    Map<String,String> a = new HashMap<String,String>();
    Map<String,String> b = new HashMap<String,String>();
    Map<String,String> c = a;In this case, there are only 2 objects.
    The first object has (at least) 2 references pointing to it.
    The second object has (at least) 1 reference pointing to it.
    (There may be more, if the HashMap library keeps
    references to these things, or if the HashMap object has
    some internal cyclic references...)
    If you're asking this, then it can't be done.
    It's an active research topic in universities
    and software research labs, called "alias analysis".
    Type it in google, and you'll see people are working hard
    and having little success so far.
    #2. Finding the number of instances created from a class.
    In this case, what you have to do is to add a counter to
    the constructor of the class. Every time an object is constructed,
    you increment the counter. Like this:
       class MyClass
           public static int counter = 0;
           public MyClass( )  { counter++; }
        // Then later in your program, you can do this:
        MyClass a = new MyClass();
        MyClass b = new MyClass();
        System.out.println(MyClass.counter); // It should show 2Note: you won't be able to do this to every class in the system.
    For every class you care about, you have to modify its constructor.
    Also: when an object is deleted, you won't always know it
    (and thus you won't always be able to decrement the counter).
    Finalizers cannot always work (read Joshua Bloch's
    "Effective Java" book if you don't believe me), but basically
    (1) finalizers will not always be called, and
    (2) finalizers can sometimes cause objects to not be deleted,
    and thus the JVM will run out of memory and crash

  • On win 7 64 bit mozilla or IE 10  I get the following message This installation package could net be opened verify that the package exist and that you can access for contact the application vendor to verify this is a valid windows installer package I trie

    I get this following message when installing the latest itunes on mozilla or IE10 was working on this machine before crash and reinstalled for HP disc I tried at leat 15 times firewall off /on microsoft essentials on/off  on windows 7  64 bit  see  message
    This installation package could net be opened verify thatthe package exist and that you can access for contact the application vendor to verify this is a valid windows installer package

    If you are not already doing so, install from an Administrator account.
    If you haven't already done so, download the iTunes Installer from:
    http://www.apple.com/itunes/download/
    Then right click on the installer and select "Run as Administrator." (Even though you are using an admin account).
    If that doesn't work, try creating a new administrator account and installing from there.

  • I have updated to ios 7 and Microsoft outlook web access for work emails no longer works nor my remote access can you help

    I have updated to ios 7 and Microsoft outlook web access for work emails no longer works nor my remote access can you help

    This happened to me as well. I read somewhere else that resetting the network settings (General, Reset, Reset Network Settings) would help and it partially did. I get half (the folders) of the Web Access screen rather than a blank screen. I tried tihs a few more times and got the right half (the messages) on occasion but never the whole web page.

  • How to restrict the access of "InPlaceRecordsListSettings.aspx" and "InPlaceRecordsSettings.aspx" pages for some users and allow the access for some users?

    I have a requirement to restrict the access of "InPlaceRecordsListSettings.aspx" and "InPlaceRecordsSettings.aspx" pages for some of the users and allow the access for some of the users.
    I have applied the below code on the web.config file but this modification impacting only on the web application level not on the site collection and sub site level.  
    <location path="_layouts/15/InPlaceRecordsSettings.aspx">
        <system.web>
          <authorization>
            <deny users="*" />
          </authorization>
        </system.web>
      </location>
    <location path="_layouts/15/InPlaceRecordsListSettings.aspx">
        <system.web>
          <authorization>
            <deny users="*" />
          </authorization>
        </system.web>
      </location>
    When I tried the access on
    :<portno>/sites/<scname>/_layouts/15/InPlaceRecordsSettings.aspx">http://<servername>:<portno>/sites/<scname>/_layouts/15/InPlaceRecordsSettings.aspx page allowed the access for all users.           
    Please suggest the possible solution to restrict the access of "InPlaceRecordsListSettings.aspx" and "InPlaceRecordsSettings.aspx" pages on SharePoint2013.
    Thanks
    Ramasubbu

    You can't do it from OOTB. 
    _layout folder is accessible to the users if they have read access in any of the site even subsite.
    You can modify *.aspx file, add your custom control which will check user.
    [custom.development]

  • Where do i find the reference number for my preorder? and yes i no this is prob a dumb question but i cant find it anywhere......

    Where do i find the reference number for my preorder? and yes i no this is prob a dumb question but i cant find it anywhere......

        Hi droidboy52999,
    Your email won't have the same confirmation number as it was ordered over the phone. You will need the last name used for the order, the location code (this ends in 01) and an order number (five to six digit number). Please keep us posted if you need further assistance with this.
    Thank you,
    MariaC_VZW
    Please follow us on Twitter @VZWSupport

  • "Enable Access for Assistive Devices" is missing from Yosemite and my QuicKeys program depends on this to work.  Help!

    This is my second day trying to get my QuicKeys application to work in Yosemite, but "Enable Access for Assistive Devices," which QuicKeys needs to work, is missing from Yosemite.  I have gone through the entire System Preferences panel (Security and Privacy, Accessibility, Keyboard, etc.) without success - it's just not there.  I have checked this app in the Privacy pane and dragged
    "QuicKeysUserEventHelper" out of the QuicKeys Resources folder into the Applications folder so it could "appear" in the Privacy pane, and then checked it there. Is there any way to enable access for assistive devices - a Terminal command, perhaps?
    QuicKeys is my most used program, which I have had since its inception at least 10 years ago!  Help!

    Thank you for your reply!  I did everything that Startly recommended (actually, gb2), and when I dragged the QuicKeys Helper into the Privacy box. I didn't see it, but after I quit and restarted QuicKeys, it worked!  However,I had  first  dragged the QuicKeys app to the trash, emptied it, then restarted.  Next, I redownloaded QuicKeys from Startly and THEN I went to gb2's directions.  All together, my QuicKeys now works on my MacBook Air.  BUT NOW, I keep getting the warning that says that this version and activation code are already in use by another user!  I am also getting those warnings on my Mac Pro -  which had the same problem yesterday (QuicKeys not working), until I heard back from a Technical Advisor from Startly, who told me about trashing the app and redownloading from their site.  Last night, that version of QuicKeys worked WITHOUT my having to drag the QuicKeys Helper app into the Privacy pane.  Perhaps it is there, but invisible - the helper app is not visible on either of my computers' Privacy panes.
    OK, NOW WHAT DO I DO?  Every 20 seconds or so, I'm getting those annoying warning signs (on BOTH computers) and requests to put in my activation key, and then told that it is being used by another user!!!
    AM I EVER GOING TO BE ABLE TO USE MY 2 LICENSES FOR MY 2 QUICKEYS PROGRAMS???

  • Internal and external reference voltage for DAC

    Hi
    For example: If we are using +10V as the internal reference voltage, the range of the DAC would be -10 to +10V. But if the signal goes only from -5 to +5 V, the resolution of DAC is not getting maximized. To maximize the Resolution, an external refernce voltage of +5V can be given. Now the range of the DAQ will be -5V to +5V, same as that of the signal..
    What is internal and external reference voltage for DAC ?????
    Somil Gautam
    Think Weird

    Hi,
    you're better post this question on the "multifunctional DAQ" section, quoting the P/N of your device, as well as your programming language

  • My Hard Disk setting has been changed into no access for everyone and i can't open my mac. please tell me how can i login as an admin to change the setting cause i have a lot of date in my hard drive.

    My Hard Disk setting has been changed into no access for everyone and i can't open my mac. please tell me how can i login as an admin to change the setting cause i have a lot of date in my hard drive.

    Read and follow Apple Support Communities contributor Niel's User Tip: kmosx: I accidentally set a disk's permissions to No Access

  • Reference Library for Converting Between LabVIEW and XML Data (GXML)

    Please provide feedback, comments and questions on the Reference Library for Converting Between LabVIEW and XML Data (GXML) in this thread.
    The latest version of the NI GXML Library is availble in VIPM on the NI LabVIEW  Tools Network repository.

    Francesco, Thank you for the feedback.  With this component it was my intention to make a more "terse" version of the LabVIEW Flatten to XML VI that was also supported on RT and that gave the user more flexbility regarding the structure of the parsing type definition. I think you are right that the XML parser is not compliant to section 2.11 of the XML spec.  The parser does specifically looking for a #D#A and this appears to be an oversight on my part.  Please confirm for me, the specifcation is saying that the XML parser should be able to recognize three possibilities as an "end of line" character: #D#A, #D, or #A.  Am I reading this right?There are more efficient (and in some cases much more efficient) ways of sharing data between LabVIEW and LabVIEW: some examples are flattened binary strings and the datalog binary format.  XML is slower than these optons but the upside is that it is human readable.  Furthermore XML is inherently hierarchical which is convenient for complex data structures like clusters of arrays of clusters, etc.  If you don't care about human readability then you are correct XML doesn't make as much sense.I will return to the GXML source code and try to fix this in the near future but I would hope that instead of creating yet another custom VI from scratch that you could reuse what I have provided for you.  I included enough documentation in the source code so that users could make some modificiations themselves. The target application for this reference library was LabVIEW to LabVIEW communication.  As such I documented the schema on the dev zone document from a LabVIEW perspective.  It includes all the supported datatypes and all the supported data structures (cluters, arrays, multidimensional arrays, clusters of multidimensional arrays, etc.)  I do see some value in making a more conventional XML spec but the time investment required didn't really line up with my intended use case. Were there any other downsides to GXML that I have missed?  Best Regards, Jeff TippsSystems Engineer - Sound and VibrationMessage Edited by Jeff T. on 04-21-2010 10:09 AM

  • SAP Roles and Access for SAP Implementation team members

    Hi,
    Is it correct practice to give SAP_ALL role access for all SAP Implementation team members in Dev and QA?
    If not, what is the correct practice?
    Kindly let me know

    Madhu,
    It is NOT correct practice to give anyone SAP_ALL in any of the systems; not DEV, not QAS, and certainly not PRD. However, many implementation teams (and particularly consultants from SIs) insist that they cannot possibly do their jobs without it. This is completely incorrect as there are specific roles for them to use for that purpose. The only circumstance where it could be justified is if you require a special "firefighter" role - and even then, I would still be a bit doubtful.
    You should also consider that once you have given someone SAP_ALL, they will fight tooth and nail to keep it. It also means that they probably are not testing the user roles correctly. Most of those that insist they need it simply do not understand the security issues and probably don't care.
    Just think; if they have access to do soemthing that they shouldn't and then cause a big problem, are they the ones that will have to fix it or are they going to expect you to do it? If they expect you to clear up after them, then you have the right to insist on restricting their access to cause issues in the first place.
    But I know just how demanding they can be....
    Best of luck
    Tony

  • Hello,i have changed the access of library and system files in macintosh HD through get info option.i changed the access to write only access for library and system files to no access for everyone.then mac stopped working..nothing opening now.

    hello
    i have changed the access of library to WRITE ONLY and also i changed the access of system files to NO ACCESS FOR ANYONE in macintosh HD.then,suddenly it stopped working.i tried it shut down.then it didnot shut down.then i pressed ctrl+command+power button.then it was shut down.
    NOW, nothing is opening in macbook pro.it is opening and only apple logo is shown.what should i do now.i knew nothing in mac.please help me.operating system is 10.7

    hello CT,
    it showed
    permissions differ on library: should be drwxr-xr-r
    repaired "library"
    permissions differ on system: sholud be should be drwxr-xr-r;they are d-wx-----------
    repaired "systems"
    like this many steps occured.
    then next step is permissions repair complete.

  • How do I configure my application to provide access for mobile and web brow

    Hi everyone.
    I have one application and I need to provide access for mobiles and desktop browsers, and I don't know how do I configure my application to do this.
    Let me explain:
    In my jDeveloper I have One application and 3 projects:
    -Mobile (here is my mobile application)
    -Model (here is my model)
    -ViewController (here is my Web Browser application)
    In Mobile I have
    JavaEE Web Application name: mobile-Mobile-webapp
    JavaEE Web Context Root: mobile
    ViewController I have
    JavaEE Web Application name: mobile-ViewController-webapp
    JavaEE Web Context Root: myapplication
    When I run some page of ViewController I have this URL "http://localhost:7101/myapplication/index.jspx".
    When I run some page of ViewController I have this URL "http://localhost:7101/mobile/index.jspx".
    My problem is that, I want to have Just one landing URL like that "http://localhost:7101/myapplication/index.jspx" and when I get this URL by Desktop Browser my ViewController is showed, and when i get by Mobile the Mobile project is showed.
    Someone knows how do it?
    Thanks....

    Yes, I can, thanks for response.
    But, don't have some configuration in Oracle for this? I've been thinking do this with java or JavaScript, but I was looking something more beautiful for this.
    Java or JavaScript is the only way?

  • Delete and unlock access for infotypes

    Hi All,
    Is there way to have only access to delete and unlock infotypes in HR?
    We need to give access for unlocking and delete access to few users
    Please suggest.
    Regards
    Manish

    HI Gaj,
    I have check E and D:
    E comes with package of delete,create and change records
    and D has auth to unlock records.
    But my req is just to have delete locked records and Unlock lock records.
    That is combination of E and D.
    please advise
    Regards
    Manish

Maybe you are looking for

  • Nokia Lumia 800 won't update!!!!!!!!!!!!!!!!!!!!!!...

    Yes, I know there are already several topics on this but I'm pretty desperate now. I receive a Nokia Lumia 800 in December for christmas (I know it's not the latest but my family doens't have all that much money). Since christmas day I have been tryi

  • Itunes on Windows 7 computer

    I have downloaded an updated iTunes recently and now if you don't used it for about ten minutes it freezes up and the only way to stop it is through the task manager. Before the update it never used to do that.

  • Not happy with window appearance

    The subtle gray window appearance is depressing especially when there are several window's open it's hard to tell which is which. To bad unsanities haxies shape shifter is not fully working in Leopard. Are there any altervatives to shape shifter ?

  • Change to RSViewerPage.aspx doesn't reflect the change to the Sharepoint

    I am trying to update RSViewer.aspx file under -15/TEMPLATE/LAYOUTS/ReportServer. It seems like the changes I made isn't reflected on the sharepoint. Please let me know if you can give any suggestion to make this work. Note: I have made same changes

  • Flash default classPath / sourcePath

    I'm developing a utility application that gives all kinds of tools for flash designers. Some of the features requires me to install AS2 and AS3 classes and some include files. So the install processes needs to place actionscript files where flash IDE