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.

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.

  • Easy question about Reformatting

    Hello all,
    I am trying to reformat my HD after I have deleted Windows XP off of a partition. The reason for this is an upgrade to Vista and a larger allotment of HD space. My question is:
    I am using Backup v3.1.1. (v369) and I have FULL backup files of my Home folder, and my Music folder (as backup for my backup) for all my iTunes libraries. These are located on a portable HD. Are these the correct files to have backed up in order to have my MAC the way it was before I started the process? If so, then once the reformatting is complete, how do I get it all back onto my MAC permanently? Will all my apps and tweaks work as before?
    I am sure this is a simple question, however, I have never had to do this with a MAC, and I want to make sure I have all bases covered before I begin this. Any other comments or advice would be greatly appreciated.
    Thanks All!

    You call this an easy question ???
    Just messin with ya
    Your home folder is the most important folder containing your music, documents, preferences etc. but a lot is also stored in the system folder and library folder outside your home folder, if you want to be ensured of an exact copy of your current system the best way to go at this is to clone your system partition.
    The app i use for this is carbonCopyCloner
    http://www.bombich.com/software/ccc.html
    To add to this.. i've heard there is software for the mac that allows you to make adjustments to the size of your partitions without having to format the drive, i don't know the names of these products but i do know that it's very risky to use them, if you decide to use an app like that make sure you have proper backups of everything just in case it goes wrong.
    Message was edited by: Pr0digy V.

  • Real easy question about defining objects in java

    hey guys here is my problem. I am trying to implement an insert() method for my binary tree. i have my node class defined to contain
    public T element() {
              return _data;
    and then my actual tree class has an instance of this declared to be called runner.
    BTreeNode runner;
    runner = _root;
    The problem occurs when i try to compare what i am inserting (obj) with what i have (runner.element) The actual line of code is
    ( obj.compareTo(runner.element) < 0 )
    i get an error that says "runner.element cannot be resolved or is not a field".
    I believe the error comes because i didnt adequately define runner but im not sure how to take care of that. Any suggestions would be most appreciated.
    -peter

    this is all of the code that has a relation to the error I am getting. The error is found in the BasicBTree class and says
    "The method compareTo(T) in the type Comparable<T> is not applicable for the arguments
    (Comparable)"
    Basic Binary Tree Node class
    public class BTreeNode<T extends Comparable<T>> implements Position<T> {
         private BTreeNode<T> _left;
         private BTreeNode<T> _right;
         private BTreeNode<T> _parent;
         private T            _data;
         public T element() {
              return _data;
         }Basic Binary Tree class
    public class BasicBTree<T extends Comparable<T>> implements BinaryTree<T> {
    public void insert(T obj) {
              BTreeNode runner;
              runner = _root;
              if (obj.compareTo (runner.element()) = null) { // ERROR OCCURS HERE
                   _root = new BTreeNode(obj);
              return;   
    }the interface posistion
    public interface Position<T> {
         public T element();
    }

  • 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

  • Easy Question about resizing video

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    In my old program "Premiere', to resize and move a video around was very easy. You could adjust the scale and X-Y values numerically, or you could use a Free Transform like in Photoshop. Simply dragging bounding boxes for size and aspect and also dragging the clip to decide it's location.
    The only way I know how to do this in FCP is I double click a clip in the sequence, it loads into the viewer, I go to the Motion Tab and then I can adjust the Scale, which is cool. But then I'm left with the Distort section to adjust position (and aspect if need be). In the Distort section there are 8 numeric fields of info to figure out and fill out just to get one clip in a different position correctly.
    I'm thinking there must be another way to adjust the location (or aspect) of a video clip without spending a bit of time on exact coordinates, I want to eye-ball where I want the clip to go and simply move it there. Is the Distort feature the only way to do this? If not, which is the fastest way to move and change the dimension of a clip.
    Thanks for reading, I hope there is another way, I'm not use to these calculations and they're slowing me down.
    Monty

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    That's because it's not a simple question at all and yet every one of those threads was related to the OP's question. As you discovered, there are lots of ways to interpret "resize," during capture, editing, effects, output, viewing, encoding, printing. But the solution was even simpler than you thought. All you had to do was open the manual or the online help system. Start taking the manuals to the gym with you. FCP is not Premiere. You're going to hate FCP, you're going to love FCP but it will never behave like Premiere beyond the elements of the functional paradigm. Forget Premiere.
    bogiesan

  • 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/

  • Hopefully an easy question about arrays

    hi there
    is there any way of creating an array of objects that is of unspecified size at the time of creating and then add objects as and when they are read from a file?
    longer explanation:
    i am creating molecule visualization software. the molecule's structure is stored in a text file, ie each line has info on one atom ie 3d coords etc. i'm storing the molecule structure in an object (Molecule.java) which has an array (Structure[]) of atoms (Atom.java). obviously molecules can have any number of atoms in it and you don't know how many until you've gone through the whole file and counted. The only way i can think of doing it is to go through the whole file, coun the atoms, close the file, create the Molecule object with the structure array size of NoOfAtoms and then open the file again and add the atoms as i go through them again. however, i refuse to believe this is the most efficient way of doing it as i have to go throguh the same file twice which brings me back to my original question.
    as i said i'm hopeing there is a simple answer
    cheers

    Use a Collection . Use a Vector, ArrayList or even a Hashtable. You do not need to define the size of these objects and can add and remove Objects from them whenever you want

  • Very easy question about variables

    Can I convert float-variable to String-variable?

    Hi, a very easy way to convert almost anything is
    called "typecasting". It might sound difficult, but
    it isn't.
    You use it like this example
    > String outcome;
    Double input;
    input = 3.54789654587;
    Output = ""+input;
    That's not casting. It's implicit formatting.
    What it does is making an empty string and pasting
    your number behind it. VERY easy! You can do this
    with allmost every type of variables.What it's doing is creating a StringBuffer, appending an empty string to it, then appending the result of calling toString on the Double, which is itself a String. (Though things change a bit in jdk1.5.) It works because StringBuffer.append has versions for each primitive type, and toString exists for all Objects.
    One problem is that it's not efficient -- you're doing a lot of work behind the scenes to do something that can be done much more simply. But the bigger problem is that it's using operators in a roundabout way and with implicit results. So it's sort of a hack. "+" is the append operator for Strings (well it actually comes down to an implicit method call, or several). Putting the double on the right side of that also causes an implicit format. So you're implicitly formatting a value, and then appending it to nothing, to get a result. You're not actually meaning to append, you're meaning to format, but you're using an append operator.
    The more straightforward way to do it is simply to explicitly format it, using the methods already shown on this thread, or using java.text.DecimalFormat.

  • 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.

  • Quick (hopefully easy) question about rotating video...

    I'm going to be shooting some video soon that I will later be editing with FCP. I'm going to shoot the video on a Canon Vixia HF10 (AVCHD) camcorder.
    In the situation I'll be shooting, with the mount I'll be using, it would be much easier for me to shoot this video with the camera fully upside-down.
    If I shoot the video fully upside down, can I easily rotate it 180 degrees in FCP with no loss of quality?
    Thanks!

    An interesting thing about video that is shot upside down is the ballistics of the camera movement can be weirdly disconcerting. For instance, if it's a helmet- or wing-style mount, pans and tilts just feel odd.
    As Eric suggests, flipping the image 180 degrees is easy but practice and evaluate.
    bogiesan

  • Quick Easy Question About N580GTX-M2D15D5 Bios

    Hey guys!!
    I just have a real quick and easy (i suppose) question!
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly since the bios date and version remained the same?
    Thanks !

    Quote
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    Quote
    version 70.10.17.00.01
    that's suppose to be, this is the version of the both bioses
    Quote
    & date November 09, 2010
    this is GPU release date, not BIOS date
    Quote
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly
    Get this: https://forum-en.msi.com/index.php?action=dlattach;topic=147603.0;attach=7931
    extract it somewhere, then run info1 , and look for the last line
    Quote
    since the bios date and version remained the same?
    they are not the same, your looking the wrong stuffs

Maybe you are looking for

  • How to Move Music Library from one external HD to another

    I had about 60GB of music on an external hard drive, nicely organized and "linked to" from iTunes (just upgraded to version 5). I recently purchased a larger external hard drive and basically copied the contents of my older external drive to the new

  • Best Drum program for logic???

    HI need help..which is the better drum program.for a non drummer..Idrum..ezdrummer..or bfd?...what i intend on using it for is for making my own beats..i need to know if these r loop sampled software or can i make my own beats...thank u..any and all

  • How to I fix a phone that fell into water?

    My phone fell into water is there any hope of saving it?? Suggestions are also welcome.

  • Exporting podcast results in a 40k file and 0:00 length

    Hi all, I've been using GB for two years now. I upgraded to GB '08 the day it came out and put out two podcasts with no problems with it so far. Today, I'm editing the third podcast I created with GB '08 and I get a 40k file with a length of 0:00 if

  • Delete temporary tables

    Hi all, we are working with an Oracle Schema as staging area. Basically, what we want is to store all the intermediate transformation in temporary tables (stored in this Oracle staging area). These temporary tables are used as source datastores in ot