When 'new' is necessary and when is not ?

The following codes were extracted from a book :
ArrayList<Account>  things = new ArrayList<Account>();
things.add(new Account());
Account myAccount = things.get(0);Question:
The 3rd line didn't have 'new' keyword, does it mean that myAccount is storing a reference to the 1st item of 'things' instance ? So to say, myAccount itself doesn't an instance of its own for Account class. Am I right ?

JoachimSauer wrote:
System.identityHashCode() comes closest to the memory address of an object. It returns a almost-unique number that is derived from the object identity alone. It doesn't change when an objects values chane, it stays constant for the objects life time, and the result for two different objects is (almost always!) different.Depends on your definition of "almost always." :-)
I usually get duplicated hashcodes after just a couple thousand objects with this code.
import java.util.*;
public class HC {
    public static void main(String[] args) {
        Map<Integer, List<Object>> map = new HashMap<Integer, List<Object>>();
        for (long ix = 0; true; ix++) {
            Object obj = new Object();
            int hc = obj.hashCode();
            if (map.containsKey(hc)) {
                List<Object> list = map.get(hc);
                list.add(obj);
                System.out.println("Iteration " + ix + ", hc=" + hc + ", count="
                        + list.size());
            else {
                List<Object> list = new ArrayList<Object>();
                list.add(obj);
                map.put(hc, list);
}

Similar Messages

  • I have a new iPod touch and when I connect it to my pc and itunes, a window says "this ipod cannot be used because the Apple Mobile Device Service is not started."

    I have a new iPod touch and when I connect it to my pc and itunes, a window says "this ipod cannot be used because the Apple Mobile Device Service is not started."

    This might help restart it http://support.apple.com/kb/TS1567

  • I just got a new ipod 5 and when I plugged in the charging cord that came with it, it says it is not supported, and may not charge. It worked the first few times, but now it won't charge at all.

    I just got a new ipod 5 and when I plugged in the charging cord that came with it, it says it is not supported, and may not charge. It worked the first few times, but now it won't charge at all.

    - See:      
    iPod touch: Hardware troubleshooting
    iPhone and iPod touch: Charging the battery
    - Try another cable. Some 5G iPods were shipped with Lightning cable that were either initially defective or failed after short use.
    - Try another charging source
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Make an appointment at the Genius Bar of an Apple store. The cable as well as the iPod, is covered by the warranty.
    Apple Retail Store - Genius Bar                          

  • I purchased a new MacBook Pro and when transferring files iphoto did not transfer.  I have a question mark in the place of the icon.  My pictures are in library but can't properly access iphoto.  Thank you

    I purchased a new MacBook Pro and when transferring files iphoto did not transfer.  I have a question mark in the place of the icon.  My pictures are in library but can't properly access iphoto.  Thank you

    Sure-glad to help you. You will not lose any data by changing synching to MacBook Pro from imac. You have set up Time Machine, right? that's how you'd do your backup, so I was told, and how I do my backup on my mac.  You should be able to set a password for it. Save it.  Your stuff should be saved there. So if you want to make your MacBook Pro your primary computer,  I suppose,  back up your stuff with Time machine, turn off Time machine on the iMac, turn it on on the new MacBook Pro, select the hard drive in your Time Capsule, enter your password, and do a backup from there. It might work, and it might take a while, but it should go. As for clogging the hard drive, I can't say. Depends how much stuff you have, and the hard drive's capacity.  As for moving syncing from your iMac to your macbook pro, should be the same. Your phone uses iTunes to sync and so that data should be in the cloud. You can move your iTunes Library to your new Macbook pro
    you should be able to sync your phone on your new MacBook Pro. Don't know if you can move the older backups yet-maybe try someone else, anyways,
    This handy article from Apple explains how
    How to move your iTunes library to a new computer - Apple Support''
    don't forget to de-authorize your iMac if you don't want to play purchased stuff there
    and re-authorize your new macBook Pro
    time machine is an application, and should be found in the Applications folder. it is built in to OS X, so there is nothing else to buy. double click on it, get it going, choose the Hard drive in your Time capsule/Airport as your backup Time Machine  and go for it.  You should see a circle with an arrow on the top right hand of your screen (the Desktop), next to the bluetooth icon, and just after the wifi and eject key (looks sorta like a clock face). This will do automatic backups  of your stuff.

  • I created a new Itunes playlist and when I synch my phone it is not visable as a playlist on my phone (Iphone 6), but it does appear on my computeras a playlist on my phone.  How can I get it to be visable on my phone?

    I created a new Itunes playlist and when I synch my phone it is not visable as a playlist on my phone (Iphone 6), but it does appear on my computer as a playlist on my phone.  How can I get it to be visable on my phone?

    Hi,
    It sounds like there may be some disconnect between the phone and the computer.  Could be a number of things going on, but one way I've been able to fix this issue on several occasions is by completely removing all of the music from the iPhone (Settings > General > Usage > Storage > Manage Storage > Music > swipe 'All Songs' to the left and tap 'Delete') and then re-syncing it from iTunes all at once.  Be sure to disconnect your phone from the computer and close iTunes first.  Keep in mind that any songs that are on the phone but are NOT in the iTunes library will not be synced over after you delete them from the phone.  If the songs on the phone were purchased from the iTunes Store you can transfer them to the computer's iTunes library by connecting the phone to iTunes then selecting File > Devices > Transfer Purchases from [user's] iPhone.
    After deleting all songs from the phone, go back into Settings and check the music storage again to make sure everything was deleted.  If the 'Music' app is not listed anymore, then you should be good to go.  Just to be sure, you can also check the Music app itself and make sure no songs appear there (if songs appear with cloud icons next to them, turn off 'Show All Songs' in Settings > Music and then check the Music app again -- no songs should appear).
    Once you're absolutely sure all songs have been removed from the phone, restart the iPhone, plug it back into the computer, and let iTunes sync.  Give it time to sync everything over at once and make sure the sync doesn't get interrupted.  Everything you've set to sync should sync over properly.
    If it still doesn't sync, there may be a corrupted file in the iOS installation on the phone or in the iTunes installation on the computer.  It's more likely that the issue is in the phone's software, especially if you ever installed an iOS update over Wi-Fi (through the Settings app).  I'd recommend making an iTunes backup and restoring the phone to factory settings through iTunes.  Then set the iPhone up as a new iPhone and test the syncing -- the playlist should sync over properly.  If not, Remove and reinstall iTunes and related software components for Windows Vista, Windows 7, or Windows 8 - Apple Support.  Then test again.
    Once you get the syncing working with the phone set up as new, restore the phone from your iTunes backup and test the syncing again.  Now that the iOS files have been reinstalled, hopefully the corruption is gone!  If it still doesn't sync properly, the corruption may be somewhere else (in a song in the playlist, in some app data in the backup, etc.).  That could be harder to pinpoint, but don't worry about that for now.  Start simple.
    Good luck!

  • I bought a new itouch 5, and when I plugged it in to get the updates it could not update and I got an error code

    I bought a new itouch 5, and when I plugged it in to get the updates it could not update and I got an error code

    And that error code is?

  • I bought a new McBook Pro and when I backed up from my old computer, the iCal on my new computer is not syncing. It says "The server did not recognize your user name or password for (name of my mobile me acct). Make sure you enter them correctly."

    I bought a new McBook Pro and when I backed up from my old computer, the iCal on my new computer is not syncing. It says "The server did not recognize your user name or password for (name of my mobile me acct). Make sure you enter them correctly." Any suggestions?

    Carla,
    Check this post for a possible solution.

  • I have bought  a new ipad mini and when i try to use app store asks me  my email but it does not let me review, it get blocks and does not let me tap review

    I have bought  a new ipad mini and when i try to use app store asks me  my email but it does not let me review, it get blocks and does not let me tap review

    You have to provide email to access app store,dont expect walk in and walk out

  • I just get the new iPad air and when connecting it to my laptop, why the battery is not charging?

    just get the new iPad air and when connecting it to my laptop, why the battery is not charging?

    A lot of computers don't provide enough power to their USB ports to charge the iPad at a sufficient rate - it may still be charging slowly, and should be a bit quicker if the iPad's screen is off (if you leave it for a while and then disconnect it from your computer you may find that it's battery percentage has gone up). The wall charger is usually the most efficient way to charge the iPad.

  • System cache cleaning - when is it safe, and when is not?

    System cache cleaning is one of those so-called "maintenance" tasks that you may read about on the forums on Mac OS X guides that has mixed reviews, and typically is not necessary. In fact, when it is done at the wrong time, data corruption can lead to a situation where an erase and reinstall is necessary. I can't reproduce it easily, but I will say I've had it happen to at least three of my clients, so it is not as random as one would hope.
    You've probably heard of browser cache, and that's safe to clean anytime you like. One thing you'll notice about when you do, is that some websites will load slower, and others will load faster depending on your internet connection, and the frequency those websites get updated.
    System cache on the other hand which you'll find in ByHost and Cache folders in your Hard drive -> Library, System -> Library, Users -> yourname -> Library are a much more sensitive type of file. These will optimize the speed of frequently done operations on the operating system itself as well as specific applications which require those folders. When one of these files get corrupted, programs won't launch, will unexpectedly quit, will launch and close on their own, and in some cases Disk Utility won't function normally, or System Preference panels won't launch. To avoid these problems:
    1. Only do system cache cleaning after your data is completely backed up to your satisfaction, so that a system restore won't waste your time.
    2. Do it when no other applications are running, and there are no memory resident programs that may be affected by such cleaning in Apple menu -> System Preferences -> Accounts -> Login or Startup Items. Check the Process or Activity Viewer applications for applications you might have installed.
    3. Do not allow the process to be interrupted until it is finished. If any power outage happens, you may be left with a corrupted cache file.
    If you have a corrupted cache problem, attempt to isolate if it is happening just to one account by creating another account with Apple Menu -> System Preferences -> Accounts with admin access and see if it impacts that account as well. Do the following depending on whether or not it does affect that account:
    1. If isolated to one user, go back to the user and delete that user's Library folder's cache files relating to system and Launchservices, and log out and log back in the user twice. If it disappears as a problem once, and reappears, something you are running is persistentantly corrupting that user's cache folder, and you may have to move all the non-corrupt files to the new user.
    2. If it is not isolated to the user go to the System and Library folders under the hard drive and see if the Launchservices files and System cache files are removed if the issue disappears on reboot, and if it does, does it reappear after a second reboot. If it reappears after a second reboot, then you have the scary prospect of an erase and install of your system.
    Don't use automatic utilities to manage your system or user cache files. If anything only manually clean the cache when it is necessary and you have corrupted files. The cache is there to speed your system, and should otherwise not be touched.

    System cache cleaning is one of those so-called "maintenance" tasks that you may read about on the forums on Mac OS X guides that has mixed reviews, and typically is not necessary. In fact, when it is done at the wrong time, data corruption can lead to a situation where an erase and reinstall is necessary. I can't reproduce it easily, but I will say I've had it happen to at least three of my clients, so it is not as random as one would hope.
    You've probably heard of browser cache, and that's safe to clean anytime you like. One thing you'll notice about when you do, is that some websites will load slower, and others will load faster depending on your internet connection, and the frequency those websites get updated.
    System cache on the other hand which you'll find in ByHost and Cache folders in your Hard drive -> Library, System -> Library, Users -> yourname -> Library are a much more sensitive type of file. These will optimize the speed of frequently done operations on the operating system itself as well as specific applications which require those folders. When one of these files get corrupted, programs won't launch, will unexpectedly quit, will launch and close on their own, and in some cases Disk Utility won't function normally, or System Preference panels won't launch. To avoid these problems:
    1. Only do system cache cleaning after your data is completely backed up to your satisfaction, so that a system restore won't waste your time.
    2. Do it when no other applications are running, and there are no memory resident programs that may be affected by such cleaning in Apple menu -> System Preferences -> Accounts -> Login or Startup Items. Check the Process or Activity Viewer applications for applications you might have installed.
    3. Do not allow the process to be interrupted until it is finished. If any power outage happens, you may be left with a corrupted cache file.
    If you have a corrupted cache problem, attempt to isolate if it is happening just to one account by creating another account with Apple Menu -> System Preferences -> Accounts with admin access and see if it impacts that account as well. Do the following depending on whether or not it does affect that account:
    1. If isolated to one user, go back to the user and delete that user's Library folder's cache files relating to system and Launchservices, and log out and log back in the user twice. If it disappears as a problem once, and reappears, something you are running is persistentantly corrupting that user's cache folder, and you may have to move all the non-corrupt files to the new user.
    2. If it is not isolated to the user go to the System and Library folders under the hard drive and see if the Launchservices files and System cache files are removed if the issue disappears on reboot, and if it does, does it reappear after a second reboot. If it reappears after a second reboot, then you have the scary prospect of an erase and install of your system.
    Don't use automatic utilities to manage your system or user cache files. If anything only manually clean the cache when it is necessary and you have corrupted files. The cache is there to speed your system, and should otherwise not be touched.

  • HT1449 i have bought a new iPod touch and when i went to sync my iTunes library most of the songs didn't come across they get a explanation mark at the side they are whole cds of music. but i didn't have this problem on my old ipod touch when i was using

    I have bought a new ipod touch and when i went to sync my music library on to it only a few songs went over, the ones that didnt had a ! next to them. I had no problem when using my last ipod touch but i was using a pc at the time not a mac though.

    Hi there,
    This usually meas that iTunes can't find the original files. I would recommend taking a look at the article below for some tips on locating that lost media.
    iTunes: Finding lost media and downloads
    http://support.apple.com/kb/ts1408
    -Griff W.

  • I backed up my old core 2 duo imac and and was trying to transfer files to my new 2011 imac and when i go to oppen a folder from what i transferred it says "The folder "Music" can't be opened because you don't have permission to see its contents."?

    I backed up my old core 2 duo imac and and was trying to transfer files to my new 2011 imac and when i go to oppen a folder from what i transferred it says "The folder “Music” can’t be opened because you don’t have permission to see its contents".  Why cant i access the files from my old mac?  I tried the time machine and that isnt working either.  I have files that I need to use on my new mac, all my old programs and such.  I thought they said it was easy to get your files from one mac to another.  Please help.

    Your account names are probably different on the two Macs. If you know the UNIX command line, open a terminal window and run:
    $ id 
    You should see a line that starts with something like this:
    uid=501(your_user_id_here)
    now check the owner of the folder you copied over:
    $ ls -ld Music
    drwx------+ 8 some_user_id_here  staff  272 May 14 16:08 Music
    Do the IDs match? If not, you could change the ownership. Say your id is "johnsmith"
    $ chown -R johnsmith Music
    Now try and access it with iTunes.

  • My daughter has a new ipod touch and when synced it had all of my iphone contacts. she deleted the ones she didn't want and they were removed from my phone as well. How can I get them back if they were deleted from the cloud? I also had them on my pc

    My daughter bought a new ipod touch and when synced received the contacts from my iphone. She deleted the ones she didn't want on her ipod and now they are gone from my iphone. I have the cloud and i thought back up on itunes. I have tried to re-sync and no luck. How can I get my contacts back?

    Your problem is that she used your icloud ID to connect to icloud and thus had all your data synced to her device.  Contacts are not saved in a backup to icloud, since they are stored independently in the Contacts section of icloud.  If someone deletes them, they are gone.  If you had them on the PC would they be available in some backup you frequently make of the PC?

  • I just bought a new ipod touch and when i plug it into my Mac usb port nothing is happening I can get the computer to sync other ipod in the same port

    I just bought a new ipod touch and when i plug it into my Mac usb port nothing is happening I can get the computer to sync other ipod in the same port

    Try:
    iPhone, iPad, iPod touch: Device not recognized in iTunes for Mac OS X
    Do not omit the Additional Information paragraph.
    Is the iPod that connects an iPod touch? If not that does not mean anything since iOS devices like iPod touch, iPhone and iPad use different drivers than other iPods.

  • I got a new ipod touch and when I went to text it used my Dad's number.  I want to use our family's itunes account (for music etc) but have my own id/number for texting.   What do I do?

    I got a new ipod touch and when I went to text it used my Dad's number.  I want to use our family's itunes account (for music etc) but have my own id/number for texting.   What do I do?

    See:
    MacMost Now 653: Setting Up Multiple iOS Devices For Messages and FaceTime
    You will not have a phone number, only an email address.
    iOS and OS X: Link your phone number and Apple ID for use with FaceTime and iMessage

Maybe you are looking for

  • View Column info not displaying in Columns Tab

    Running XP SP2 and SQL Developer 1.5.1 5440 When looking at views that are using tables from another schema. I don't see any of the columns information. I have DBA role In rel 1.1.2.25 2579 I see them just fine. (Both loaded on machine right now) Is

  • Hi sap expert

    can u brifely give a example of infotypes and macros in abap hr

  • The invoice & excise Invoce s are genrated but  does not diplay in Sales Re

    Dear Team, The invoice & excise Invoce s are genrated but  does not diplay in Sales Report.(ZMSR ) . then i have go throught the VF02 & enter the invoice no & click the Relese to Accounting the flag but problem is not solve. pl give the correct solut

  • ISCR question

    I have a mastered CD with ISCR codes written in Waveburner. If I import tracks from that CD to WB, ISRC codes don´t show up. My question is: If I import this CD to iTunes or Toast and burn copies. Are ISCR codes included in copies? Thanks! JanD

  • Garish Colors in Aperture 2?

    Why are colors so garish in Aperture 2? This is not a monitor calibration issue (Apple 30-inch HD Cinema Display) because when the same file is opened in PhotoShop or Lightroom, the colors, (especially flesh tones) are much more natural. I want to re