How to reference a class without using the new keyword

I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
c.getFirstName();

quedogf94 wrote:
I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
c.getFirstName();No.
Using new does not erase anything. There's nothing to erase. It's brand new. It creates a new instance, and whatever that constructor puts in there, is there. If you then change the contents of that instance, and you want to see them, you have to have maintained a reference to it somewhere, and access that instance's state through that reference.
As already stated, you seem to be confused between class and instance, at the very least.
Run this. Study the output carefully. Make sure you understand why you see what you do. Then, if you're still confused, try to rephrase your question in a way that makes some sense based on what you've observed.
(And not that accessing a class (static) member through a reference, like foo1.getNumFoos() is syntactically legal, but is bad form, since it looks like you're accessing an instance (non-static) member. I do it here just for demonstration purposes.)
public class Foo {
  private static int numFoos; // class variable
  private int x; // instance varaible
  public Foo(int x) {
    this.x = x;
    numFoos++;
  // class method
  public static int getNumFoos() {
    return numFoos;
  // instance method 
  public int getX() {
    return x;
  public static void main (String[] args) {
    System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
    System.out.println ();
    Foo foo1 = new Foo(42);
    System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
    System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
    System.out.println ("foo1.x is " + foo1.getX ());
    System.out.println ();
    Foo foo2 = new Foo(666);
    System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
    System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
    System.out.println ("foo1.x is " + foo1.getX ());
    System.out.println ("foo2.numFoos is " + foo2.getNumFoos ());
    System.out.println ("foo2.x is " + foo2.getX ());
    System.out.println ();
}

Similar Messages

  • Hello! I'm out of the country and all my iWeb information is on my computer at home. Now I need to make changes on the webpage... how can i do that without using the computer i made the page on? Thank you!!

    Hello! I'm out of the country and all my iWeb information is on my computer at home. Now I need to make changes on the webpage... how can i do that without using the computer i made the page on? Thank you!!

    iWeb uses the domain.sites2 files to store its assets.
    You'll find it here :
    ~/Library/Application Support/iWeb/
    where ~ is your Home directory.
    If you take a computer with you, you have to store that file in the same location.
    It's not different from taking documents with you if you want to edit them.
    A solution is to remotely control your computer at home.
    TeamViewer, LogMeIn, Apple Remote Desktop or any VNC application you can use, like "Chicken of the VNC".

  • How do i install opensolaris without using the virtual box??

    hi.
    i am new to solaris
    i am currently using a windows XP OS
    i got down the opensolaris cd from SUN
    how do i install opensolaris without using a virtual box ?

    The OpenSolaris CD is a "Live CD". You can boot off of the CD, and either run the OpenSolaris operating system directly, or you can select the "Install" icon on the LiveCD desktop. You can find full instructions here: http://dlc.sun.com/osol/docs/content/IPS/getst1.html
    Do you want to keep your Windows OS on the disk? If so, then you want to follow the instructions for partitioning your disk (unless you already have a spare partition).
    -- Alan

  • How to install snow leopard without using the dvd drive?

    Is it possible to install snowleopard  without using the dvd ? i have a macbook and i have unfortunatly broken the cd and dvd player..

    Yes you can.
    How to use Migration Assistant:
    http://support.apple.com/kb/HT4889?viewlocale=en_US
    http://support.apple.com/kb/HT4413?viewlocale=en_US
    http://support.apple.com/kb/TS1963

  • RPM - How to re-process prices without using the front end.

    Hi all,
    There is a way of re-processing prices without using the front end? For instance, using the front end, a new clearance is created state in rpm_clearance ‘pricechange.State.conflictCheckforApproved’ and changed for ‘pricechange.State.worksheet’ after the conflict check.
    Now, I want to re-process the same clearance without using the front end. I’ve tried to change again the STATE to ‘pricechange.State.conflictCheckforApproved’ but no success. Any suggestions?
    Thanks in advance.
    Regards

    Can you please attach your VI?
    Prashanth N
    National Instruments

  • How to create a inputstream without using the file operation

    Hi friends
    In my application, I have to create a Streamsource object using the below constructor:
    public StreamSource(InputStream inputStream)
        Construct a StreamSource from a byte stream. Normally, a stream should be used rather than a reader, so the XML parser can resolve character encoding specified by the XML declaration.
        If this constructor is used to process a stylesheet, normally setSystemId should also be called, so that relative URI references can be resolved.
    Parameters:
        inputStream - A valid InputStream reference to an XML stream.*[http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/stream/StreamSource.html#StreamSource(java.io.InputStream) |http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/stream/StreamSource.html#StreamSource(java.io.InputStream) ]*
    But for creating the inputstream, i am creating a tempory file, ie I am using fileinputstream.
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.StringReader;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    public class SourceConvertor
        private static Source convertStaxToStream(Source request)
    // here the argument to this method is StaxSource and the return type is StreamSource
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = null;
            File fp = null;
            FileInputStream fInp = null;
            try
                transformer = factory.newTransformer();
                fp = new File("tempFile.txt");
                transformer.transform(request, new StreamResult(fp));
                fInp = new FileInputStream(fp);
            } catch (Exception e)
                e.printStackTrace();
            return new StreamSource(fInp);
        public static void main(String args[])
            try
                String message ="<author><name>Rai</name><book>GodOfSmallThings</book></author>";
                Source original = new StreamSource(new StringReader(message));
                Source converted = convertStaxToStream(original);
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer();
                transformer.transform(converted, new StreamResult(System.out));
            catch (Exception e)
                // TODO Auto-generated catch block
                e.printStackTrace();
    This is not at all a good aproach because evey time it is creating a new file.
    So can anyone suggest a better aproach or idea or a simple code snippet so that i can create the inputstream without creating a temporary file.
    Thanks in advance:
    *[http://www.javamilestone.blogspot.com/  |http://www.javamilestone.blogspot.com/  ] *

    Err, a StreamSource is a Source. Check the Javadoc. You can pass it directly to the transform.

  • How do i make selections without using the mouse?

    for example, when I go to quit Photoshop, there is a box that comes up that asks whether I want to save changes to a file before I quit. Below are three buttons; "Don't Save", "Cancel", and "Save". The "Save" button is a dark blue, and if I simply hit the return key, I've made my selection as "Save". I know that if I hit the "Command" key and the period at the same time, I've made my selection as "Cancel".
    What I can't figure out is how to make the selection for "Don't Save" only using the keyboard?
    Thanks!

    command d clicks the "Don't save" button from the keyboard without having to select it first in almost any application.

  • How to create a domain without using the root user in Sunone Server

    Hi,
    I am having one requirement to create a domain without using root user in sunone application server 8.1. Does any body know the solution?
    Message was edited by:
    SPBP

    Hi,
    If you are using file-based installation, you can install as non-root user and create domains as usual. You can use asadmin command available at <AS_INSTALL>/bin to do this.
    ex: ./asadmin create-domain domaindir /tmp/justfortest adminport 4850 --adminuser admin domain_nonroot_test
    Did you face any problem doing this in non-root. Unless you have write permissions in domaindir, you won't be facing any problem.
    Hope this clarifies your question.
    Thanks,
    -Balaji.

  • How to create window key without using the trillium option

    Hi,
    I am having some problems when trying to create using the window key generator module in ODI data quality.
    I created a business data parser for cleansing my records. This had to pass thru 4 routines, the transformer, parser, window key generator and the matcher routines. The transformer and parser routines have run properly but they window key generator is asking me to specify the window key.( I created the rules for the window key. Like last 3 consonants of last name and 5 digits of some ID). But this is not getting accepted when i am running it and pops an error message.
    I also do not have the trillium module integrated with ODI as of now.
    Can anyone help me with this problem or anyone has faced the same situation and have tried a work around for it.
    Please let me know.
    Thanks,
    Chapanna

    Hi,
    If you are using file-based installation, you can install as non-root user and create domains as usual. You can use asadmin command available at <AS_INSTALL>/bin to do this.
    ex: ./asadmin create-domain domaindir /tmp/justfortest adminport 4850 --adminuser admin domain_nonroot_test
    Did you face any problem doing this in non-root. Unless you have write permissions in domaindir, you won't be facing any problem.
    Hope this clarifies your question.
    Thanks,
    -Balaji.

  • How to stop a session without use the kill

    We are developing an application client/server using DELPHI and ORACLE (10.1.0.5.0).
    Into our application we would like to have the a button to stop a query on the database.
    Delphi programmers explain me that they are unable to implement that function because DELPHI is unable to stop a query started into a thread: if you start the query into the main thread, DELPHI can stop the query.
    So they ask me if they can kill the session using the ALTER SYSTEM KILL.....
    What do you think about it?
    Do you have any suggestion to resolve the problem?

    Of course, if your query is running, this is not a solution, you should have the hand to run an "alter session". And if your query is running, you have not.
    So, in your Delphi application, you fire a query, and if no response after some time, you want to allow the user to cancel the query, right ? Like there is such button in Toad ? It is more or less a simulate of CTRL-C in SQL*Plus. Maybe some specific Delphi function.
    Nicolas.

  • How to reboot RT programatically without using the VI

    I have a bunch of PXI RT systems deployed. We setup an IVI looking interface for our client monitor systems to the PXI RT systems, this is over enet.  Other than snooping the network activity, can anyone provide the command structure needed to send the reboot command to the RT systems?  We can NOT use the included labview VI because some of our clients are running VxWorks.
    Thanks!

    Hello JFTICH,
    For any PXI Real-Time systems that have LabVIEW Real-Time, the VI you spoke of will definately work.  It sends the command to the specified PXI systems.  After looking at the VI, I see that it is locked.  The way that it creates this functionality is protected for some reason.  Perhaps you could contact National Instruments Support for some more information regarding its method of operation.
    You can create a service request here: ni.com/support
    Steven T.

  • How do you burn a playlist using the new version  of itunes if no provision is made unlike previous versions. have thaey ( Programmers made a mistake)

    Downloaded latest version of itunes. Noticed that there is no provision to burn a playlist to CD under the file menu as in past versions. Although the help menu still references this function. Is this an oversight ?
    Also noticed that the  new  itune program which interfaces with the iphone 5 , will only play videos bought through itune store. Where previous versions would play any video, or have I got wrong??
    Any help would be appreciated .
    Thanks
    Oldsalt 94

    Someone gave me the Mac Format magazine (Jan 2013), which contained a complete guide to iTunes 11.
    One section was "Get the old look back".  It stated that it was possible to tweak the interface to get the old look back by:-
    1.  Be on Music view and select Songs tab at top of window.
    2.  Click on the View menu.  (Mine was hidden, but if you click on the dropdown arrow in the top left-hand corner the option is there to show the Menu Bar).
    3.  Click on Show Sidebar, then click on Show Status Bar.
    This should make iTunes look like the old version.
    Hope this helps others :-)
    Slightly happier Apple!

  • How to open a JCalendarCombo without using the mouse ???

    In my swing-application i implementet a JCalendarCombo Object for selection of different Date Times.
    Now it's necessary to display this JCalendarCombo for example entering a Key (F1/F2 etc.)
    I didn't find a possibilty to realize this item.
    The JCalendarCombo package is downloaded with the following packages:
    org.gui.ButtonActionListener
    org.gui.ButtonItemListener
    org.gui.ComboBoxItemListener
    org.gui.JCalendar
    org.gui.JCalendarCombo
    org.gui.JDayButton
    org.gui.JDayLabel
    org.gui.TextFieldMouseListener
    All Classes instead of MouseListener are protected, so that it's not possible to call a method like "initializeCalendar" ore something like that.
    No methods like key-Listener are implementet.
    Here's the source code:
    * test6.java
    * Created on 13. M&auml;rz 2008, 15:25
    import org.gui.JCalendarCombo;
    import java.util.GregorianCalendar;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Locale;
    import javax.swing.JComponent;
    import org.gui.JCalendar;
    import org.gui.JCalendarCombo;
    import java.awt.Robot;
    * @author goetz
    public class test6 extends javax.swing.JFrame {
    /** Creates new form test6 */
    public test6() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {//GEN-BEGIN:initComponents
    jPanel1 = new javax.swing.JPanel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jTextField3 = new javax.swing.JTextField();
    jTextField4 = new javax.swing.JTextField();
    jTextArea1 = new javax.swing.JTextArea();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jTable1 = new javax.swing.JTable();
    //org.gui.JCalendar cal=new org.gui.JCalendar();
    Date heute=new Date();
    GregorianCalendar today = new GregorianCalendar();
    today.setTime(heute);
    GregorianCalendar calendar = new GregorianCalendar();
    int currentmonth =today.get(GregorianCalendar.MONTH);
    int currentyear = today.get(GregorianCalendar.YEAR);
    int currentday = today.get(GregorianCalendar.DAY_OF_MONTH);
    calendar.set(currentyear, currentmonth, currentday);
    JCalendarCombo jCalendarCombo = new JCalendarCombo(JCalendarCombo.MONDAY, true, 1900, 3000, false);
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    jCalendarCombo.setDateFormat(JCalendarCombo.YEAR_BIG, JCalendarCombo.MONTH, JCalendarCombo.DAY, '.');
    jCalendarCombo.setDate(calendar);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    jTextField1.setText("jTextField1");
    jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 130, -1));
    jTextField2.setText("jTextField2");
    jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, 130, -1));
    jTextField3.setText("jTextField3");
    jPanel1.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, 130, -1));
    jTextField4.setText("jTextField4");
    jPanel1.add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 190, 140, -1));
    jTextArea1.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(java.awt.event.KeyEvent evt) {
    jTextArea1KeyPressed(evt);
    jPanel1.add(jCalendarCombo,new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 20, -1, -1) );
    jPanel1.add(jTextArea1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 50, 70, 40));
    jButton1.setText("jButton1");
    jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 270, -1, -1));
    jButton2.setText("jButton2");
    jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 270, -1, -1));
    jTable1.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null}
    new String [] {
    "Title 1", "Title 2", "Title 3", "Title 4"
    jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(java.awt.event.KeyEvent evt) {
    jTable1KeyPressed(evt);
    jPanel1.add(jTable1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 110, -1, -1));
    getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 30, 500, 350));
    jCalendarCombo.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(java.awt.event.KeyEvent evt) {
    jCalendarComboKeyPressed(evt);
    pack();
    }//GEN-END:initComponents
    public void jTable1KeyPressed(java.awt.event.KeyEvent evt) {
    // Add your handling code here:
    if(evt.getKeyCode()==evt.VK_ESCAPE)
    System.out.println("registriert");
    //jPanel1.setCursor(jTextField2);
    jButton1.requestFocus();
    public void jCalendarComboKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
    // Add your handling code here:
    if(evt.getKeyCode()==evt.VK_F6)
    System.out.println("registriert Calendar");
    //jPanel1.setCursor(jTextField2);
    //jButton1.requestFocus();
    }//GEN-LAST:event_jTable1KeyPressed
    public void jTextArea1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextArea1KeyPressed
    // Add your handling code here:
    if(evt.getKeyCode()==evt.VK_ESCAPE)
    System.out.println("registriert");
    //jPanel1.setCursor(jTextField2);
    //java.awt.event.FocusListener l=new java.awt.event.FocusListener();?????????????????????
    //jCalendarCombo.addFocusListener(FocusListener);???????????????????????
    //mvt.MOUSE_CLICKED;
    //org.gui.TextFieldMouseListener.mousePressed(mvt);????????????????????????????????
    try???????????????????????????????????????????????????????
    java.awt.Robot rob=new java.awt.Robot();????????????????????????????????????????????&szlig;
    rob.mousePress(3)??????????????????????????;
    catch(Exception e)
    }//GEN-LAST:event_jTextArea1KeyPressed
    /** Exit the Application */
    public void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
    System.exit(0);
    }//GEN-LAST:event_exitForm
    * @param args the command line arguments
    public static void main(String args[]) {
    new test6().show();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jButton2;
    public javax.swing.JTextField jTextField3;
    public javax.swing.JButton jButton1;
    public javax.swing.JTextArea jTextArea1;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JTextField jTextField2;
    public javax.swing.JTextField jTextField1;
    public javax.swing.JTextField jTextField4;
    public javax.swing.JTable jTable1;
    public JCalendarCombo jCalendarCombo;
    // End of variables declaration//GEN-END:variables
    Has anybody an idea ????
    The parent Frame was created with sun one studio 4 community edition.
    The JCalendar Combo was implemented by myself and runs properly by mouse, not by keyboard.

    the code's not formatted so I'm not going to try to read it,
    and there's too many ?? to remove before it will compile,
    so, you say it works with the mouse - how, clicking a button?
    if so, search for the keyBindings tutorial where you can set up
    an action for (e.g.) F2 to do button.doClick()

  • I had start over just like getting a new computer, one thing, i lost mail and iphoto, but my daughter has it on her's.  how can i get it without using the start disk, because i don't have one.

    how do i get back mail and iphoto?

    Mail should be there, have you looked in the Aplications folder?

  • I want get an acount with Apple ID but i dont have a credit card, how i can do this without using the bank account

    Hello, i want to create a account to get Apple ID to download free apps from iTunes, but when I try it I must put an bank account but I didn`t have it. This is my first apple product and I`m a little disappointed because there are a lot of problems to do a simply things. Thanks and sorry for my English.

    To Create a New Account... See Here...
    Create an iTunes App Store account without a credit card

Maybe you are looking for

  • Issue with PO Response in SRM 7.0

    Hi Experts, We have upgraded our system from SRM 4.0 to 7.0. Post upgrade we are facing an issue with PO Response document. Scenario:          When the PO is ordred, Vendor sends a the PO response through XML. Our middleware call the an FM which uses

  • What are the drawbacks of creating execute queues

    Hi thread Gurus What are the drawbacks of using execute queues. I understand that if queues are not used they stay idle but on solaris the SunOS scheduler will only give active threads CPU time. what ar the other resources being wasted in the process

  • Sharepoitn 2013 - Office Web Apps Licensing

    Dears, I do have the license key with me for the office web apps 2013. The office web apps are working with our SharePoint 2013 portal without any issues. We were able to view the documents but couldn't edit the documents which are hosted in our port

  • How do i make a navigation bar for all pages

    Hi friends ! I want the same navigation bar to appear on all the web pages of my website. (As these are the common things that all the webpages will have). But I didn't find any option to use the navigation bar as a template. Will I have to copy and

  • How can i hook up my droid 2 to get netflix on hdtv

    how can i hook up my droid2 to my tv to get netflix