Question about object instantiation

I'm trying to do something like this...I want to instantiate an object with a name from user input...but I'm having difficulties.
(the below code is not working for me)
Scanner stdIn = new Scanner(System.in);
System.out.println("Enter Your Name");
stdIn.next() = new Person; Is it possible to instantiate an object directly from user input or am I going to have to do something like this instead?
Person a = new Person();
Person b = new Person();
Person c = new Person();
a.setName().setAge().setWeight().setHeight().setFrame().setBodyFat()Edited by: stuckne1 on Dec 14, 2008 2:28 PM

The reason the code is not working is because in java, you never, ever put a method call on the left hand side of '='. You have to have a variable on the left hand side. Also, don't forget your parentheses when making a new instance of an object (new Person() ).
You could try something like this:
String instr = stdIn.next();
//if instr is valid then...
Person p = new Person(instr);
//else throw errorAs for your chain of sets, does a name have an age, which has weight, etc.? Probably not. You probably want a.setAge(), not a.setName().setAge()

Similar Messages

  • A question about Object Class

    I got a question about Object class in AS3 recently.
    I typed some testing codes as following:
    var cls:Class = Object;
    var cst:* = Object.prototype.constructor;
    trace( cls === cst); // true
    so cls & cst are the same thing ( the Object ).
    var obj:Object = new Object();
    var cst2:* = obj.constructor.constructor;
    var cst3:* = obj.constructor.constructor.c.constructor;
    var cst5:* = Object.prototype.constructoronstructor;
    var cst4:* = Object.prototype.constructor.constructor.constructor;
    var cst6:* = cls.constructor;
    trace(cst2 === cst3 && cst3 === cst4 && cst4 === cst5 && cst5 === cst6); //true
    trace( cst == cst2) // false
    I debugged into these codes and found that cst & cst2 had the same content but not the same object,
    so why cst & cst2 don't point to the same object?
    Also, I can create an object by
    " var obj:Object = new cst();"
    but
    " var obj:Object = new cst2();"
    throws an exception said that cst2 is not a constructor.
    Anyone can help? many thanks!

    I used "describeType" and found that "cst2" is actually "Class" class.
    So,
    trace(cst2 === Class); // true
    That's what I want to know, Thank you.

  • A question about objects and queries

    I just started using COM objects in ColdFusion. I am mostly
    using CreateObject, but occasionaly use <CFOBJECT>
    My question is; Do I have to destroy these object variables
    when I am done? I know in a lot of other languages I work in, you
    have to "clean up'" after yourself and destroy some variables when
    you are done to avoid memory leaks. How does CF handle this?
    While I am asking, what about queries? Do hey have to be
    destroyed as well? What about queries made with QueryNew?
    Thank you for the help.

    Cold fusion cleans up for you.
    You do not need to explicitly destroy anything unless threads
    are spawned in a non standard way by Java or C code that you are
    using.

  • Questions about Objects, pointers, and the memory that loves them

    Hey,
    This is all just a theoretical discussion so do understand that the code itself is not germane to the topic.
    I have been mulling over the whole object release/retain/copy thing and need to understand a bit more the real inner workings of the beast. The catalyst for this is the repetitional fervor that most books on the subject of Objective C have employed. Yet they all seem to fail in a complete explanation of the whys and wherefores so that one can determine on her own the correct implementation of this.
    Let's say I have an Object. For the fun of it it is an instance of NSObject and we'll call it myObject.
    When I "create" this object thusly:
    NSObject *myObject = [[NSObject alloc] init];
    What I, in fact get back is a pointer to the object in question, yes?
    So when I "seemingly" add this object to an array like:
    NSArray *myArray = [[NSArray alloc] initWithObject:myObject];
    What is actually placed in the array? is it another pointer to the original object created by myObject or is it a pointer to the pointer of myObject?
    The reason I ask this is because I have run into a situation where some previous instructions on the subject have caused errors. I was told that if I did something like this and then passed the array to a calling method that I could release this array and it would then be the responsibility of the calling method to handle the memory. Further more if I place an object into an array and then copy it into another object of the same type as the original then I could release the array and still have the reference to the first object in the second object. When I have done this I get unpredictable results, sometimes the original object is there and sometimes it isn't
    At what point should I release the array, after it is passed to the calling method (with the use of an autorelease) or when the class that it is encapsulated in is done?
    Sorry about the length of this but I can't believe that I would be the only one that would be helped by such a discussion.
    MM

    etresoft,
    Thanks for the detailed reply. I wish I could say that I wasn't still a bit confused by this. I thought I had this down after going through the lessons. It seems to not be working in practice the way that it works in theory.
    My current project is an example
    In a class I have declared a couple of ivars thusly:
    NSMutableString *source;
    NSMutableString *destination;
    @property (nonatomic, retain) NSMutableString *source;
    @property (nonatomic, retain) NSMutableString *destination;
    This is followed by the appropriate @synthesize directives.
    in the init method for my class I have the following:
    source = [[NSMutableString alloc] initWithString:@"customer"];
    destination = [[NSMutableString alloc] initWithString:@"home"];
    in a method triggered by a button click I have the following:
    if (sender == sourcePop){
    source = [sourcePop titleOfSelectedItem];
    }else{
    destination = [destinationPop titleOfSelectedItem];
    NSLog(@"SOURCE-%@", source);
    NSLog(@"DESTINATION-%@", destination);
    When I run the code and change the source selection the console reads the correct value for what is in the source popupbutton and "home" for the destination. If I then change the destination popupbutton I get a crash and nothing written to the console.
    Placing a breakpoint at the beginning of the "if" and running shows me that just before the crash the source ivar is reported as "out of scope." There are no release or autorelease statements for this ivar anywhere in the class. Yet if I change the line that sets the ivar to the value of the popupbutton to this:
    [source = [sourcePop titleOfSelectedItem] retain];
    The debugger will have the correct value for the ivar and when run normally there is no crash.
    I would assume that the problem is that the ivar is being released but I am not the one releasing it. Why does this behavior happen? Shouldn't the retain count still be 1 since the @property directive has it and there is no release in the code? Or is it that the statement that sets the ivar to the value of the popup really just setting it to the pointer and it is the popup that is somehow being released?
    Is there something else that I should be doing?
    MM

  • Javascript question about objects

    Hi,
    Let's say I've created a new object. One of the properties of my object
    is an array. I would like another property to return the length of that
    array. How do I do this.
    For instance here's some code (and I hope that the email interface
    doesn't screw this up so badly to make it unreadable. I'm going to avoid
    using square brackets as well by using round ones instead even though
    it's a syntax error, since square ones are known not to work with email.)
    function test(){
         this.a = new Array();
         this.b = this.a.length;
    x = new test();
    x.a(0) = 3;
    x.a(1) = 3;
    x.b;
    Returns 0. In other words, just setting this.b = this.a.length doesn't
    not get updated automatically as this.a is added to.
    Now, I tried turning this.b into a method (ie this.b = function(){return
    this.a.length)  and that works, but then to get the length I keep having
    to refer to myObject.b().
    How can I avoid that? How can I have a built-in length property for an
    object.
    Hope this is clear and has come out legibly via email. Apologies in
    advance if it hasn't.
    Thanks,
    Ariel

    Hi all,
    1) About the original question—which doesn't regard prototype inheritance in itself: "How can I have a built-in length property for an object"—I think the most obvious approach is to directly use an Array as the base object. Since any Array is an Object you can append methods and properties to it while keeping benefit from the whole array's API:
    var myData = [];
    myData.myProp = 'foo';
    myData.myMeth = function(){ return [this.myProp, this.length, this.join('|')]; };
    // Usage
    myData[0] = 10;
    myData[1] = 20;
    alert( myData.myMeth() ); // => foo,2,10|20
    // etc.
    2) Now, if for whatever reason you cannot use the previous technique or need to deal with a precustomized Object structure such as:
    var myObj = {
        items: [],
        meth: function(){ alert("Hello World!"); },
        // etc.
    then the challenge is more difficult for the reasons that Jeff mentioned above. You can anyway mimic a kind of 'binding' mechanism this way:
    // The original obj
    var myObj = {
        items: [],
        meth: function(){ alert("Hello World!"); }
    // Adding length as a 'fake property' (getter and setter)
    (myObj.length = function F(n)
        if( !F.root )
            (F.root=this).watch('length', function(_,ov,nv){ F(nv); return ov; });
            F.valueOf = function(){ return F().valueOf(); };
            F.toString = function(){ return F().toString(); };
        if( 'undefined' == typeof n )
            n = F.root.items.length >>> 0;
        else
            F.root.items.length = n;
        return n;
    }).call(myObj);
    // Usage
    myObj.meth(); // => Hello World!
    myObj.items[0] = 10;
    myObj.items[1] = 20;
    alert( myObj.length ); // => 2
    var x = myObj.length-1; // works too, thanks to F.valueOf
    alert( x ); // => 1
    myObj.length = 5; // testing the setter
    alert( myObj.length ); // => 5
    alert( myObj.items ); // => 10,20,,,
    Of course it's totally unreasonable to implement such an artillery just for the convenience of writing myObj.length instead of myObj.length()—and myObj.length=x instead of myObj.length(x)—so I only suggest this for the sake of experimentation.
    @+
    Marc

  • Question about Object Oriented Design in Oracle

    Hi everyone,
    Right now I'm updating my oracle skills, years ago without programming (last time with Oracle 7.3 :O)
    Well, if I have to design a new system with this features:
    1.- Using Oracle as DB
    2.- Web enable
    3.- OO Design
    My questions:
    1.- What is the best practice to make database design? E-R + Object Types? I mean is better making the design on Oracle directly or in Java-UML environment?
    2.- I was thinking in programming with Forms, but it works well with OO design?
    3.- If I want to program some web services based, Could I do it with PL/SQL and Jdeveloper?
    please if you know about articles and whitepapers about OO design approach with Oracle let me know!
    Thanks.

    I have been involved in some of these projects that have used Java, C#, VB, C++ etc. as front-end languagaes. I have been able to implement these projects successfully using the following approach:
    1. create a relational model of the database - third-normal form (assuming it is an OLTP application)
    2. Write PL/SQL code (packages and procedures mainly)
    3. Interact with the front-end layer by sending and receiving ref curosors and/or PL/SQL tables
    If you want to use Forms (I am assuming Oracle Forms) then there may not be much need for an OO design. Embeeding SQL in the forms will do most of what you want.
    Shakti
    http://www.impact-sol.com
    Developers of Guggi Oracle - Tool for DBAs and Developers

  • Question about object retention and scope

    I have a hole in my understanding of Cocoa.
    I can create temp objects, to populate an array with, like this:
    for(int i=0;i<10;i++)
    myObject *tmpObj= [[[myObject alloc] init]] ;
    [[myMutableArray addObject:tmpObj]];
    [[tmpObj release]];
    But I don't understand why this works. If the tmpObjects get released, then why don't the ones in the array get released? (I can access the array later, and it is populated with myObjects.)

    If you create an object from scratch (alloc, etc) then it's up to you to release it.
    If you get an object from another method of the system you don't have to worry about releasing it. More than likely it's set to auto-release but it's not your responsibility.
    If you want to hold on to any object then you retain it if you didn't create it. Any object you've retained you're responsible for releasing.
    If you pass an object before releasing it's up to that object to hold on to it if it needs it.
    Links:
    http://www.stepwise.com/Articles/Technical/2001-03-11.01.html
    http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/Memor yManagementRules.html
    Article on leaks
    http://www.cimgf.com/2008/04/02/cocoa-tutorial-fixing-memory-leaks-with-instrume nts/

  • Question about objects

    Hi
    I make a number of objects, they are all from the same class but have differing values.
    I put the objects into different arrays
    I put all the objects in a hash table so that i can associate the object with a string.
    tempOb = create.make()
    compFd= tempOb; //
    tempStr = compFd[i].returnTextValue();
    theRef.put(tempStr, tempCard);
    My question is where do the objects actually exist - and where are they only a reference to the object ? I ask because i am thinking that maybe its uneccsary to make arrays for objects when i could simply have string arrays and use the string to take the object from the hash table.
    Thanks

    Hi
    I make a number of objects, they are all from the same
    class but have differing values.
    I put the objects into different arrays
    I put all the objects in a hash table so that i can
    associate the object with a string.
    tempOb = create.make()
    compFd= tempOb; //
    tempStr = compFd[i].returnTextValue();
    theRef.put(tempStr, tempCard);
    My question is where do the objects actually exist -
    and where are they only a reference to the object ? I
    ask because i am thinking that maybe its uneccsary to
    make arrays for objects when i could simply have
    string arrays and use the string to take the object
    from the hash table.
    Thanks
    FIrst of all you need to revisit what an object is?
    An object is a self-contained entity which has its own private collection of properties (ie data) and methods (ie. operations) that encapsulate functionality into a reusable and dynamically loaded structure. After a class definition has been created as a prototype, it can be used as a template for creating new classes that add functionality. Objects are programing units of a particular class. Dynamic loading implies that applications can request new objects of a particular class to be supplied on an 'as needed' basis. Objects provide the extremely useful benefit of reusable code that minimizes development time. As far as the storage is concerned and all object variables are references.

  • Easy question about objects

    why with this code;
    private Scanner x;
    public void openfile(){
    try {
    x = new Scanner(new File(chinese.txt));
    why do you say x is a variable at private scanner x and then make x an object? why do both variable and object? the code is from http://www.youtube.com/watch?v=3RNYUKxAgmw
    Edited by: 980099 on Jan 19, 2013 4:30 PM
    Edited by: 980099 on Jan 19, 2013 4:38 PM
    Edited by: 980099 on Jan 19, 2013 4:42 PM

    why do you say x is a variable at private scanner xThe code doesn't actually say it's a variable, but it is. It is a reference of type Scanner. As it isn't initialized in the declaration, its initial value is null.
    and then make x an object? It doesn't. it creates a new Scanner instance and then assigns the reference to 'x'.
    why do both variable and object?You should now be able to see that the question is meaningless.

  • A question about Object Manager

    Hello, a question set the server with the installation wizard, select all ObjMgr of application, but I have none running on the server, only the following:
    srvrmgr> comp list for server SERVER
    CC_ALIAS SV_NAME CC_NAME CT_ALIAS
       CC_RUNMODE CG_ALIAS CP_DISP_RUN_STATE CP_STARTMODE CP_NUM_RUN_TASKS CP
    CP_ACTV_MTS_PROCS MAXTASKS CP_MAX_MTS_PROCS CP_START_TIME CP_END_TIM
    E CC_INCARN_NO CC_DESC_TEXT
    SERVER FSMSrvr FSMSrvr File System Manager
       Online Auto Batch SystemAux 0 20
                1 1 2012-06-29 16:52:39
    SERVER ServerMgr ServerMgr Server Manager
       Interactive System Running Auto January 20
                                                     2012-06-29 16:52:34
    SRBroker SERVER Server Request Broker ReqBroker
       Interactive System Running Auto July 10
    0 1 1 2012-06-29 16:52:34
    Server Request Processor SERVER SRProc SRProc
       Interactive Running Auto SystemAux February 20
                1 1 2012-06-29 16:52:39
    SvrTblCleanup SERVER Server Tables Cleanup BusSvcMgr
       Background Running Auto SystemAux January 1
                                                     2012-06-29 16:52:39
    SvrTaskPersist Server SERVER Task Persistence BusSvcMgr
       Background Running Auto SystemAux January 1
                                                     2012-06-29 16:52:39
    SERVER Siebel Administrator Notification Component AdminNotify AdminNotif
    Auto Online and Batch SystemAux 0 10
                1 1 2012-06-29 16:52:39
    Siebel Connection Broker SCBroker SERVER SCBroker
       Background Running System Auto 1 January
                                                     2012-06-29 16:52:34
    8 rows returned.
    how I can change others?

    Sebastian,
    You can run command below using srvrmgr:
    enable compgrp callcenter
    Callcenter component group has call center Object Manager. You need to restart the Siebel Server after running this command. Check link below for further details:
    http://docs.oracle.com/cd/E14004_01/books/SystAdm/SystAdm_SrvrMgrCLI12.html#wp1004864
    You may need to assign the component group to a specific siebel server.
    Thanks,
    Wilson

  • Basic questions about Objects and variables...

    If I have the following:
    Species theAnimal = new Species();
    Am I right in saying that the object here is 'theAnimal'?.
    If we just wrote it as:
    Species theAnimal
    Then i'm assuming that here 'theAnimal' is the variable name...right?
    I'm just trying to get facts straight when reading.
    Thanks for the help...
    Yash

    At first, theAnimal is pointing to one object, and
    theMammoth is pointing to another?
    In the final line, they're both pointing to the same
    object. Isn't that kind of saying, they're pointing
    to the same memory address/location?Yes.
    They might actually hold the physical memory address of the object, or they might hold some other abstraction that the VM uses to locate the object. In either case, though, they both hold the same value, and you can picture that value as the address of the object.

  • Question about object lock

    Hello everyone,
    I want to know which method owns the lock of a specific object (some of my methods are blocked because they can not achieve the lock of a specific object, and I am wondering which method owns the lock to solve the deadlock issue). Does anyone know how to get the information?
    Thanks in advance,
    George

    Thanks Feamar,
    U should not think of a method as having a lock,
    rather than that u should think of a piece of
    synchronized code to have the lock on an object.
    U should try and find nested synchronization
    statements in your code, those are risky and can lead
    to deadlocks.
    Good luckYour reply is very helpful. What means "nested synchronization statement" in your reply?
    regards,
    George

  • LDAP BC QUESTION ABOUT OBJECT CLASSES

    Hi
    i am working with a bpel and its ldap-bc, when i create an entry in my ldap through the bpel it has all the object classes from the attributes i set. for example if i set cn and sn attributes then my entry has the object class person; i want to know if there is any way of setting object classes to my entry on the ldap, even if i am not setting any attributes; for example if i only set the cn and sn attributes using the bpel, i still can tell the entry that it can has another objectclass like iplanet-am-user-service with out setting any of its attributes.
    thanks for your help

    Actually, I'm not getting duplicate objects, but I like to get rid of
    doubles in one particular column.
    For example if I had a table as follows:
    Table DESC
    int pkid
    String description
    description can contain duplicate entries, I want to query as follows:
    select distinct description from DESC
    How could I write a query which retrieves all tuples in a table, but removes
    duplicate from a specific column?
    Thanks.
    Andreas.
    Abe White wrote:
    How does the engine use DISTINCT automatically?It detects whether joins are made such that duplicate rows might be
    returned from the JDOQL filter, and if so adds a DISTINCT.
    What I basically want to do is to remove any doubles I get from the
    query. When I turn logging on to see the sql statement, I only get a
    SELECT without the DISTINCT keyword.You shouldn't be getting doubles. If you are, could you please post the
    offending JDOQL filter and give some description of the schema and/or
    object model? There is a bug in Kodo in which some queries involving OR
    clauses and joins are not made DISTINCT when they should be, but it has
    been resolved for our upcoming 2.5 release.
    Is there also a way I can specify GROUP BY?No, JDOQL does not have an equivalent to GROUP BY.

  • Question about Object

    Hi, when I tried to initialise the Object with values it will give me error.
    eg.
    private Object[][] data;
    public MyClass(){
    data ={
    {"Information1"},
    {"Information2"}
    The error says illegal start of expression at data={. I do not want to initialise data when I declared it. Are there any ways to get around with this?
    Thanks in advance.

    Like this:
    public MyClass() {
      data = new Object[] {
        {"Information1"},
        {"Information2"}     

  • Question about Object Reference

    I have this situation:
    CREATE OBJECT equipo EXPORTING sernr = p_sernr1
                                   matnr = p_matnr1.
    CALL METHOD equipo->ingreso_directo_homologado
                         EXPORTING centro  = aux_centro
                                   almacen = ga_pos_entregas-almacen              IMPORTING error   = error
                                   texto   = p_texto.
    CREATE OBJECT equipo EXPORTING sernr = p_sernr2
                                   matnr = p_matnr2.
    CALL METHOD equipo->ingreso_directo_homologado
                         EXPORTING centro  = aux_centro
                                   almacen = ga_pos_entregas-almacen              IMPORTING error   = error
                                   texto   = p_texto.
    Could be that second CREATE OBJECT sentence fails, and second CALL METHOD sentence refers to first object created?
    Points guaranteed.

    Hi,
    I have Test the same ; which i have written above . it working fine.
    U can cross check. ( copy paste the code & run it )
    Check the value <b>o_alvgrid</b> in debugging mode.
    u will fine new refrence for each create object.
    DATA  : o_alvgrid       TYPE REF TO cl_gui_alv_grid,
            o_custcontainer TYPE REF TO cl_gui_custom_container,
            o_custcntr_sum  TYPE REF TO cl_gui_custom_container.
    CONSTANTS :
           lc_custcontrol  TYPE scrfname VALUE 'CC_ALV',
           lc_custcntr_sum TYPE scrfname VALUE 'CC_ALV_SUM'  .
        CREATE OBJECT o_custcontainer
          EXPORTING
            container_name              = lc_custcontrol
          EXCEPTIONS
            cntl_error                  = 1
            cntl_system_error           = 2
            create_error                = 3
            lifetime_error              = 4
            lifetime_dynpro_dynpro_link = 5
            OTHERS                      = 6.
          CREATE OBJECT o_alvgrid
            EXPORTING
              i_parent          = o_custcontainer
            EXCEPTIONS
              error_cntl_create = 1
              error_cntl_init   = 2
              error_cntl_link   = 3
              error_dp_create   = 4
              OTHERS            = 5.
        CREATE OBJECT o_custcntr_sum
          EXPORTING
            container_name              = lc_custcntr_sum
          EXCEPTIONS
            cntl_error                  = 1
            cntl_system_error           = 2
            create_error                = 3
            lifetime_error              = 4
            lifetime_dynpro_dynpro_link = 5
            OTHERS                      = 6.
          CREATE OBJECT o_alvgrid
            EXPORTING
              i_parent          = o_custcontainer
            EXCEPTIONS
              error_cntl_create = 1
              error_cntl_init   = 2
              error_cntl_link   = 3
              error_dp_create   = 4
              OTHERS            = 5.
    write :/ 'ABC'.
    <b>As per 2nd  post of urs .</b>
    i think result will be unpredictable.
    initial value of refrence variable are always ...illegal refrence.
    it may clear the variable to initial value
    or
    it may retain the current memmory location.
    <b>Reward Points & Mark Helpful Answers</b>

Maybe you are looking for

  • How do I send images in-line in text eMails?

    Using TB 24.6.0 and sending eMails in text format (not HTML) I am unable to add images (J-pegs) in-line. How do I overcome this problem or it is not actually possible in TB? Many thanks

  • Time Capsule & Bethere UK = Not compatible?

    I recently bought a 1GB time capsule and wanted to hook it up with my Bethere 24Mbit router. I plugged in the time capsule, hooked it up with a LAN cable to my Bethere router. Then I plugged in another LAN cable from the time capsule to my Macbook. M

  • HT1386 iTouch/iTunes sync issue

    My iTouch is (all of a sudden) not able to connect with iTunes (PC) with a USB connection.  The PC doesn't appear to recognize/acknowledge it.  No reason to believe there's any software corruption or hardware damage...my iPhone continues to connect/s

  • Personal number error in CJI3

    In Activity type allocation through KB21N, I post man hrs against some personal numbers. When I see line item report CJI3, I am not seeing the same personal number I entered in KB21N. Which ever Personal number I entered in KB21N, it shows a fix cons

  • Problem with adobe audicion 1,5

    I have a problem for installations adobe audicion 1.5 install it and then there was error in Windows Media Format 9 Series Runtime this Windows Media technology is incompatible with this version Setup program from Windows Media format is not respondi