What happens to objects when you redeclare a new object?

... and is there a more proper way of "deleting" them from memory, or is it a case of waiting until the garbage collector in java sweeps them up?
i.e.
private CustomObjectType myObject;
public final void myMethod() {
myObject = new CustomObjectType("I am the first object");
// do some temporary work with myObject
/// now I need to do more work with another temporary object, so just replace the "link"
myObject = new CustomObjectType("I am a second object");
Is it better to declare new variables to hold this second object?
Should a person declare the object to be null when no longer required?
Do I ever need to worry about this, does the garbage collector sort out references for me?
(Please go easy, still learning and don't really need to know this right now but I'm curious! :)

What happens to objects when you redeclare a new object?If you go:
Dog myDog = new Dog();
and then go:
Dog myDog = new Dog();
you are replacing the first reference to Dog() with another one. I don't think it would make sense to do this because it is redundant.
But if you go:
static Dog myDog = new Dog();
and then go:
static Dog myDog = new Dog();
then then second one will be ignored because the first one already assigned Dog() to myDog.. so the second one won't replace the first one - it will just be ignored or generate an error.
is there a more proper way of "deleting" them from memory, or is it a case of waiting until the garbage collector in java sweeps them up?In c and c++ you have to think about when the life of an object ends and destroy the object to prevent a memory leak. But in Java the garbage collector takes this task on if a certain amount of memory is used. If you don't use a lot of memory the gc won't bother and the objects will be destroyed when you exit the program.
You can use:
finalize(){
// insert code to be executed before the gc cleans up
and if you call System.gc() (which you probably won't need to do) then the code in the finalize() method will run first e.g. to erase a picture from the screen before collecting the object.
private CustomObjectType myObject;public final void myMethod() {
myObject = new CustomObjectType("I am the first object");
// do some temporary work with myObject
/// now I need to do more work with another temporary object, so just replace the "link"
myObject = new CustomObjectType("I am a second object");
you could do:
public class CustomObjectType{
    //this constructs an instance of the class using a string of your choice
    CustomObjectType(String str) {
        System.out.println(str);
    static void main(String[] args){
        CustomObjectType myObject = new CustomObjectType("I am the first object");//  This sends the constructor the string you want it to print
        CustomObjectType myObject2 = new CustomObjectType("I am the second object");//  This sends the constructor the string you want it to print
}Bruce eckel wrote Thinking in Java 4th edition considered to be the best book on Java because of how much depth he goes into, although some recommend you should have atleast basic programming knowledge and a committment to learn to get through the book.
I just started it and it helps a lot. Maybe u could borrow it from the library.. good luck!

Similar Messages

  • What Happens to music when you re-install ipod on pc?

    I have a 20G ipod with 2,000 songs on, none of which are on my pc. My ipod no longer appears in itunes, so i am going to re-install it with the disk i got when i first bought the ipod. However, i dont know what will happen to my music, will it be deleted? Anyone re-installed an ipod with the disk, and had music on the ipod? If so, does it remain or get deleted?
    Thanks

    If you RESTORE your iPod you will delete all the music on it. I'd try everything else first. If you can get your computer to talk to your iPod the first thing I'd do is back up my music!

  • What happen to menus when you burn to folder?

    I create full menus in PE7 prior to burning to folder. When I use Nero to burn the file to disc, it doesn't incorporate the menu. Any suggestions?
    I only use Nero as neither my internal nor external DVD writer is recoginsed from within PE7 if I try to burn to disc.

    Paul has given you some good info on getting the Project Burned to a Folder and then to disc. However, the problem with not being able to locate your burner(s) from within PE is most likely an issue with Nero and it's InCD packet-writing program. This module of Nero will "seize" control of your burner(s) and will not let any Adobe products have full control, which Adobe products need to do any Burn to disc. The same thing happens with Roxio's DLA module and even with Windows' packet-writing software, especially if you have Quicken and have ever used its Backup to CD function.
    Packet-writing software allows one to see a writable DVD (or CD), as a virtual drive and perform drag-and-drop functions on it. These are often installed by default and really mess up anything Adobe. I highly recommend removing Nero (or Roxio, et al) and then doing a Custiom Install of just the modules that are necessary, omitting DLA, InCD, etc. One often has to do an uninstall and then a Registry cleaning to fully remove all traces of these packet-writing programs. Once clean, do a Custom Install, and choose exactly what you need, leaving out packet-writing modules and any indexing modules.
    Good luck,
    Hunt

  • What happens to RandomAccessFile when seek operation fails?

    Hi,
    I wonder what happens to RAF when the seek() op fails - does the file remain open?
    I guess i should close it if fails, what is the best thing to do - protect or catch exception?
    Am i wrong about it?
    Thanks.

    I wonder what happens to RAF when the seek() op fails - does the file remain open?In the absence of evidence or documentation to the contrary that is what you should assume.
    I guess i should close it if failsWhy? All it means is that that offset doesn't exist within the file.

  • What are your options when you run out of hard drive space?

    What are your options when you run out of hard drive space? 

    I 110% agree, it is a disaster but it saves your mac until you recieve an external HD.
    Csound1 wrote:
    XcodeDeveloper wrote:
    I know but he just wanted options so I gave him one that helped me. If he filled up his HD a Gigabyte is sometimes a small miracle, exaggeration on small .
    OSX with 1G of free space is a disaster waiting to happen.
    Read this:

  • When you open a new browser tab, underneath the box to type in what you are looking for is the recently visited list. I want to disable or delete this list...how do I get rid of this list???

    When you open a new browser tab, underneath the box to type in what you are looking for is the recently visited list. I want to disable or delete this list...how do I get rid of this list???

    The drop-down list displays items from your History and/or Bookmarks.
    You can control what shows (or nothing at all): Options > Privacy, "Location Bar" section. Options are:
    *History and Bookmarks
    *History
    *Bookmarks
    *Nothing
    See --> https://support.mozilla.com/en-US/kb/Options%20window%20-%20Privacy%20panel
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You may need to update some plug-ins. Check your plug-ins and update as necessary:
    *Plug-in check --> http://www.mozilla.org/en-US/plugincheck/
    *Adobe Shockwave for Director Netscape plug-in: [https://support.mozilla.com/en-US/kb/Using%20the%20Shockwave%20plugin%20with%20Firefox#w_installing-shockwave Installing ('''''or Updating''''') the Shockwave plugin with Firefox]
    *Adobe PDF Plug-In For Firefox and Netscape: [https://support.mozilla.com/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]
    *Shockwave Flash (Adobe Flash or Flash): [https://support.mozilla.com/en-US/kb/Managing%20the%20Flash%20plugin#w_updating-flash Updating Flash in Firefox]
    *Next Generation Java Plug-in for Mozilla browsers: [https://support.mozilla.com/en-US/kb/Using%20the%20Java%20plugin%20with%20Firefox#w_installing-or-updating-java Installing or Updating Java in Firefox]

  • What is it called when you do this?

    What is it called when you have something similar to a blog where you have your code say, let there be 5 posts, and after 5 posts create a new page to put the other posts on that page so there is only 5 per page?
    I'm not really sure how to search that so I can learn how it's done.
    I'm using Repeating Template Regions so if anyone can either tell me what it's called or link me to a good tutorial that would help me that would be great!
    Basically what I'm hoping is that I can press the little "+" on my Repeating Template Region and once there is more than a specific number of the regions, the excess will continue onto another page that I can link to.
    (Side Question... Anyway to organize these regions in Alphabetical order?)
    - Thanks!

    It's called pagination
    There are server behaviors in Dreamweaver to do this.
    MySQL queries use the ORDER BY argument to ORDER BY alphabetically or numberically either in ascending or descending order.
    example:
    SELECT table_column, table_column2
    FROM table_name
    WHERE table_column = 'something'
    ORDER BY table_column ASC
    best,
    Shocker

  • What does it mean when you get a "The iTunes library file cannot be saved. There is not enought memory available." ? And what can I do to correct it?

    What does it mean when you get a "The iTunes library file cannot be saved. There is not enought memory available." ? And what can I do to correct it?

    Well, I installed the latest iTunes this AM, works perfectly.  Although for some reason it did lock up after playing a song today.
    Horror stories?  That's a bit overly dramatic.
    No, it isn't.
    The issue you are experiencing is one that has occurred in multiple versions of iTunes, a simple search would have revealed this.
    A simple search was conducted, no one seemed to have an answer.  Do you always adopt such a haughty attitude?  Or was I just lucky.

  • HT201299 what does it mean when you get this message on the Iphone? "online maps consume data traffic"

    what does it mean when you get this message on the Iphone? "online maps consume data traffic"

    That means that if you use online maps, it will consume data. If you're on WiFi, no worries. If you are on cellular data, then it will eat into your cellular data plan.

  • What does it mean when you call someone and it goes straight to the 3 beeps to mean cancelled

    hi
    what does it mean when you call someone and it goes straight to the 3 beeps to mean cancelled? this phone doesnt even ring, it just goes straight to the BEEP-BEEP-BEEP, its an iphone 4 and on IOS7 and it was ringing eailier on in the day when i spoke to this person. it wouldn't mean i have been blocked would it?
    what does all this mean?
    thanks
    mrredrunner100

    i got my friend to message this person to see if they had the same problem, and the message went through and i think he got a reply, and all of a sudden this has started to work again (calls only) but apparently none of my messages went through that i have sent since the block activated. and they still havent even though there working again, and "apparently" a message was sent to me at 9pm today and it has never arrived. so imessage and text still isnt working, before i go asking this person about this, is this a genuine block or is there a phone problem?

  • What does it mean when you receive a text on your iphone 6 form your own number and the message is duplicated on each side (sent/recieved) and has "verizon message" with a long number at the end of the text, duplicated as well?

    what does it mean when you receive a text on your iphone 6 from your own number and the message is duplicated on each side (sent/received) and has "verizon message" with a long number at the end of the text, duplicated as well?

        Great question stacybrownie! Let's get to the bottom of this so that it's not a cause for concern. When a message is sent to/from your own number, it will display as one sent, one received. This makes it display two messages as you are seeing. Let's clarify the second part of your question. Where do you see "Verizon Message" exactly? What is the long number at the end of the text? When did this start and is it with all text messages or only this instance?
    AdaS_VZW
    Follow us on Twitter at @VZWSupport 

  • What does it means when you turn on the macbook and a file with a "?" mark flashes?

    What does it means when you turn on the macbook and a file with a "?" mark flashes?

    It usually means some system files are missing or corrupted. Reinstalling OS X is the fix:
    Reinstall OS X without erasing the drive
    Do the following:
    1. Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    2. Reinstall Snow Leopard
    If the drive is OK then quit DU and return to the installer.  Proceed with reinstalling OS X.  Note that the Snow Leopard installer will not erase your drive or disturb your files.  After installing a fresh copy of OS X the installer will move your Home folder, third-party applications, support items, and network preferences into the newly installed system.
    Download and install the Combo Updater for the version you prefer from support.apple.com/downloads/.

  • TS2310 what does it mean when you're about to install itunes and it says This update requires OS X version 10.6.8 or later.??? i don't understand... Can someone please explain to me what that means...??? And how to fix it.

    what does it mean when you're about to install itunes and it says This update requires OS X version 10.6.8 or later.??? i don't understand... Can someone please explain to me what that means...??? And how to fix it.

    1. It means exactly what it says. Apple dropped support for earlier Mac OS X versions in iTunes 10.7.
    2. Update the computer to 10.6.8. If it's running a Mac OS X version prior to 10.6, this requires buying a Mac OS X 10.6 DVD from the online Apple Store, which requires an Intel Mac with at least 1GB of RAM.
    (93025)

  • What does it mean when you computer crashes and when you turn it back on it shows you a blank blue screen with a little folder and a question mark in the middle?

    What does it mean when you computer crashes and when you turn it back on it shows you a blank blue screen with a little folder and a question mark in the middle? It's a old imac from 1997.

    I don't have original discs that it came with.
    Then you still can use the second option with the keyboard combo I posted, called "resetting the PRAM."
    Also when you way hold the c key down do you mean turn computer off and turn back on holding the c key?
    Yes, or you can simply restart. As you don't have the CDs, this isn't on the plate any more.
    The internal backup battery is not expensive and, in most iMacs is user-replacable. If yours has a tray-loading optical drive like this one:
    it takes a major teardown to replace the internal battery. If this is the case, you'd be better off to leave the computer plugged in all the time; that eliminates the main reason for having a working battery.
    If it has a slot-loading optical drive like this one:
    things are much easier. The battery is visible through the RAM access door on the bottom of the computer case. The manual:
    http://manuals.info.apple.com/en_US/iMacG3_2000UserManual.PDF
    has sketches of how to access the RAM and therefore the backup battery. Unfortunately, the pdf on the manual goes up sideways on-screen and the RAM instructions are pretty deep into the manual. It's probably easier to scroll (for a while) to the section on adding RAM and print the applicable pages.
    When you work on the battery, some sort of non-conductive pliers or large tweezer or forceps help unless you have tiny fingers. Make sure to note the polarity of the old battery and install the new one in the same orientation.
    The battery itself is readily available. If price is no oblect, you can get it for a small rasom from Radio Shack Store ("Tandy" outside the US) as part number 23-026.
    Online, they are dirt-cheap even after adding shipping. I buy backup batteries form this outfit:
    3.6v Newer Technology Lithium 1/2 AA PRAM Computer Clock Battery

  • HT1918 This article is great, IF IT WORKS!  What is the fix when you enter new billing details and all iTunes tells you is, "contact iTunes support"?

    This article is great, IF IT WORKS!  What is the fix when you enter new billing details and all iTunes tells you is, "contact iTunes support"?

    pbsimon82 wrote:
    This article is great, IF IT WORKS!  What is the fix when you enter new billing details and all iTunes tells you is, "contact iTunes support"?
    You contact itunes support, just as it told you to do
    http://www.apple.com/support/itunes/contact/

Maybe you are looking for

  • DRQ : Customer / Vendor ref. no. duplication check

    Hi Expert, At present Customer / Vendor ref. no. duplication check is perform on all documents (e.g. A/R Invoice / A/P Invoice) Where as I believe it should be performed Customer / Vendor wise. The reason is simple, say in a new year all customer / v

  • Not enough memory error when passing an array to a chart

    Hello. I am trying to pass some data from a reading loop to a display loop using queues and charts. In order to save on redraws I am reading the queue just once a while, flush it and pass the resulting array to the Chart. It is actually an array with

  • Trouble with mic on dragon dictate?

    i am having problems with my macbook running 10.9.1 using dragon  dictate headset, mic keeps saying not connected.

  • [SOLVED] Cannot compile taskview-git

    I cannot compile taskview-git. Here's my output: ==> Edit PKGBUILD ? [Y/n] ("A" to abort) ==> ------------------------------------ ==> n ==> taskview-git dependencies: - glib2 (already installed) - git (already installed) ==> Continue building taskvi

  • Firefox will not load either Google, or my AOL mail

    When I type in http://www.google.com, the site will not load. Also, when I am signed in on http://www.aol.com , if I click the mail icon, my mail page will not load.