Question about duplicate var declaration....

the ff. code will compile and run... my question is there's a duplicate var declaration
(s var as a String type)...
Big Q: "Why the compiler didnt complain about it?"
it should be "duplicate var declaration" sort of thing......
public class Bits {
     public static void main(String args[]){
              new Bits();
    public Bits(){
         f1();
    private String s; // class var declaration, var name is "s"
    private void f1(){
       // another var declaration name "s", why the compiler dont complain about this!?!
         String s=new String("Hello World!");
         f2();
    private void f2(){
    // does this var "s" refers to the class var?
         System.out.println ("s: "+s); // the output is null
}Thanks!

Big Q: "Why the compiler didnt complain about it?"
it should be "duplicate var declaration" sort of
thing......Bcos one is a local variable and the other is an instance variable. They arent duplicates.
> private String s; // class var declaration, var name is "s"
>
private void f1(){
// another var declaration name "s", why the compiler dont complain about >this!?!
     String s=new String("Hello World!"); As i said b4, this is a local variable. Within the scope of this method, this variable hides the instance var, 's' , to access which, u will have to use this.s
>
private void f2(){
// does this var "s" refers to the class var?Yes.
System.out.println ("s: "+s); // the output is null//that's bcos u havent initialized it anywhere. Local variable have to be compulsorily initialized. Instance variables are initialized to null (if they are Object references)
ram.

Similar Messages

  • Question about env. var. LANGUAGE

    Hi,
    I noticed that when I do:
    echo $LANGUAGE
    I get:
    &LANG
    This seems to mess up libtool when building Subversion 1.5.2, so I'm just wondering what &LANG means. When I manually assign en_US to LANGUAGE, libtool is happy. How can I make the LANGUAGE variable assigned to the actual value of LANG on boot up? It seems that setting the locale in rc.conf actually causes the LANG variable to change, so I'm just wondering what LANGUAGE's purpose is and why it has such a funny value.
    Thanks.

    Big Q: "Why the compiler didnt complain about it?"
    it should be "duplicate var declaration" sort of
    thing......Bcos one is a local variable and the other is an instance variable. They arent duplicates.
    > private String s; // class var declaration, var name is "s"
    >
    private void f1(){
    // another var declaration name "s", why the compiler dont complain about >this!?!
         String s=new String("Hello World!"); As i said b4, this is a local variable. Within the scope of this method, this variable hides the instance var, 's' , to access which, u will have to use this.s
    >
    private void f2(){
    // does this var "s" refers to the class var?Yes.
    System.out.println ("s: "+s); // the output is null//that's bcos u havent initialized it anywhere. Local variable have to be compulsorily initialized. Instance variables are initialized to null (if they are Object references)
    ram.

  • Question about multiple Script declarations

    I'm reading Flash Builder 4 and Flex 4 Bible.
    On page 121 it states:
    "Any particular <fx:Script> element can contain nested ActionScript or use the source property to link to an external Actionscript file, but it cannot do both at the same time. You can, however, have as many <Script> declarations in a single MXML file as you need>"
    My questions are about the last sentence.
    1)  They specifically used <fx:Script> and <Script>. Are these two different entities?
    2)  I've never seen examples of using multiple <fx:Script> declarations in a project. How would this work?
    3)  Are they promoting bad practices by making this claim?
    Thank you
    Kristin

    Although multiple script tags are allowed, I'd guess that they're not commonly used.
    Gordon Smith
    Adobe Flex SDK Team

  • Question about scope!!

    Hi ~
    I have a question about scope.
    for example
    primitive character variable ("char")
    what is principle upon which it is based?
    How can scope implemented?
    Please explain at low level in detail..
    thanks

    Scopes are related to braces (and the for+catch-statements).
    Inside a function nested scopes of the same name are forbidden {int x; {int x; ... } ...}, as misunderstanding could arise.
    You may mention a name (method name, class name, var name), before its declaration, like:
    int f() {x = 3;} int x;Implementation issues address variable locations on the stack and heap management (garbage collection), and exceptions (stack unwinding).
    If you are interested in compiler construction try the javap tool, and try out the JVM, by for instance writing a compiler to JVM byte code.
    To answer your question on variable clean-up: I'm afraid while playing compiler you need to calculate var addresses/frame sizes, and calls/stack frames are a bit confusing, but the rest is easy.

  • Vars declaration

    Hello everybody,
    I've got a couple of questions about vars declaration, mainly inside methods. The thing is I read somewhere that since inside a method vars wont get a default value, you should declare them assigning its "natural" default, just as a good practice and to guarantee they don't get garbage at the value.
    public boolean declareVars(MyObject param) {
        boolean isEmpty = false;
        MyObject o = null;
        //do stuff
        isEmpty = o.equals(param);
        return isEmpty;
    }But in some other place said, you should not declare vars at the begining since this is not C++. Declaration should be done when you need the object for the first time. What would be a better advice?
    And to make the couple, here's the second. When you need a var thats gonna be instantiated inside a loop several times, is there any diference or advantage if I write the declare statement before the loop begins instead of insede the loop?
    //Outside the loop
    MyObject mo = null;
    for (MyObject item: myObjects) {
        mo = item;
    //  do stuff using mo
    //Inside the loop
    for (MyObject item: myObjects) {
       MyObject mo = item;
    //  do stuff using mo
    Thanks in advance for your advise.

    The general guideline is that a variable should be declared in as constrained a scope as possible -- within the block where it is used, if it does not need to be accessed from outside the block.
    is there any diference or advantage if I write the declare statement before the loop begins instead of insede the loop?From the performance standpoint, no difference. Semantically, if it makes sense that the variable be scoped within the loop, then that's where it should be declared.
    db

  • Follow-up on question about copying 10.4

    I only got one reply to my question about how to copy OS 10.4 from one internal drive to another and unfortunately, the response was cut short. Something about if I had another computer with Firewire, using it and that's as far as the response went. Yes, I have a  laptop and have Firewire, but still don't know how to use it to help.

    If you just wish to make a duplicate of one hard drive to another hard drive in the same G5, then do this:
    Clone using Restore Option of Disk Utility
    Open Disk Utility from the Utilities folder.
    Select the destination volume from the left side list.
    Click on the Restore tab in the DU main window.
    Check the box labeled Erase destination.
    Select the destination volume from the left side list and drag it to the Destination entry field.
    Select the source volume from the left side list and drag it to the Source entry field.
    Double-check you got it right, then click on the Restore button.
    Destination means the second internal drive. Source means the internal startup drive.

  • Question about PNP...LDB

    Hi All,
    I have been asked a simple but strange question about PNP LDB. When we assigned logical database in our program, it will basically create a selection screen, which have certain fields. Like Today.. Some date ranges. Person assigned number, company code, company status.
    From my standpoint I know when ever we give selection to PNP screen we have to check this selection parameters in our programs, like date range ,person number, employee status etc ….RIGHT?
    Somebody ask me that without checking selection in our report I mean any parameters, it can filter the record, my Answer was BIG “NO”. You need to check all the parameters in your program.
    Next question asked by me was what the purpose of PNP. I replied that rather then declaring and doing bunch of databases SAP provide logical database so current all the records and do what ever you like to do.
    What you think guys?
    Thanks

    Here`s the question , when I am giving "1"active employee in employee status why its pulling up the information for '0' withdrawn employee?
    Message was edited by: Saquib Khan

  • Question about pictures file in home folder

    I am trying to create more space on my hard drive and have a question about the pictures file.
    In addition to the iPhoto Library I have several folders named 1, 2, 3 etc each containing a bunch of photos; plus several hundred individual photo files.
    My question is whether these files are duplicates of what is in the iPhoto Library - and is there an easy way to find that out?
    And I guess also to find out how they got there in the first place. Could these be imports from disks as opposed to my digital camera?
    Thanks for any help,
    Laura

    Hey laura,
    I haven't used iPhoto for a while but from memory i think that i work similar to iTunes. Whne files are processed by iPhoto they are catalogued on the hard drive according to the iPhoto preferences. I would check out the iPhoto preferences and see if you can see anything in here that will tell you what is going on.

  • Question about size of ints in Xcode

    Hello. I have a a few quick questions about declaring and defining variables and about their size and so forth. The book I'm reading at the moment, "Learn C on the Mac", says the following in reference to the difference between declaring and defining a variable:
    A variable declaration is any statement that specifies a variables name and type. The line *int myInt;* certainly does that. A variable definition is a declaration that causes memory to be allocated for the variable. Since the previous statement does cause memory to be allocated for myInt, it does qualify as a definition.
    I always thought a definition of a variable was a statement that assigned a value to a variable. If a basic declaration like "int myInt;" does allocate memory for the variable and therefore is a definition, can anyone give me an example of a declaration that does not allocate memory for the variable and therefore is not a definition?
    The book goes on, a page or so late, to say this:
    Since myInt was declared to be of type int, and since Xcode is currently set to use 4-byte ints, 4 bytes of memory were reserved for myInt. Since we haven't placed a value in those 4 bytes yet, they could contain any value at all. Some compilers place a value of 0 in a newly allocated variable, but others do not. The key is not to depend on a variable being preset to some specific value. If you want a variable to contain a specific value, assign the value to the variable yourself.
    First, I know that an int can be different sizes (either 4 bytes or 8 bytes, I think), but what does this depend on? I thought it depended on the compiler, but the above quote makes it sound like it depends on the IDE, Xcode. Which is it?
    Second, it said that Xcode is currently set to use 4-byte ints. Does this mean that there is a setting that the user can change to make ints a different size (like 8 bytes), or does it mean that the creators of Xcode currently have it set to use 4-byte ints?
    Third, for the part about some compilers giving a newly allocated variable a value of 0, does this apply to Xcode or any of its compilers? I assume not, but I wanted to check.
    Thanks for all the help, and have a great weekend!

    Tron55555 wrote:
    I always thought a definition of a variable was a statement that assigned a value to a variable. If a basic declaration like "int myInt;" does allocate memory for the variable and therefore is a definition, can anyone give me an example of a declaration that does not allocate memory for the variable and therefore is not a definition?
    I always like to think of a "declaration" to be something that makes no changes to the actual code, but just provides visibility so that compilation and/or linking will succeed. The "definition" allocates space.
    You can declare a function to establish it in the namespace for the compiler to find but the linker needs an actual definition somewhere to link against. With a variable, you could also declare a variable as "extern int myvar;". The actual definition "int myvar;" would be somewhere else.
    According to that book, both "extern int myvar;" and "int myvar;" are declarations, but only the latter is a definition. That is a valid way to look at it. Both statements 'delcare' something to the compiler, but on the second one 'define's some actual data.
    First, I know that an int can be different sizes (either 4 bytes or 8 bytes, I think), but what does this depend on? I thought it depended on the compiler, but the above quote makes it sound like it depends on the IDE, Xcode. Which is it?
    An "int" is supposed to be a processor's "native" size and the most efficient data type to use. A compiler may or may not be able to change that, depending on the target and the compiler. If a compiler supports that option and Xcode supports that compiler and that option, then Xcode can control it, via the compiler.
    Second, it said that Xcode is currently set to use 4-byte ints. Does this mean that there is a setting that the user can change to make ints a different size (like 8 bytes), or does it mean that the creators of Xcode currently have it set to use 4-byte ints?
    I think that "setting" is just not specifying any option to explicitly set the size. You can use "-m32" or "-m64" to control this, but I wouldn't recommend it. Let Xcode handle those low-level details.
    Third, for the part about some compilers giving a newly allocated variable a value of 0, does this apply to Xcode or any of its compilers? I assume not, but I wanted to check.
    I don't know for sure. Why would you ask? Are you thinking of including 45 lines of macro declarations 3 levels deep to initialize values based on whether or not a particular compiler/target supports automatic initialization? Xcode current supports GCC 3.3, GCC 4.0, GCC 4.2, LLVM GCC, CLang, and Intel's compiler for building PPC, i386, and x86_64 code in both debug and release, with a large number of optimization options. It doesn't matter what compiler you use or what it's behavior is - initialize your variables in C.

  • Newbie question about loading servlets on tomcat

    I have what is probably a very basic question about loading simple servlets on to tomcat to test its installation. I have followed instructions from numerous tutorials to the letter but still I can't get it to work.
    I have installed tomcat on win2k in c:\tomcat. I set up the jdk, environment vars (JAVA_HOME, CATALINA_HOME, TOMCAT_HOME) which all point at the correct dirs. I can compile a servlet without errors. I can also place a test jsp and html file into the root directory and they both work fine.
    However, now I am trying a test servlet and no matter what I do it gives me a 404. I have a servlet class file called "HelloServlet.class" which I placed into the %install_dir%\webapps\ROOT\WEB-INF\classes directory. I try to reference it using this url:
    http://localhost/servlet/HelloServlet
    Tomcat is configured to use port 80 and has been restarted after adding the servlet class file. Does anyone have a clue why this is not working for me?
    Many thanks
    Marc

    You have to add in the web.xml file that it is in the WEB-INF dir, the information about your servlet. An example:
    <web-app>
    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
    </servlet-mapping>
    </web-app>

  • Question about function with in parameters

    Hello,
    I have a question about functions with in-parameters. In the HR schema, I need to get the minimum salary of the job_id that is mentioned as an in-parameter.
    this is what I am thinking but I dont know if it's correct or not or what should I do next!
    create or replace function get_minimum_salary (i_job_id in varchar2)
    return number
    as
    begin
    SELECT min_salary INTO min_sal
    FROM jobs
    where job_id = get_minimum_salary(xy);
    RETURN i_job_id;
    end get_minimum_salary;
    thanks in advance
    EDIT
    Thanks for your help all.
    Is it possible to add that if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:
    create or replace procedure insert_error (i_error_code in number,
                                                      i_error_message in varchar2)
    as
    begin
    insert into error_table (error_user, error_date, error_code, error_message)
    values (user,sysdate,i_error_code,i_error_message);
    end insert_error;
    This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
    Any ideas of how to do that?
    Thanks again
    Edited by: Latvian83 on Jun 1, 2011 5:14 AM

    HI
    I have made little bit changes in ur code. try this
    create or replace function get_minimum_salary (i_job_id in varchar2)
    return number
    as
    v_Min_sal jobs.salary%type=0;---- Variable declaration
    begin
    SELECT min_salary INTO v_ min_sal
    FROM jobs
    where job_id = i_job_id;
    RETURN v_Min_sal;
    end get_minimum_salary;
    Regards
    Srikkanth.M

  • Question about Percent Function

    This kinda goes along with my question about the plus sign. That was answered by the fact it means there is more than can be displayed in the field with the plus sign. The problem I am having is all of the fields with the plus sign are formated to be PERCENT. These fields are filled in via the C# program. The values are calculated in the C# program and outputed to the PDF form in the form of 00.00 - 100.00. Thus if I am filling in these fields with values that are within a PERCENT range, then why are they showing a plus sign. I have even go as far as to wipe the field clean, re-do the Text box, re-format as PERCENT, with the text centered, and the No Calculation radio button set true. The only other thing I do these fields is set the FONT to 10 point or otherwise the huge in size.

    Thank you all for the help on this. What I found is:
    it is correct that the incoming value to a fillable field for a PERCENT must be between 0 and 1 BUT this is NOT the complete answer.
    If I filled the field with 33.33 then it will display  33.33 + which says the display is too big.
    If I filled the field with .3333 thin it will display .3333 without the PLUS sign, but is still not correct because the FORMAT is set to PERCENT.
    What I had to do is add the following JAVA script.
    // Custom Calculate script for text field
    (function () {
        // Get the field values
        var v1 = getField("NO_FEAR_ASSOC_WITH_TARGETED_DISABILITY_PERCENT_1").value;
        // Set this field value
        event.value = v1;
    Now if the input is .3333 the display is now 33.33% which is correct. Sense the JAVA Script is basicly a NOP, this tells me that the PERCENT format requires some kind of trigger. Sense a FILL is NOT a trigger, the display comes out incorrect.

  • Question about distinct_values for multiple fields

    Hi,
    With the distinct_values() function we can get the distinct value for a specified field, and is there any way to get the distinct value for multiple fields?
    Thanks!

    Hi simpson213,
    According to your description, you have some questions about your report design.
    1. How to have non-duplicating child info?
    In this scenario, since you don't want to hide the duplicate data, we suggest you filter the duplicated records on query level by using Distinct statement. If you want to do it on report level, you can group
    records on chid id and use First() function on other fields. 
    Reference: First Function (Report Builder and SSRS)
    2. How to  have various sections that contain fields with numerous values?
    We can also add these fileds into the child group of child and have them toggled by child id. 
    Reference: Add an Expand/Collapse Action to an Item (Report Builder and SSRS)
    3. How to add a page break between each child?
    Right click on the Row Group(child id)->Page Break->Select between each group instance.
    Reference: Add a Page Break (Report Builder and SSRS)
    4. How to select multiple child id when rendering report?
    When creating parameter, select Allow multiple values in General.
    Reference: Add, Change, or Delete a Report Parameter (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • I have three questions about managing my music library

    Hello,
    I have three questions about managing my music library, I hope you can help me with them:
    1) Is there a limit of how many entries, songs, albums, art work, can iTunes handle? I have a hunch iTunes is like a database program and am curious about its capacity. I have two 2-TB drives and am wondering what is going to happen when I fill these two drives up. Other than disk space, what are iTunes limitations?
    2) Talking about these two drives. How can I use both as a source for my iTunes library. Can I have two folders selected as the source of my library? I am not sure if I have enough disk space to hold all my music, but I do also have a 1TB almost empty drive is need be.
    3) OK now comes te real question. I am sure that I have duplicates in my library and I sure would love to clean my library up.Possiby if I do get to clean it up, I can save some disk space and that is always a good thing. Any good techniques, software, techniques to follow while ripping music to help keep my library organized. Please be as detailed as you can.
    Thanks and I can't wait to hear from you.
    Waseem

    Wassimn wrote:
    Hello,
    I have three questions about managing my music library, I hope you can help me with them:
    1) Is there a limit of how many entries, songs, albums, art work, can iTunes handle? I have a hunch iTunes is like a database program and am curious about its capacity. I have two 2-TB drives and am wondering what is going to happen when I fill these two drives up. Other than disk space, what are iTunes limitations?
    As far as I know you're going to run out of disc space before you hit any limits. Each object in iTunes has a 64-bit key to access it. That said as your library grows it will get less responsive as bigger indexes take exponentially longer to process.
    2) Talking about these two drives. How can I use both as a source for my iTunes library. Can I have two folders selected as the source of my library? I am not sure if I have enough disk space to hold all my music, but I do also have a 1TB almost empty drive is need be.
    iTunes wants to manage everything inside one big folder. Some idiosyncrasies with the way it manages things if you have to move to a new drive means it is best if you can stick to that plan. If your library grows larger then you'll have to take manual control of where some or all of your content is stored. I use a variation of a script called ConsolidateByMoving which you could adapt for your needs.
    3) OK now comes te real question. I am sure that I have duplicates in my library and I sure would love to clean my library up.Possiby if I do get to clean it up, I can save some disk space and that is always a good thing. Any good techniques, software, techniques to follow while ripping music to help keep my library organized. Please be as detailed as you can.
    When it comes to deduping I've written another script for that called DeDuper, see this thread for background.
    And for some general tips on getting organized in iTunes see Grouping tracks into albums.
    tt2

  • Question about get web service result in actionscript and convert data format

    Hi, All
    I have question about how to get dataset from web services
    and put it in tree structure. I have 2 questions about this:
    1, How can I get data correctly in actionscript?
    I have no problem to get data by
    <mx:ArrayCollection id="acFolder"
    source="{mx.utils.ArrayUtil.toArray(MyGServices.getFolder.lastResult)}"
    />
    And display in datagrid.
    But when I try to use
    public function
    handleFolderContents(event:mx.rpc.events.ResultEvent):void{
    arData=mx.utils.ArrayUtil.toArray(event.result);
    acData=new ArrayCollection(arData);
    input.text=acData.getItemAt(0).id;
    Seems I can’t get data, it always say:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference.
    2, how to convert data format
    I get data from web service and want to convert it to tree
    structure, as mention below:
    I get:
    <Array>
    <id>111</id>
    <Name>Production1</Name>
    </Array>
    <Array>
    <id>222</id>
    <Name>Production2</Name>
    </Array>
    Convert to:
    <mx:XMLList id="treeData">
    <node>
    <node label="Production1" data="111">
    <node label="Production2" data="222"/>
    </node>
    </node>
    </mx:XMLList>
    Please help me.
    Thanks.

    First, don't specify the package path in the argument
    declaration. Instead import the event object:
    import mx.rpc.events.ResultEvent;
    The docs state this emphatically.
    Second, try "lastResult", in place of "result":
    arData=mx.utils.ArrayUtil.toArray(event.lastResult); // I am
    not positive about this. I maybe recall reading that result was ok
    for the event object, but maybe not.
    Finally, why do you want to convert the xml? You certainly
    could, but it would be a manual process, recursively reading the
    existing xml nodes and building the new structure, but again, why?
    Just use a labelFunction if necessary to display the nodes as
    you wish.
    Tracy

Maybe you are looking for

  • Cannot access music store - error message 404

    ok- i guess i'm looking for an explanation more than a solution. while trying to download a song (as usual) this morning i received an error message for the first time ever. "cannot access music store. please try again later. 404" ... for 2 hours i s

  • Retrieve filename and insert in body of htm file?

    Is there a way in Dreamweaver CS4 to retrieve the filename of the current file and insert it into the body? I want to accomplish the following: retrieve: currentworkingfilename.htm replace: href="constant/filename.htm">  (this is a consistent string

  • You can't open the application Library because it may be damaged or incomplete

    I am a newby to the support communities as a questioner though I have searched and found quite a few answers to other problems.  My problem today is the above message whenever I click on an .mp4 file in my Finder.  The files are in my iTunes Library

  • Pass Cluster into LabVIEW Generated DLL using __cdecl

    I'm using a DLL generated with LabVIEW 7.1 to calculate IIR filter coefficients in a application I'm writing in C++. The DLL contains several different functions. The function prototype in question looks like this: long __cdecl ButterworthCoefficient

  • What is the name in the status bar when we activate a webdynpro??

    hi all, When we activate the webdynpro,in the status bar its displayin some name like 1BCWDY/*********==CP. I got it is the include program. The name getting displayed in status bar and the name in the table WDY_WB_SOURCEMAP differs. If i give the co