A question from a beginner

I'm teaching a introductory programming course in java to some folks, and explaining variable lifetimes and the need for object member variables to store values longer than just a method call.
So the example given was of a parameter being saved in a member variable
The question arose, "Why can't you just specify the member variable as the parameter?"
To which i gave the obvious reasons.
When the class was over, i thought about it some more, and except for syntactic unpleasantries, there is no reason why this couldn't be done. Given that this is a common idiom, its odd that you can't do that.
It's only not odd, because it's never been done before.
Just thought it was an interesting thought that new-person thought produced.

To paraphrase the JLS: When the method or constructor is invoked, the values of the actual argument expressions initialize newly created parameter variables, each of the declared type, before execution of the body of the method or constructor. The identifier may be used as a simple name in the body of the method or constructor to refer to the formal parameter. Taking your example:
public class Foo {
  private int input;
  public void setInput( int Foo.input ) {}
}Here you are not initializing any newly created parameter variables, and you have no identifier that may be used as a simple name in the body of the method or constructor to refer to the formal parameter. This breaks another part of the language specification which states that formal parameters are referred to only using simple names, never by using qualified names. You might also get into issues with the float-extended-exponent value set and the double-extended-exponent value set.
Alternatively, you may just be suggesting that the compiler perform qualified name erasure to transform:
public class Foo {
  private int input;
  public void setInput( int Foo.input ) {}
}to:
public class Foo {
  private int input;
  public void setInput( int input ) {
    this.input = input;
}If this is the case, isn't syntactic sugar supposed to makes things "sweeter" to use? IMHO, this syntax isn't.

Similar Messages

  • Basic Perl questions from Perl beginner now using Leopard

    Question: I used to dabble in Perl programming (beginner!!) and want to continue my dabbling with my new iMac running Leopard.
    Which Perl do I need to install?
    Where do I get it from?
    What tricks / concerns are there in the installation?
    What's the best source of information (books?, internet?) for learning about using/programming Perl on Leopard?
    Any other advice that you believe would be helpful would be appreciated.
    Many thanks!! D

    I used to use MacPerl as well, it's even better now that Perl is pre-installed and native.
    The two thing that took me the most time to figure out are:
    Line endings. All my old scripts had carriage return - line feed as end of line delimiters.
    On linux they have to be line feed '\x0A'. You do that by setting it in your text editor. I use BBEdit or Text Mate to write perl, although I'm pretty sure that using TextEdit will work, and will have line feed line endings.
    Setting the script's executable bit. A script file needs to have a bit set in the linux filesystem to tell linux it's executable. You do that by opening the terminal and typing chmod +x then drag your script file into the terminal and pressing return.
    That's detailed here:
    http://www.oreilly.com/pub/a/mac/2003/11/07/scripting_osx.html
    Also there are 2 main ways to run your script.
    One is by opening Terminal and +typing perl+ then dragging your script into the terminal window and hitting return. if you want to do it this way the very first line in your perl script needs to look like this:
    #!/usr/bin/perl
    The other way (which is only slightly easier) is by dragging your script into the terminal window and hitting enter, no typing perl every time. To do this the very first line of your perl script needs to be:
    #!/usr/bin/env perl
    Another huge tip is if you are in the Terminal window hitting command-up arrow will show you the last command you typed in, so you can hit enter and re-run it.
    Other than that stuff I can't remember any differences between regular linux perl and Leopard perl. I still refer to the Camel book I bought 15 or so years ago.
    So type into a text editor:
    #!/usr/bin/perl
    use strict;
    use warnings;
    print "Hello World\n";
    Then save the file as Hello.pl
    open terminal and type *chmod +x*
    drag Hello.pl into the terminal and press return
    Type perl into the Terminal
    drag Hello.pl into the terminal and press return.
    and it should print.

  • Question from a beginner

    Hi, all, I'm new to JSP and JavaBeans. Now I have to develop a web site with these technology.
    My first question is:
    Can I just put all database access(query, update, delete...) into JavaBean and create a bean for every table I have. Is this a good idea or I'd better follow the MVC model? Am I able to call a method in such a bean to access database?
    I've tried it, but I got a "NoSuchMethodError".
    Thank you so much.

    Using beans is a pretty good way to display database content in your jsp - it's certainly better than having all your code in JSP scriptlets (ie. between <% ... %> tags). The idea is to have as little actual java code in your jsps (separate presentation from business logic).
    The ultimate goal is an MVC architecture. Struts (http://jakarta.apache.org) is a framework which helps you to set this up and takes a lot of the pain out of setting up your own.
    HOWEVER ... I'd say that if you're just starting out with java and jsp then an MVC framework might confuse the hell out of you and your colleagues. If your app is not too complex then you might prefer to start off simply using beans in your pages until you get up to speed with all the other jsp issues. It's virtually impossible to get your jsp webapp architecture perfect the first time round, so perhaps set your sights on a simple model.

  • Question from a beginner, really need help

    I am starting to do a little programming these days. The question is about the (program file) format to provide to the end users.
    I can use "javac" "java" to compile or run my code in a command prompt window, or use some development tool. But I do not expect the users of my program to install the jdk (or other software) in order to run the program. How to deal with this?
    What is the usual last format of a Java Program?
    Hope I have made my question clear.
    Thanks
    Xiaohua

    It depends, a good solution is to pack it into a jar file and make it executable, but if you are new to Java (I have no idea how experianced you are) it might give you more trouble than it's worth in the beginning.
    You could distribute your .class file (the .java files are only source and can not be executed) and a .bat file which would contain the command to launch the applicaiton. That's how I would do it as a newbie.
    Check out an installer program like Inno Setup ( http://www.jrsoftware.org/isinfo.php ) if you want a neat way to distribute your files. You can specify a .bat file as being the one executed when the applicaiton is started, that way your program could be run from a start menu entry (sorry, I'm assuming that you are using Windows here, to maintain cross-platform abilities this won't work)
    Does this give you an idea? There are many ways to distribute an application. You should also read up on Java Webstart...

  • Few questions from a beginner

    hi there , i have a few questions first thing
    is it possible to make every connector that comes out of a specific shape the same color , im building a map where 1 shape gives of multiple connections, i want them all to be in the same color, and the connections coming from the second shape are all in
    a different color from the first shape
    second question: how can i select all the connectors that pass in a particular area
    i selected in the option select shapes partially in area, but it selects connectors that are NOT in the area that i selected
    thank you very much for your help

    There is no out of the box way for the first question but you can write a macro to do that. 
    Shape properties Shape.Connects and Shape.FromConnects can be used for selecting all
    outgoing connectors of a shape programmatically. And then appropriate formatting (colors) can be applied on selection by selection.

  • A few questions from a beginner

    Please don't hit me because of my questions...
    1. Is there a build in method (class or whatever) to increase an array size? I don't want to copy the array each time into a larger array and then setting the pointer of the new larger array to be the same as the old smaller array. I mean a method like Array.increase(param) or something like that.
    2. Is there a way to find out how many dimension an array has? A build in method like .length
    3. Can I convert a array into a vector? If yes, how?
    4. The Math.round() method accepts only one parameter which contains the double number to be rounded. But it does't have a second parameter by which I can tell the method to round a number to the second (third or whatever) number after the dot. Is there a method like that somewhere else or do I need to program it for myself?

    ::smack::
    there, now that's out of the way..
    1) No.. arrays are static in length, which is set upon instantiation. If you need a datatype to store multiple objects that will need to increase in size, you should use Vector.
    2) I believe I'm right in saying that there's not really a way to check that. A multidimensional array is basically an array of arrays. I guess you could know that if you got myarray[0] and did a check to find out what datatype it was, you'd know that if the index contained an array, it'd be 2D ... then you could check that array, etc. However, since you are declaring the array, and when passing the array, you'd have to specify what it was (ie public void foo(int[][][] my3dIntArray) ) you should never not know the dimensions.
    3) Yes. But you'll have to loop through your array and add items to the Vector.
    4) You're right, it doesn't. Now that you mention it though, I can't think of a method that does that.... but it shouldn't be too hard for you to work out your won.

  • Very simple question from a beginner

    I am currently doing a little exercise, but I ran into a problem. I have written a class that supports operations on rational number. The fields are two long variables, one each that stores the numerator and denominator.
    I have made add, subtract, multiply, and divide methods...
    1. what I need help in is: beingh able to store the rational number in reduced for, with the denominator always positive
    2. constructing a toString method, equals method, and compareTo method.
    3. it also says "make sure the toString method correctly handles the case in which the denominator is zero by throwing an exception.
    I have been working on this for a long time now, an I am stuck at this point.
    I know this will be very simple for you guys and gals, but I am a beginner. Please offer some input, advice, and/or some code to help me get past this problem.
    Thanks so much,
    Jason

    ok, here is what I have so far
    public class Rational {
         public long num, den;
         public Rational(long n,long d) {
              this.num = n;
              this.den = d;
         public static void main(String args[]) {
              Rational r = new Rational(1,2);
              Rational s = new Rational(3,4);
              Rational rmuls = r.multiply(s);
              Rational rdivs = r.divide(s);
              Rational radds = r.add(s);
              Rational rsubs = r.subtract(s);
              r.print();
              s.print();
              rmuls.print();
              rdivs.print();
              radds.print();
              rsubs.print();
         public void print(){
              System.out.println(this.num+ "/" +this.den);
         public Rational multiply(Rational t){
              long n;
              long d;
              n = this.num*t.num;
              d = this.den*t.den;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational divide(Rational t){
              long n;
              long d;
              n = this.num*t.den;
              d = this.den*t.num;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational add(Rational t){
              long n;
              long d;
              n = (t.den*this.num)+(t.num*this.den);
              d = t.den*this.den;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational subtract(Rational t){
              long n;
              long d;
              n = (t.den*this.num)-(t.num*this.den);
              d = t.den*this.den;          
              Rational answer = new Rational(n,d);
              return answer;
         //public int compareTo (Rational t)??????

  • Oracle Triggers  - A few questions from a beginner to oracle.

    Hi,
    1. If we cannot COMMIT within a trigger, then how is it possible to use TRIGGERS to INSERT rows into an audit table that will track any INSERT/UPDATE attempt on a table. I have to record even failed attempts.
    2. Is it possible to make API calls from within a TRIGGER? (This API will write out data from the table being INSERTED/UPDATED into corresponding tables in a MYSQL database (somewhat like replication))
    3. If 2 is not possible, we are planning to write updates to an intermediate table that will be checked by a webservice every few minutes and in turn update the MYSQL db.
    Please help/advise.
    Thx.
    Vis.

    1. use autonomous transactions.
    2. if the API a PL/SQL code, yes you can call PL/SQL from
    the trigger body.
    To connect Oracle and MySQL, following thread might help:
    Re: Oracle to MySQL database connectivity
    Message was edited by:
    Pierre Forstmann

  • Compression Question from a beginner

    I'm trying to export my first video. I'm a little lost when it comes to all the compression options. Basically I have a 2min video with sound that I want to upload to youtube, but its fairly important that the sound quality isn't diminished too badly. I'm guessing that I want to export to an AVI or MPEG4, but again, I'm new to this. Can anyone make any recommendations? Much appreciated.

    This is for Compressor, but the principles are the same for exporting from FCE.
    http://www.kenstone.net/fcphomepage/youtube_compressorgary.html

  • Questions from a beginner

    does Jdeveloper have a servelet containers?
    i have to choose bettween eclipse and Jdevelopper which one shall i choose and why?
    i have to call "api" written with "c" to a java application ,are there a solution?
    thank u

    As already stated, Jdeveloper comes with an embedded version of the OC4J J2EE container, which supports JSP's, Servlets, EJBs, etc...
    Our organisation is currently migrating away from a combination of WSAD 5.1, which is an Eclipse based IDE, and MyEclipse, and standardizing on JDeveloper 10.1.3 - the feedback in almost all areas has been extremely positive.
    The only area where Eclipse seems superior is in its interfaces to CVS. JDeveloper works OK in this area but can be clunky with accessing repositories on WAN connections.
    Also, if you plan on using Maven2 - its not really documented anywhere, but a workable plugin was available as part of the original ADF Faces release to Apache. I can't find it right now, but it would be great if Oracle would officially release it or contribute it to the Apache Maven group <hint/>

  • Basic question from a beginner

    I am looking for a solution to this problem: I wish to record some classical piano for an audition DVD. I have a video camera, but the dynamic range and fidelity of the microphone are not very good. I'd like to simply strip out the audio and replace it with input from a good microphone. (I have a good microphone and USB input for it.) The audio/video syncing has to be seamless. In the past I've recorded audio using GarageBand, and I've used iMovie from camera input (A&V) for separate projects. I hear the problem is that GarageBand samples at 44 kHz (and cannot be adjusted) while video is normally recorded a 48 kHz. What do I need in terms of software to do this job? Would you recommend FC Express, strip out the audio, and find some audio recording software that can sample at 48 kHz? Any recommendations? An economical solution would be nice. I appreciate the help in getting me started.
    Message was edited by: joelmg

    Does your camera allow use of an external mic? That would be the simplest solution.
    If you need to record the audio separately, you can use the QuickTime Player to convert the sample rate to match that of your Final Cut Sequence, though lots of folks have used 44.1kHz audio successfully in FCE. (I think you need QT Pro in order to have the sample rate conversion capability.)
    As you begin recording, include a clap or some big sound to aid you in synching the two audio sources. Once you get everything recorded, I'd bring the video into your Timeline with the camera's audio, then import the external audio, synch up the audio sources, then unlink the camera audio from the video and delete that audio.

  • A simple question from a beginner

    how do i check for a null reference? eg:
    String val = null;
    // do some stuff with a hashtable...
    // now want to check if val is still null
    if (val.equals(null)) // this is where i get a NullPointer Exception
    System.out.print ("val is still null!");
    thanx in advance

    if (val == null) ...

  • A beginner question from a beginner in JDBC

    Hi,
    I am trying to execute a query on the database and I have a really strange problem:
    When i execute the query, the system answers me "invalid column name?". I try to male query to find the name of all the column and the answer is good (all the column exist).
    The qu

    Did you check the spellings of column names?
    -XL

  • Questions from a beg.  CF,HTML,  Renaming folder/path and adding main page.

    Questions from a beg. CF,HTML, Renaming folder/path and
    adding main page.
    Hello I have inherited this new job and I am trying to
    understand it asap. I am a complete beginner to html,CF and web
    development overall
    Yes I grabbed some books, but if you can help me. I really
    appreciate is.
    I have this file structure
    Z:\ToExport\RepDocs\MyReport
    Pointing to it
    http://myserver/Myreport/
    Here you find a MyReport folder
    And find 2 .cfm
    1. Index
    2. version.cfm
    I have 2 BIG questions, ok 3
    HOW DO YOU MAKE A PAGE THAT WILL CONTAIN
    The link of this MyReport.
    A main page. In other words.
    Main page that has a text Main report
    For name of the division_
    Then a link called My reports. And Your report
    Prefereably sorted
    · My reports.
    · Your report
    HOW DO I CHANGE THE FOLDER
    FROM
    Z:\ToExport\RepDocs\MyReport
    Pointing to it
    http://myserver/Myreport/
    TO
    Z:\NewExport\repmining\myreport
    Then point to it
    http://myserver/ repmining\myreport
    WHY IS THE REPDOCS NOT TYPED IN THE BROWSER WHEN VIEWING THE
    MYREPORT.( i dont have to type (repdocs)to view the report?)
    in other words:
    Z:\ToExport\RepDocs\MyReport
    Is typed
    http://myserver/Myreport/
    without repdocs.
    Please excuse me.
    I am a real beginner.
    Thanks .
    Hope someone replies soon.
    Take care.

    OK, I think I understand your questions, so here goes:
    quote:
    HOW DO YOU MAKE A PAGE THAT WILL CONTAIN
    The link of this MyReport.
    Simply have a link on a page, ex:
    <a href ="LINK URL">LINK TEXT</a>,
    As for your question on your reports, I do not understand
    what you are asking
    quote:
    HOW DO I CHANGE THE FOLDER
    FROM
    Z:\ToExport\RepDocs\MyReport
    Pointing to it
    http://myserver/Myreport/
    TO
    Z:\NewExport\repmining\myreport
    Then point to it
    http://myserver/ repmining\myreport
    If you are directly connected to the server, just create a
    folder in (from what it looks like) Z:\ToExport\RepDocs\ that is
    the new folwer name, ex:
    Z:\ToExport\RepDocs\NEW_folder and put files into it. If you
    are now directly connected to the server, use a program like FTP
    server to connect via FTP and do the same.
    quote:
    WHY IS THE REPDOCS NOT TYPED IN THE BROWSER WHEN VIEWING THE
    MYREPORT.( i dont have to type (repdocs)to view the report?)
    in other words:
    Z:\ToExport\RepDocs\MyReport
    Is typed
    http://myserver/Myreport/
    this is simply because
    http://myserver/Myreport/ is
    set to point at the folder Z:\ToExport\RepDocs\MyReport therefore
    it looks like
    http://myserver is set to the folder
    Z:\ToExport\RepDocs\ anything you add into a folder after that will
    be included.
    I hop eI answered some of your questions

  • Why can't I post a question from my new system?

    Hello All:
    I was just trying to post a question from my new mbp but it wouldn't allow me to do anything.  It continually gave me a message highlighted in 'red' that i was;t allowed to modify or post anything.  I've been asking questions for quite a while and have never seen this.  I also happen to have my older bmp, also logged onto the 'Apple Discussions' site, open beside me.  Can anyone explain this to me please?  BTW, my new system obviously has Yosemite on it while my older bmp has Lion.  Thanks in advance, to all those who respond.
    Regards,
    Ciaochiao

    ChitlinsCC, I'm adding your reloaders to my article on how to make using ASC easier.
    Here is my ASC work flow...
    1) I login.
    2) Block the automatic 30 minute logout.
         Unless you do something every thirty minutes you get logged out.  The forum software waits to tell you this as long as it can to keep you in suspense  ;-) . Filling out a reply is the exception to the thirty minute window.
            Start an auto reloader.
    Safari = SafariTabReloader
    Firefox = ReloadEvery: "Reload web pages automatically"
    Others = Reloaders | Cerberus - Support Center
      You need to pick a page that will reload over time without stalling out. It's ASC.  I've found my profile display the best to use. I get my Profile page after some  logins.  It's ASC.  Change rccharles to your apple id.
    https://discussions.apple.com/people/rccharles?view=discussions
    Reply technique
    Open a new browser window.  Pick some discussion.  Open a reply window.  As long as this reply window is open, you will stay logged in.  The 30 minute times is reset as needed by the ASC software.
    3) I open another window to do my normal ASC browsing.
    4) I have a FireFox bookmark to goto the discussions that I have participated in. I've modified it to add on the content stuff.
             turingtest2 recommends. Change rccharles to your apple id:  
    https://discussions.apple.com/people/rccharles/content?filterID=participated~obj ecttype~objecttype%5Bthread%5D
    5) Use turingtest2's generated links with the /content suffix as browser bookmark to the ASC discussions: 
    Site map of Communities and Categories
    https://discussions.apple.com/docs/DOC-2463
    6) Adjust the ASC web page layout.
    For FireFox
    I run with Hiroto's modification to user content.  This is the only way these forums are readable for me.  How to adjust the format and layout of ASC Web Pages:
    https://discussions.apple.com/docs/DOC-7501
    For Safari
    "ASCPowerTools is a Safari Extension designed to give more control"
    http://www.etresoft.com/ascpowertools
    7) Read and answer my old posts.  I kind of memorize the time I last posted. ( It's way bad that apple eliminated the last poster to a thread. )
    8) I use tabbed browsering.  From a list of discussions, hold down the command key then click on the link. You get two tabs this way. The original window will keep where you have been.

Maybe you are looking for

  • Error message on Adobe reader download

    Can't download Adobe reader (although my system says I already have it).  Error message - The ordinal 701 could not be located in the dynamic link library iertutil.dll.  How can I fix this?

  • HT201301 How do I "Select All" in a Pages document? I would like to copy and past more than one paragraph at a time.

    How do I "Select All" in a Pages document. I would like to copy and paste more than one paragraph at a time.

  • Issue regarding Automatic payment program

    Hi, I have created a payment proposal and while running payment program, progarm is strucked with Payment Run has been realesed 10.07.08 09:30:44.  Please some one can help me why this is message is comming and how to fix it and carry out my payment

  • Php classes in dreamweaver?

    hi, is it possible to use php classes, includes, extends etc. in dreamweaver? i learned to program in php at school this way, but at my work (training cource) i have to use dreamwaver, including its behaviours, so other people can change my pages usi

  • Error in Tax calculation.

    Dear all, I have created a tax code in TAXINN  in  transaction FV11(Condition type JIPC)  for CST 1% . When I put this tax code in PO -  at Invoice Tab page at item level and when I click on details the calculation of  1% tax on BASB  Rs. 100/-  Come