How to make sure 2 Variables of same class do not share internal variables?

K, I am having trouble making a new instance of an object.
I have a class call File_Class that have a public static attribute call File_Name.
Now in another class, I have a linkedlist and each one of the element is supposely a File_Class object. The problem that I am having now is that whenever I create a new File_Class (File_Class New_Class = new File_Class (File_Name)), i am actually getting a reference to the old one so that anything that I change reflects on every element of my link list.
My question now is
1. how exactly do i enforce that a new instance of the object (File_Class) is created so i can make sure every element in my linked list is distinct.
2. why is this happening at all
thanks for your help in advance.
Hung-Hsun Su

Here is a simple example that i wrote just to demonstrate the point. it seems that i always get the same object no matter what. Thanks again.
Result:
AFTER 0 1 2
1 2
AFTER 1 10 20
10 20
10 20
AFTER 2 99 999
99 999
99 999
99 999
Code:
class T
          public static int A;
          public static int B;
class Test
          static T TA[] = new T[5];
          private static void Set_Value (int i, int A, int B)
                    T t1 = new T ();
                    t1.A = A;
                    t1.B = B;
                    TA[i] = t1;
          private static void Print (int i)
                    for (int k = 0; k <= i; k++)
                              System.out.println (TA[k].A + " " + TA[k].B);
          public static void main (String args[])
                    System.out.println ("AFTER 0 1 2");
                    Set_Value (0, 1, 2);
                    Print (0);
                    System.out.println ("AFTER 1 10 20");
                    Set_Value (1, 10, 20);
                    Print (1);
                    System.out.println ("AFTER 2 99 999");
                    Set_Value (2, 99, 999);
                    Print (2);
     }

Similar Messages

  • How to make a Java program that recognises a function of two variables...

    How to make a Java program that recognises a function of two variables to assign values to that?
    First I will give an example and then do the question.
    Ex1.
    We have any function, eg.y = x ^ 2 + 1 (read 'y' equals 'x' high to the square), a function of the second degree.
    To build the graph of this function attach values to 'x' to find the values of 'y'
    And thus mount the pair ordered (x, y) which represents a point on the Cartesian plane.
    Assigning values to 'x' 'we can build up a table that gives us the pairs ordered:
    We can use any numbers, but arfer interval [-3.3]
    X | y = x ^ 2 + 1
    -3 | Y = (-3) ^ 2 +1 = 10
    -2 | Y = (-2) ^ 2 +1 = 5
    -1 | Y = (-1) ^ 2 +1 = 2
    0 | y = (0) ^ 2 +1 = 1
    1 | y = (1) ^ 2 +1 = 2
    2 | y = (2) ^ 2 +1 = 5
    3 | y = (3) ^ 2 +1 = 10
    We then ordered the pairs:
    (-3.10), (-2.5); (-1.2), (0,1), (1,2), (2,5), (3,10)
    Tabem that can be represented by a table:
    X | y
    -3 | Y = 10
    -2 | Y = 5
    -1 | Y = 2
    0 | y = 1
    1 | y = 2
    2 | y = 5
    3 | y = 10
    Now I begin to explain my doubts.
    See this program:
    Ex2
    * To change this template, choose Tools | Templates
    * And open the template in the editor.
    Encontrando_o_valor_de_y package;
    * @ Author des Soldat Gottes
    Import javax.swing.JOptionPane;
    Public class (Main
    * @ Param args the command line arguments
    Public static void main (String [] args) (
    Int x, y;
    String x1;
    X1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',"); / / receives a value for the function y = x + 1
    X = Integer.parseInt (x1); / / tranforma String in int
    Y = x + 1; / / receives the value of 'x' and calculates' y '
    JOptionPane.showMessageDialog (null, "The value of 'y' is: \ t \ t" + y);
    / / Displays the value of 'y'
    System.exit (0);
    We see that the program receives above a value for 'x' and replaces the function contained in the program, y = x + 1, and so is the value of the variable 'y'.
    In: x1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',");
    The entry is a number and that number is assigned aa ja existing function in the (y = x + 1).
    The question is: would it be possible to come to a function?
    Ex: the program ask: DIGITE THE FUNCTION?
    The USUARIO DIGITARIA A FUNCTION ANY, TYPE: y = x ^ 2 +1
    The program would recognize the function and give numerical values to that function as Ex1, at the beginning of this text.
    And then to find the values of the x and y launch a table.
    It would be possible that?
    By invez of entering with a number so that the program sustitua a function ja existing as Ex2, seen above, entering with a function quaquer (type: y = x ^ 2 +1) for the program atribuisse values to that function and then create a table of values as Ex1.
    I hope it has been easier to understand my doubts now.
    Thank you for your attention!
    God bless!

    rafaelmenezes wrote:
    Thanks for the explanation, could understand what fly said.
    But as it applied to a program?
    How to create a program that recognizes that the entry coefficients?Are you asking about how to parse out the coefficients from the string "3x^4 + 4x^3 - 8x^2 + 5x^1 + 2x^0"? If you define the format to strictly follow that example, this should get you started:
    Strip out the spaces
    Split the String on "x^"
    That should give you [3, 4+4, 3-8, 2+5, 1+2, 0]
    Split each resulting String on "+ | -", preserving the operator as a token so you can apply the correct sign to the coeff.
    That should leave you with [3, 4, +, 4, 3, -, 8, 2, +, 5, 1, +, 2, 0]. Every other number is a coeff, the rest are the degrees.
    You can strip out the +, since those coeffs are already positive, and strip out the - after negating the following number. This is all assuming that you have to write this yourself. There is no doubt already a library or 5 out there that does this for you.

  • HT4515 How to make sure that after browsing that the webpage is not running in the background, but totally closed down

    How to make sure that after browsing that the webpage is not running in the background, but totally closed down

    Double tap the Home button, tap & hold the Safari icon until it starts to wiggle, tap the red minus sign to remove it from the Multi-Tasking bar. Tap the Home button when finished.

  • I just upgraded to the new 4, but not sure how to make sure all my apps (purchases) get over to the new phone from iphone 3.  can't seem to find instructions. thanks.

    I just upgraded to the new iphone 4, but am hesitant to get it plugged in b/c I don't know how to make sure all the apps purchased on my iphone 3 get to the new phone.  can't seem to find instructions so I'm sure it just "does it", but hesitant to literally pull the plug.  thanks.

    Follow these instructions:  iPhone: Transferring information from your current iPhone to a new iPhone, http://support.apple.com/kb/ht2109

  • How to draw a perfect circle and how to make sure it is perfectly centered inside a square

    How to draw a perfect circle and how to make sure it is perfectly centered inside a square in Photoshop elements using the Ellipse option.

    1. Create a square canvas.
    2. With the Elipse tool, hold down Shift (Shift forces a circle). Draw the circle anywhere on the canvas (Shape 1 in this example).
    3. Simplify the circle layer
    4. Ctrl-click the layer to select the circle.
    5. Copy the selection to the clipboard (Edit > Copy).
    6. Deselect the selection.
    7. Paste from the clipboard (Edit > Paste). The pasted circle (Layer 1) will be centered.
    8. Delete the original circle layer.
    NOTE: Step 6 is the key. This guarantees that the pasted circle will be centered.
    If you want a circle completely within a square you can simply draw and simplify a circle on any shape canvas. Ctlrl-click the circle to to select it and copy to the clipboard.
    Then do File > New from Clipboard. This creates the circle cropped to a square on transparent background.

  • How to make sure that schema name is not included with generated sqls

    How to make sure that schema name is not included with generated sqls with tableadapter wizard.
    What should I use? Oledb, ODT.NET, where can set that I want "pure" sqls, not schemas, not ", or anything like this
    I want
    "Select a,b from t1" ,not "select "a","b" from schema.t1"
    Also schema name is put in all parameters, all over the place... What if schema name changes. (b1test to b1prod)
    . I now manually edit XML files of dataset. It works but....
    thanks

    The full hardware :
    Processor Intel core due 3.00 MHz
    RAM:1.5GB
    psu:650 Watt (but i baught i cheap one so it may be actually about 400 watt)
    HD Disk:160 GB
    But about the power supply if it not able to run the VGA card ,Is it will not show any screen or it will not able to run the computer??

  • HT200131 how to make sure only my laptop can connect to my apple tv?

    I don't want to see my flatmate apple tv under "connect"
    how to make sure I don't click on his tv accidentally and he won't be able to connect mine?
    thank you!

    Hey J-Justin,
    Great question! You can name your Apple TV to differentiate it from others in the AirPlay list:
    Apple TV: Change the name of your Apple TV - Apple Support
    http://support.apple.com/en-us/HT200028
    Furthermore, you can setup an onscreen code or password to restrict access for AirPlay. The password method sounds like the best option for your setup:
    Apple TV (2nd and 3rd generation): Understanding AirPlay settings - Apple Support
    http://support.apple.com/en-us/HT202618
    Set a password
    Go to Settings > AirPlay > Security > Password > [set password]. You can use this setting to require a password for AirPlay-enabled devices to connect using AirPlay on the Apple TV. Use this setting if your device will need permanent access and you only want to enter the password once.
    Thanks,
    Matt M.

  • How to make 2 clients on same VLAN communicate to each other when tunnel-loop-prevention is enabled?

    Requirement:
    How to make two clients on same VLAN communicate to each other when tunnel-loop-prevention is enabled on tunneled-node configuration at controller?
    Whenever we enable tunnel-loop-prevention on controller while we configure tunneled-node, the communication between two tunneled-node client on same VLAN is blocked or dropped.
    If the tunneled-node clients are of different VLANs then they can communicate between them even when the tunnel-loop-prevention is enabled on the controller.
    Solution:
    To make two tunneled-node client on same VLAN to communicate between them, we need to enable "local-proxy-arp" for the interface VLAN on the controller.
    Once it is enabled now the tunneled-node clients on same VLAN can communicate between each other. 
    Configuration:
    To enable "local-proxy-arp":
    Get to the interface of the VLAN on the controller
    Example :
    (config)#interface vlan 5
    (config)#ip local-proxy-arp
    To enable tunnel loop prevention on controller
    (config)# tunnel-loop-prevention
    Verification
    Show commands:
    To check if tunnel-loop-prevention is enabled or disabled
    #show tunneled-node config
    Tunnelded node Server: Enabled
    Tunnel Loop Prevention: Enabled
    To check if local-proxy-ap is enabled:
    #show interface vlan 5
    Look for in the output "ProxyARP enable"

    streetfi8er wrote:
    Server ready,waiting for client:
    Exception in thread "New THREAD" java.lang.NullPointerException
         at server4$server4Thread.run(server4.java:88)
    Failed to accept client
    when i run the second client programme on different a console in the same system i get the error that:
    Unknown HostOK, I'm no socket programming expert; but I can see a few potential problems with what you've written.
    1. First off, which line is line 88? Line numbers would be useful. Also, indenting your code properly would make it easier to read.
    2. Your 'while(!str.equalsIgnoreCase("close"))' will always fail with a NullPointerException because 'str' is initially set to null.
    3. Your 'while(true)' loop worries me. How does it exit? Relying on an exception is usually very bad practise.
    4. You are not handling SecurityExceptions. While it's unlikely to happen on your machine; it could easily happen on another.
    5. It might be worth indicating the actual exception thrown in your "Failed to accept client" message. accept() can throw three different types of IOException.
    6. All the threads you create will be called "New THREAD", which doesn't provide much value.
    HIH
    Winston

  • How to make sure the maps are loaded though nokia ...

    Hi,
    I have downloaded new nokia map v.3.0109 to my nokia E75 and loaded maps by using nokia map loader (Asia).
    but still I cant see the all regional map which I downloaded, without usign live internet connection.
    How to make sure the maps are loaded properly to my mobile ?
    with regards
    Moderator's note: Email address removed. It is not wise to publish your personal information on a public forum.
    Message Edited by myn1126 on 27-Jan-2010 07:54 AM

    Hi,
    I have downloaded new nokia map v.3.0109 to my nokia E75 and loaded maps by using nokia map loader (Asia).
    but still I cant see the all regional map which I downloaded, without usign live internet connection.
    How to make sure the maps are loaded properly to my mobile ?
    with regards
    Moderator's note: Email address removed. It is not wise to publish your personal information on a public forum.
    Message Edited by myn1126 on 27-Jan-2010 07:54 AM

  • I have received this error message when trying to send a comment to a blog : ERROR: Could not read CAPTCHA cookie. Make sure you have cookies enabled and not blocking in your web browser settings. Or another plugin is conflicting. See plugin FAQ., can any

    I have received this error message when trying to send a comment to a blog : ERROR: Could not read CAPTCHA cookie. Make sure you have cookies enabled and not blocking in your web browser settings. Or another plugin is conflicting. See plugin FAQ., can any...
    Only found one question similar and NO ANSWER to it.

    Same problem here...nothing in my settings have changed since the upgrade and I've checked my cookie settings and they allow 3rd party cookies. What's up Mozilla? I've been faithful to you for years and you let me down now?

  • Hello guys! Do you know how to make a video smaller on imovie? Not by size or trim, i mean simply show the video as small as possible in the middle of the screen! Please text back.

    Hello guys! Do you know how to make a video smaller on imovie? Not by size or trim, i mean simply show the video as small as possible in the middle of the screen! Please text back.

    Go to the Map, Background & Animatic Browser (last button in the centre tool bar alongside the Transition button). Drag the Black background (or any background) to your project. From an Event, drag the video selection directly onto the Black clip in the project. As you drop the video clip, a pop-up menu will appear. Select Picture in Picture.
    Your video will appear as a small picture within the black clip. Click on it and reposition it to the centre of the viewer, using the yellow guide lines to get the exact centre position. Resize the Picture in Picture if desired by dragging the corner handles.
    NOTE: You may need to extend the duration of the Black clip to match the duration of the video clip. Double-click on the Black clip to open the Inspector, then adjust the duration there.
    John
    Message was edited by: John Cogdell - added NOTE

  • How do I use Adaptive Limiter to make sure bounces are same volume?

    Hi,
    I've been making ear training exercises for myself - you can understand what here:
    http://discussions.apple.com/thread.jspa?threadID=490846&tstart=0
    Here's what I need to do - and don't know how:
    I want all bounced exercises to play at the same volume.
    Each exercise has two MIDI regions. The first region (Region #1) plays at the begining of all exercises. When I look at the Output track when Region #1 plays, it is at 0.2 DB - no clipping. However, Region #2 clips in varying degrees depending on what octave an interval is being played at. For instance, a C and E played together around C1 doesn't clip - but transposed to C5 or C6 it clips anywhere from 3.7 to 4.6. I can't just lower the output volume before it clips - because it's important the Region #1 stays the same volume-wise on all of the exercises.
    Some people have said just add an adaptive limiter to the Output 1-2 track... but how do I set it?
    Any suggestions? Anyone understand this?? It's hard to explain on this end...
    Thanks.

    you don't use adaptive limiter to make sure bounces are the same volume.
    that is not the function of the adaptive limiter.
    the limiter puts a ceiling on the signal and optionally raises the gain. You'd use this on certain instruments that are known to produce loud peaks, such as Bass Guitar and Vocal,
    It is used as the last plugin in the chain on the master fader when mixing something down, to prevent the mix from peaking.
    IMO, the logic limiter doesn't destroy anything unless the mix itself has something wrong with it.
    A lot of people reach for limiter when what their ears are really looking for is to multiband compress.
    Your solution is to use a COMPRESSOR (not the multiband compressor, just the simple Logic compressor).
    Do NOT use the default setting of the logic compressor in your case, because it defaults with its 'auto Gain' turned on which will raise your volume (a lot).
    Put a compressor as the first plugin in all of your piano channels, or into a Bus, and set all your piano tracks to output to the bus with the compessor on it.
    Settings:
    THRESHOLD : -10
    ATTACK : 0 (play with it, pianos feel good with a low one,
    could try 15ms or less)
    DECAY : play with it, I'd use 50ms with a Piano track
    AUTO GAIN : off
    GAIN : +4
    RATIO : try 12.0
    This setting will attenuate anything above -10 and will raise the gain up to a healthy level to compensate.
    Anything below -10 won't be touched.
    Since the compressor will 'squash' your signal slightly,
    some frequencies will appear louder to the ear after the piano is compressed. So just AFTER the compressor on the same track, put a Logic Channel EQ and conservatively pull down some of the freq ranges to bring them back to normal.
    And that's it.
    a tip: When working in logic, no matter what the project, when it's time to mixdown put a COMPRESSOR on every single channel as the first plugin. Then play with plugins, etc.
    I do have many issues with Logic's workflow, but the dynamics plugins IMO are very good.

  • [Resoved] How to make sure numeric entry is accepted before saving.

    Running LV 2010.  I have an application in which I talk to some hardware via the USB.  Values are stored in the EEPROM inside the hardware.  I have a screen that shows these variables as floating point numbers, and allows the user to change the variables as needed, then save to the device.  The problem I have is that, if I change a number, and while the numeric field still has focus, I click the save button, the program saves the previous vaue.  It's as if the value was not entered.  If instead, I click off of the newly entered number in the middle of the page somewhere, then click save, it saves the new number.  In the save button routine, I have tried changing the focus to the save button, then "waiting" 10mS for the display to update, then saving, but this does not work.  How do I make sure the screen has accepted the change before I do the save?  Thanks.

    Care to enlighten us so that we can avoid making the same mistake?
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • MacBook Pro 15" 2007 is dead. How to make sure it's the left I/O board?

    My 15" 2007 MacBook Pro is now completely dead. No light on the 85W magsafe (which does work on unibody MBP 15), battery completely empty, no sign of life whatsoever. Apple Store says I need a new "logic board" but could not specify which one, main or left I/O. How can I make sure it is the left I/O board?
    The computers' power circuits have been steadily declining in recent months. It has a checkered history - it's the one that ran hot, had kernel panics due to graphics card drivers, and had the graphics card hardware issue. The computer died in October 2008 and "the logic board" was replaced under Apple Care, free of charge. When AppleCare ran out I bought a unibody MPB and my son inhereted the 2007 model, using it for his music and being pretty happy with it, until the battery would not charge anymore. He then ran it on the power supply only, until it would not boot up. Apple Store did some magic with it (probably reset SMC), it ran for a while longer without charging battery, then did the same thing (not booting, but magsafe connector showing green LED). Searching on the web I found some hints as to how to reset SMC and this worked - once. Took the computer off the magsafe when going on a holiday, when I came back it had deceased.
    Apple Store quoted $ 540 for a logic board replacement. The left I/O board is available online for $ 119 and I am able to mount it myself, would do so if I could make sure that this unit has failed and not the main board. And that, friends, is my question.

    Let the Apple folks - or an AASP - run diagnostics on the machine. They'll be able to tell if you need a new logic board or not. Get an estimate - if it seems outrageous then it's probably time to buy a new computer.
    Just my 2¢...
    Clinton

  • How to make an object of inner class and use it ?

    Hi tecs,
    In my JSF application i have a need to make an inner member class in one of my bean class.
    How can i make the object of this class?(what should be the entry in faces-config)
    And there are text box and check box (in the JSP) associated with the elements of this inner class. What should be the coding in JSP so that elements in the JSP can be linked with the corresponding members of the inner class ?
    Plz help.
    Thnx in advance.

    Hi
    I am havin 10 text boxes in my application.
    But out of 10 , 3 will be always together(existence of one is not possible without the other two.)
    Now i want to create a vector of objects ( here object will consist of the value corresponding to these three boxes),there can be many elements in this vector.
    So i m thinking to make an inner class which have three String variables corresponding to these text boxes that exists together.
    What can b done ?

Maybe you are looking for