Narrow scope vs. efficiency

narrow scope:
for (cond) {
  byte[] buf = new byte[const];
  in.read(buf);
  out.write(buf);
vs. efficiency:
byte[] buf = new byte[const];
for (cond) {
  in.read(buf);
  out.write(buf);
}What do you prefere? Do you use a profiler to make the decision?

But what about if buf is used throughout the procedure
(locally). It should then be declared at the class
scope for efficiency. You'll not be able to link the
buf to the method by "{}".In the choise between class or method scope I probably would declare buf in the method scope. At least if the method isn't called very often. You'll have to use common sense. On one hand you want an as narrow scope as possible but on the other hand a narrow scope cannot motivate the creation of zillions of objects in an innermost loop.

Similar Messages

  • An issue of efficiency and performance

    Suppose I'm concerned about effeciency and performance. Let's compare two snippets of code.
    Code Snippet 1:
    for(int i=0; i<10000; i++) {
      String s = "str";
    }Code Snippet 2:
    String s;
    for(int i=0; i<10000; i++) {
    s = "str";
    }My question are:
    (1) Would Snippet 1 be more memory-consuming than Snippet 2, since new String object is repeatedly created?
    (2) Would Snippet 1 be slower than Snippet 2?
    (3) Would the runtime environment automatically optimize the code, so that developer need not worry about it?
    Thanks!

    My question are:
    (1) Would Snippet 1 be more memory-consuming than
    Snippet 2, since new String object is repeatedly
    created?The same amount of "str" String objects are created in both cases. The difference is where the String reference variable s is declared.
    (2) Would Snippet 1 be slower than Snippet 2?No. In a high level language when you declare a variable (like String s) you only control its type and its scope. By placing a variable you're NOT telling the compiler where and when to actually allocate memory.
    (3) Would the runtime environment automatically
    optimize the code, so that developer need not worry
    about it?You decide type and scope of the variable, the rest is up to the compiler. There's a general rule though: Declare a variable as close to where it's used as possible (the narrow scope rule). This actually may help the compiler to optimize the code. So snippet 1 is preferable.

  • Pascal's Triangle Problem

    Hey there guys. I was looking around the forums seeing if there was anything that someone posted simliar to my assignment. While there were SOME similar things, I think mines a bit more specific. Let me just state here that I don't want anyone to just come out and do the assignment for me, nor do I think that anyone would be willing to. Anyways, here's what I am dealing with.
    I am to design a method which uses recursion to print the n-th line of the Pascal's triangle. I have a few ideas in my head about how to make it, but I just can't translate my thoughts into words.
    My first guess is that my method declaration should look something like this:
    public int println(int n)
    }But I'm just at a brainlock. My class really hasn't touched recursion extremely in-depthly expect for what was needed for AP Exam and Binary Search methods. Usually I can figure this stuff out, but ahhh!
    Anyways, any help (aka nudge in the right direction) would be very appreciated.

    A recursive function can be explained as a function defined in terms of itself.
    It is a mathematical concept. Let's take a look at something simple, like fibonacci numbers. Fibonacci numbers are defined in math something like:f(1) = 1
    f(2) = 1
    f(n) = f(n-1) + f(n-2)What this means is that the first two fib numbers are 1 and 1, and every fib number after that is the sum of the two numbers immediately preceeding it. So if we unroll the fibonacci numbers, they are:1 1 2 3 5 8 13 21 34 ...Now we want to implement a method in Java that accepts a single int argument, n, and will return the nth fibonacci number. One way is to do this recursively as such:public int fibonacci(int n) {
        if (n == 1 || n == 2)
            return 1;
        return fibonacci(n - 1) + fibonacci(n - 2);
    }(what we haven't handled is when n < 1, but since this is just to increase understanding of recursion I will omit that)
    What you see is a commonality with all recursive functions, a base case and a recursion step. All recursive methods must have a base case or they will run infinately. Similarly all recursive methods must have a recursion step, for the simple reason that they would not be recursive functions otherwise. Another thing that all recursive functions have in common is that the recursive call is made on some narrower scope (in this case n less 1 and n less 2) resulting in a call drawing ever closer to the base case (not doing so would also result in infinite recursive calls).
    Note: sometimes fibonacci numbers are defined to have the 0th number as 0 and the 1st number as 1, for me that is matter of taste and still results in the same sequence of numbers, with an added 0 at the front.
    In your example, the base case is when n == 1, and the recursion step is the call to fillN with n less 1 (i.e., narrowing the scope). The thing that is different in your example is that the resulting array is being passed around in the recursive calls, this is quite common for accumulating results as the recursion is being wound up (the calls themselves) and even down (when calls return, like in your case).
    You should try tracing out the calls on paper with a reasonably small n, this will better help your understanding. Let me do it with n == 2.fillN(2, a) // a = [0, 0]
    // n is not 1 so we do the recursive call
    fillN(1, a) // a = [0, 0]
    // n is 1 so we do the base case
    array[0] = 1 // a = [1, 0]
    // returning back to the call with n == 2
    // we run through the loop (i begins at n - 1 or 1)
    array[1] += array[0] // a = [1, 1]
    // i becomes 0 which is not > 0 so we exit the loop
    // the recursion has ended and a is now [1, 1]Now you try it with n == 3.
    ps. slightly off-topic, there is a great article by Olivier Danvy and Mayer Goldberg called "There and back again" on the programming pattern of traversing one data structure as recursive calls are being made and traversing a different data structure as the calls are returning (hence, there and back again or TABA). If you're interested you should check it out (Note: they use Scheme in their examples, but that doesn't mean that there's nothing to learn from it if you don't know Scheme):
    http://www.brics.dk/RS/05/3/BRICS-RS-05-3.pdf
    Message was edited by:
    dwg

  • Network Security IIS 7.5 FTP & Managed Firewall

    Hello
    The scenario is that we have an IIS 7.5 Windows 2008 R2 box ("IIS Box"), and on that box we want to configure a single FTP site.
    The FTP site will use the Basic Security option (no Anonymous access)
    The IIS Box sits behind a wholly-independent managed firewall appliance from a leading vendor. We trust the managed firewall and its configuration, and as such, Windows Firewall is completely disabled on the IIS Box. The managed firewall is configured to
    NAT 1-1 from private to public IP addresses.
    Ideally, I would have liked to have configured a policy on the managed firewall to allow all traffic through based on a specific source IP address, since the FTP clients to access the FTP site are well-known to us and we are not giving access to very many
    clients. Unfortunately this is not an option because the clients who are requesting access do not have static IP addresses.
    We also believe that establishing a Site-to-Site VPN and running the FTP within that, is not an option.
    What we are considering having to do, therefore, is to configure the managed firewall to allow FTP protocol through, regardless of the source IP address associated with the connection. i.e. Everyone can establish the connection, and we rely upon the Basic
    FTP security mechanism built in to IIS to protect us.
    I do not think this is ideal but it should be only a short term arrangement and we will ensure that the Physical Directory that can be accessed through the service leaves a reasonably narrow scope in terms of potential attack / abuse
    The question I have before I proceed with this, concerns the need for Passive FTP Data Channel ports.
    Clearly, to make this work, I will have to specify within the IIS settings, which ports to use. Let's say for example that I go for ports 10000-11000.
    Q1. My understanding is that I need to configure the managed firewall to permit INBOUND connections to the IIS box targeting ports 10000-11000, 20, and 21. Is that right?
    Q2. If I do, I then have a situation where my firewall is going to allow all connections through on those ports, and since this firewall is NOT application-aware, it won't care whether they are being used for FTP or anything else. It will simply let ALL
    connections through. At this point, what are the ramifications in terms of how IIS will respond? For example, is IIS FTP smart enough to realise that it should only permit connections that it has already arranged over the Control link (20/21)?
    Q3. If I specify in IIS admin that I want to use 10000-11000 for FTP - is IIS clever enough to PREVENT those ports being used by any other apps on the same IIS box? My concern here is, given that the managed firewall will definitely be letting ANYTHING through,
    what potentially happens if some other app or code starts listening on port 10500?
    I understand that whatever dynamic port range is configured on the server would generally be used for Outbound connections any way (source ports) but Still - I just would like any thoughts on the security ramifications of the configuration I am proposing.
    I don't feel Entirely comfortable yet, that I am not opening up an point of vulnerability.
    I am really looking for technical thoughts on the networking side of this, rather than (for example) general advice about "make sure you have Windows Updates installed" etc.
    thanks

    Hi Robert,
    I suggest you use the passive operational mode to achieve your goal.
    In which mode, the client initiates the data channel connection, then the server responds with the TCP port number to which the client should connect to establish the data channel. We can
    restrict the port range used by the FTP service, and then create a firewall rule that allows FTP traffic on only those allowed port numbers.
    How to Configure Windows Firewall for a Passive Mode FTP Server
    http://technet.microsoft.com/en-us/library/dd421710(v=WS.10).aspx
    Best Regards,
    Amy

  • Incompatible data types in combination

    Hi All,
    i am getting this error incompatible data types in combination when i run my interface. my interface extract data from table and loads into file.it was running fine but dun know why its giving this error now during insert rows step.

    You're essentially trying assign a void value to a double... that's what the error is telling you.
    public static void showKilometers(double m)
    double kilos;
    kilos = m * 0.001;
    JOptionPane.showMessageDialog(null,(m) + " Meters is " +
    (kilos) + " Kilometers.");
    } The reason this doesn't work is because in order to assign the value of a function to a variable, the function must actually return a value.
    Try this:
    public static double showKilometers(double m)
    double kilos;
    kilos = m * 0.001;
    JOptionPane.showMessageDialog(null,(m) + " Meters is " +
    (kilos) + " Kilometers.");
    return kilos;
    } Do the same thing for your other conversions and make sure the function and return types are correct.
    Edit: Ah, looking back over the program, you weren't actually trying to assign variables; rather, you were just wanting to display them. My bad, I only looked at the narrow scope of the error and wondered why you wanted message dialogs. =)
    But, hopefully my description of that error will help you understand a few things.
    Edited by: Thok on Oct 10, 2007 2:40 PM

  • Previous/Next View functionality is missing

    I do not see option to go back to the previous view in iPod version like in PC version. It is very inconvenient to jump to hiperlink and have no ability to return back. I found out that this question was already asked in http://forums.adobe.com/message/4060734#4060734 on Dec 2, 2011. But yet there is no any feedback on this.

    It is long overdue to implement this feature in the software.
    Mobile enviroment put particular emphasis on being able to navigate conveniently within the real estate of the screen of mobile device and within a narrow scope of commands.
    It is a pain to click a hyperlink to jump withion a document and then manually scroll back or remember a particular page number where you jumped from.\
    Ir can be implemented as gesture.
    -Sergey-

  • Maxium Payload Size...where to find its meaning?

    What does Maxium Payload Size mean in the graphics Bios?
    Right now it is set to 4096 and wich are the differences among other settings???
    Pad

    Pad,
    I thought that the Whatis.com information complete enough, but I have had a little experience with Serial Data Transitions Protocols.
    However, when you looking for information on computer functions, you will find the data is 9 out 10 times in two forms.  One is so general in nature that it only gives you small piece of what need to know or if it goes in detail, then it is so narrow scope that you spend hours boiling down all the detailed information and again it only gives you small piece of what need to know.  However, over time, you learn to put all of the little pieces of information together, and then you know the subject.
    I do not know if this will help will help, but I will try to explain what I learned to day from the Whatis.com.  As far, a PCI-E data transmitions are concerned in regards to Maximum Payload Size.
    PCI-Express data transmitions are serial data transmitions, it is just that the controller, which is transmitting the data, has multiple serial routes to send the data to the device that is to receive the data.  Therefore, to send the data faster the controller breaks the data down into packages of data and sends the packets of data all at the time using its multiple routes.
    This is where “Maximum Payload Size” comes in the controller as it divides the data by the number of routes it has to send the data on.  If the block of data the controller has to transmit is large each packet send by each route would be long and if the were no limit on the size of the packet the controller can send.  Then larger data blocks could tie up transmition of data to the device for long periods.  This is fine if there is only one program that needs to communicate with the device, but if and other program need to send a block of data to the device that is more important then its data would not get sent in a timely manor and say its was time dependant the system breaks down and the system crashes.
    Therefore, your Maximum Payload size tell controller if the block of data being transmited must be broken a into groups of packets to be sent and before it sends each group of packets.  The controller must check and see if the is another block of data with higher priority that need to be sent.  If there is the controller switches to sending the higher priority block of data’s groups of packets and is checking priority of data blocks waiting repeated repeatedly until all blocks of data are sent with the data packet groups with highest priority being send first.  Then, it is the poor device controller’s job to receive those packets, place them back into individual blocks of data and for the device to use and act upon.
    If still confused, Pad just say, so and I will try again.
    Roger
    When submitting a problem, include a complete list of your system components; include part numbers, all Power Supply Voltages, and their output ratings.  It is almost impossible to estimate what your problem is without knowing something about it. 

  • Pass parameter to success method of ExecuteQueryAsync

    I have seen how to pass a parameter to a callback method of the ExecuteQueryAsync SP.ClientContext object.  The problem occurs when multiple calls are performed.  The last value is always passed to the callback method.  Below is a sample
    of a while loop that performs multiple updates.  cT contains the value i wish to pass.  TitleVal in the success method always contains the last value. 
    Thanks in advance.
    While...{ cT = currentItem.get_item('Title'); ListItem.set_item("Approval_x0020_Status", currentItem.get_item('Approval_x0020_Status'));
    ListItem.set_item("Year", currentItem.get_item('Year'));
    ListItem.set_item("Delete_x0020_this_x0020_Risk_x00", currentItem.get_item('Delete_x0020_this_x0020_Risk_x00'));
    ListItem.update();
    var SPContextUPD = new SP.ClientContext.get_current();
    SPContextUPD.executeQueryAsync(
    Function.createDelegate(this, function() {
    CreateListItem_Success("'" + cT + "'");
    Function.createDelegate(this, function() {
    CreateListItem_Fail();
    function CreateListItem_Success(TitleVal){
    SP.UI.Notify.addNotification(TitleVal + ' updated successfully');

    also define cT variable inside loop body by adding "var" so it will have narrower scope:
    var cT = currentItem.get_item('Title');
    If it is global it may store the last updated ct value which explains why you always see the same value.
    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

  • Im puling my hair out! compiler error message

    can any one please give me an insight into why my program is giving me the following message
    myTry3.java [24:1] variable output might not have been initialized
    JOptionPane.showMessageDialog(null,output,"Information",JOptionPane.INFORMATION_MESSAGE);
    i cant understand this as i have set up the variable as a string at the start of the program. some guidance would be well appreciated here if possible please. thanks.

    Then maybe you need to assign something sensible to output, won't you?
    After all, you were the one who was insisting that it was initialized properly just a while ago. That turned out to be incorrect, didn't it?
    Peeking at my javadocs, I don't see a four-argument ctor for JOptionPane that takes an int as the fourth argument.
    My next idea is to suggest that you remove that first 'null' from the argument list and assign a sensible output message to 'output':
    output = "Something informative";
    JOptionPane.showMessageDialog(output,"Information",JOptionPane.INFORMATION_MESSAGE);Why don't you declare the output String closer to the JOptionPane? Narrow scope is a good thing.
    Other advice? Stop tearing at your hair every time you get a Java error. You'll be bald soon. Read the javadocs more often. Stop assuming that everything you do is correct and that the machine is persecuting you. Doubt yourself more. - MOD

  • Why do I get this Out of memory, how can I prevent it?

    Hello
    I have an annoying problem that never has occured before....
    I use JSP with Beans, I know that the problem lies in my method "setIntotable()"
    because its just that method that is called in current JSP-page when I get this Out of Memory error.
    All information regarding matches+players are stored in a mysql-database
    When I'm about to summerize everything and create a new "table" with fresh data+ranking I get this Out of memory error. I havent made any changes so I think its strange that I suddenly get this error. Below is my syntax:
    ......................syntax for method "setIntotable()".........................................
    public void setIntotable(){
    int noOfRows;
    String fnamn1 = "";
    String enamn1 = "";
    String fnamn2 = "";
    String enamn2 = "";
    Vector matcher = new Vector();
    matcher = readTider();
    Vector players = getPlayers();
    Player player1 = new Player();
    Player player2 = new Player();
    try {
    Connection con2 = DriverManager.getConnection(fileURL, "", "");
    Statement u = con2.createStatement();
    String s = "TRUNCATE TABLE totaltiddiv";
    u.execute(s);
    u.close();
    con2.close();
    int q = 1;
    Connection con = DriverManager.getConnection(fileURL, "", "");
    Statement updateStatement = con.createStatement();
    for (int i = 0; i < matcher.size(); i++) { //matcher  has a 200<size
    Totaltid t = (Totaltid) matcher.elementAt(i); //Se below which parameters Totaltiddiv has
    String query1 = "INSERT INTO totaltiddiv VALUES('" + t.tidnr + "','" +
    t.tidnrinv + "','" + q + "','" + t.bana + "','" + t.tid + "','" +
    t.datum + "','" + Integer.toString(Integer.parseInt(t.division)) +
    "','" + t.matchindex + "','" + Integer.parseInt(t.division) + "','" +
    0 + "','" + "','','" + "','" + "','','" + "','" + "','" + "div" +
    Integer.toString(Integer.parseInt(t.division)) + "rank" +
    t.matchindex.substring(0, 1) + "','" + "div" +
    Integer.toString(Integer.parseInt(t.division)) + "rank" +
    t.matchindex.substring(1, 2) + "','" + "','" + "','" + "','" +
    "','" + "','" + "','" + "','" + "','" + "','" + "','" + "')";
    noOfRows = updateStatement.executeUpdate(query1);
    q++;
    updateStatement.close();
    Statement selectStatement = con.createStatement();
    for (int i = 0; i < matcher.size(); i++) {
    Totaltid t = (Totaltid) matcher.elementAt(i);
    String query2 = "SELECT * FROM playerdiv WHERE totalkey='" + t.p1key +
    ResultSet rs2 = selectStatement.executeQuery(query2);
    while (rs2.next()) {
    fnamn1 = rs2.getString("fnamn");
    enamn1 = rs2.getString("enamn");
    rs2.close();
    String query3 = "SELECT * FROM playerdiv WHERE totalkey='" + t.p2key +
    ResultSet rs3 = selectStatement.executeQuery(query3);
    while (rs3.next()) {
    fnamn2 = rs3.getString("fnamn");
    enamn2 = rs3.getString("enamn");
    rs3.close();
    selectStatement.close();
    String update = "UPDATE totaltiddiv SET p1fnamn='" + fnamn1 +
    "', p1enamn='" + enamn1 + "', p2fnamn='" + fnamn2 + "', p2enamn='" +
    enamn2 + "' WHERE p1key='" + t.p1key + "' AND p2key='" + t.p2key +
    System.out.println(update);
    noOfRows = updateStatement.executeUpdate(update);
    updateStatement.close();
    con.close();
    catch (SQLException sqe) {
    System.out.println(sqe);
    ------------------------------Tottaltiddiv-----------------------------------------------
    public String tidnr;
    public String tidnrinv;
    public String idnr;
    public int bana;
    public String tid;
    public String datum;
    public String division;
    public String matchindex;
    public int tiddiv;
    public boolean ledig;
    public int rank;
    public String p1fnamn;
    public String p1enamn;
    public String p2fnamn;
    public String p2enamn;
    public String p1key;
    public String p2key;
    public int set11;
    public int set12;
    public int set21;
    public int set22;
    public int tie1;
    public int tie2;
    public boolean wo1;
    public boolean wo2;
    public boolean spelad;
    public String wonevenloss;
    public int diff;
    Every parameter above is in range of 1-50 charachters
    I cant see what should bee "eating" all the memory?
    Would be very glad if anyone could help me.....
    Thanks in advance /D_S

    That's some ugly procedural code you've written there. What is this, VB?
    Well-decomposed code would say write short methods that each do one thing well.
    If I were you, I'd decompose this method into several and test each one individually.
    One advantage of this will be narrower scope. The garbage collector will have a chance to clean up some of your mess that way.
    I don't know what all those declared variables at the bottom are about. Are those class members or something? Why are they all public?
    Please don't tell me this is scriptlet code in a JSP...
    %

  • Help with streaming result sets and prepared statements

    hi all
    I create a callable statement that is capable of streaming.
    statement = myConn2.prepareCall("{call graphProc(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}",java.sql.ResultSet.TYPE_FORWARD_ONLY,
    java.sql.ResultSet.CONCUR_READ_ONLY);
    statementOne.setFetchSize(Integer.MIN_VALUE);
    the class that contains the query is instantiated 6 times the first class streams the results beautifully and then when the second
    rs = DatabaseConnect.statementOne.executeQuery();
    is executed I get the following error
    java.sql.SQLException: Can not use streaming results with multiple result statements
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1370)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1688)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3031)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:943)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1049)
    at com.mysql.jdbc.CallableStatement.executeQuery(CallableStatement.java:589)
    the 6 instances are not threaded and the result set is closed before the next query executes is there a solution to this problem it would be greatly appreciated
    thanks a lot
    Brian

    Database resources should have the narrowed scope
    possible. I don't think it's a good idea to use a
    ResultSet in a UI to generate a graph. Load the data
    into an object or data structure inside the method
    that's doing the query and close the ResultSet in a
    finally block. Use the data structure to generate
    the graph.
    It's an example of MVC and layering.
    Ok that is my bad for not elaborating on the finer points sorry, the results are not directly streamed into the graphs from the result set. and are processed in another object and then plotted from there.
    with regards to your statement in the beginning I would like to ask if you think it at least a viable option to create six connections. with that said would you be able to give estimated users using the six connections under full usage.
    just a few thoughts that I want to
    bounce off you if you don't mind. Closing the
    statement would defeat the object of of having a
    callable statement How so? I don't agree with that.
    %again I apologise I assumed that since callable statements inherit from prepared statements that they would have the pre compiled sql statement functionality of prepared statements,well If you consider in the example I'm about to give maybe you will see my point at least with regards to this.
    The statement that I create uses a connection and is created statically at the start of the program, every time I make a call the same statement and thus connection is used, creating a new connection each time takes up time and resources. and as you know every second counts
    thanks for your thoughts
    Brian.

  • ODS vs DWH vs DM

    hi guru
    whats diff between ODS vs DWH vs DM?
    anand

    hi anand
    DSO
    - Acts as source to populate DW and marts
    - Often used for operational reporting
    - Detailed, atomic data
    - Huge data volumes
    - Integrated, clean data
    - Cross-functional and cross-departmental
    - Supports data mining
    - May use denormalized form modeling (NOT dimensional)
    DWH
    - Provides mgmt reporting
    - Summarized data
    - Tuned to optimize query performance
    - Multiple departments or processes
    - May act as staging area for data marts
    - Uses dimensional data modeling
    DMart
    - Specific application or workgroup focus
    - Narrow scope
    - Customized or stand alone analysis
    - Interactive query
    - Highly summarized
    - Single subject and department oriented
    - Uses dimensional data modeling
    jeeva

  • Persisting a properties object across the whole of my program.

    Hello all,
    As per usual, sorry for any idiocy on my part and thanks for any guidance.
    I have written a wrapper class for the Properties class.
    I have an MDI which creates a properties object and loads it at start up, and I have tried to use the same object again (to save any property changes) when the app terminates. However, I get a nullPointerException when I try and use it when the program closes. Below is what I hope are the relevant pieces of code. I don't include it all as it a couple of hundred lines long - but can easily do so if you think it will help. Many thanks once again:
    Here is the load properties method:
    private void yLoadProperties(){
            String workingDirectory = System.getProperty("user.dir");
            File yFile = new File(workingDirectory + "\\KTProperties.ini");
            YPorperties yProperties = new YPorperties(yFile);
            yProperties.yLoadProperties();
            // Retrieve application name - no conversion required
            yApplicationName = yProperties.yGetProperty("ApplicationName");
    }and here is the exit program method with the call the the save properties method
    private void yExitApplication(){
            // Save properties back to disk
            yProperties.ySaveProperties();
            // Exit
            System.exit(0);
        }I have also declared the yProperties variable thus:
    private YPorperties yProperties;
    I was hoping to use the yProperties object anywhere within my program to adjust properties as required. Any help, gratefully received.
    Steve

    That's just the way Java works. I'm sure someone is able to quote chapter and verse of the Java Language Specification that spells it out, but the basic distinction is this:
    A variable declaration has the form: <Type> <variableName> [= <value expression>];.
    A variable assignment (which assigns a value to an existing variable) has the form: <variableName> = <value expression>;
    When you specify the type of a variable, Java assumes you are declaring a new variable in the current scope, regardless of whether the name of the variable already existing in a enveloping scope. When you don't specify the type, Java will look for an existing variable with that name in the current scope and any enveloping scopes.
    In my mind, when I explicitly declared yProperties, thus:> private YPorperties yProperties;> I was making it available to the whole program.With that line you declared a member variable of type YPorperties (shouldn't that be YProperties, by the way?), which means a separate yProperties variable is available as a member of each instance of your class. Note that you already specify the type of the variable yProperties in that line, so there is no need to specify that type again when using the variable further on in your application.
    But yes, you are correct in saying that this variable would be available anywhere inside that one instance of your class. However, it is possible in Java to declare a variable with the same name in a different, narrower scope (as you have seen).
    Java looks for variables from the narrowest scope outward, so in this case it sees the local variable yProperties before it sees the member variable yProperties.
    (BTW for future reference, note that a class or an instance of a class is not a "program" as such. So declaring a private member variable does not make it available to your "program", it makes it available to an instance of a class. The fact that you use that class to start your application is irrelevant)

  • Man, is *this* guy gonna be mad in two months...

    Man pays $100,000 for superjumbo tickets
    http://news.yahoo.com/s/nm/20070904/odnm/superjumbo_ticket1_dc;_ylt=AiDvJbB9I65Ygr9kaS8zMISH9EA
    Doesn't he KNOW the price is going to be cheaper in a few months?
    Or maybe he just wanted to be the first guy on the plane - maybe that's why he paid so much money...
    (Oh, and by the way, I KNOW it's an auction for charity - don't bother replying to tell me)

    I did a similar thing in a grad course I took--it was text, but we had to read a pragraph about an event and interpret what was said in the paragraph--wedding, funeral, birthday, etc and answer: who, what, where, when.
    This took about a month and was done with 2 versions -- one in C and one in LISP. There weren't any structures or processes that couldn't be easily implemented in Java.
    The biggest question is not if it can be done in Java, but rather, do you have a sufficient grasp of Java ME and the state problem with sufficient understanding of associated theories needed to supply a slolution in the time provided.
    Do you need to implement a voice and text interface or will a text interface be sufficient? If you need a voice and text interface then you need to see what is available to you for voice recognition.
    Also keep this in mind: if you can define the scope of the project, don't mess up because you made the scope too big. Implement the text interface and then add voice to it as a level 2 goal, but not as a mandatory deliverable. I had a software engineering prof that told us what was needed without any scope other than what was absolutely required. He purposfully did that to see if we could manage scope and resources to meet the deadline. Out of 4 teams in the class, mine was the only one to complete the project (we maintained a very narrow scope of work and made a resonable timeline that took into account things like other classes, midterms, vactions and etc.)--we all recieved A's and the others lost 1 letter grade off of their over-all class grade for not completing a project.
    Have fun, but mostly only you can decide.

  • OverHiding in core java

    What is overhiding?

    Naishe wrote:
    not sure but I guess you are talking about overriding + hiding.
    That means narrowing scope of a method.
    It is not supported in Java. Thought, you can increase visibilityHiding has a specific meaning in Java:
    [http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.3.1]
    [http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.8]
    [http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.10.4]
    There are other relevant sections of the JLS, I'm sure

Maybe you are looking for