Local variable needs to be declared final

This is the error code I am getting:
C:\javacode\Notepad>javac FinalProgram.java
FinalProgram.java:60: local variable textfield1 is accessed from within inner class; needs to be declared final
System.out.println("It is detected " + pressed +
textfield1);
^
1 error
Here is my code:
comments relevant to this topic are //ALL IN CAPS
import java.awt.*; //declare packages needed
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.JMenuBar;
public class FinalProgram extends JFrame
    implements ActionListener {
static JFrame frame;
  public void actionPerformed (ActionEvent e) {
      String answer = (e.getActionCommand());
         if (answer == "Get Data") {
          JInternalFrame iFrame = new JInternalFrame("Get Data . ", false, true, false, false);
          iFrame.setLayout(new GridLayout(8,2));
          JLabel label1 = new JLabel("First Name");
          JLabel label2 = new JLabel("Last Name");
          JLabel label3 = new JLabel("Street");
          JLabel label4 = new JLabel("City");
          JLabel label5 = new JLabel("State");
          JLabel label6 = new JLabel("Zip");
          JLabel label7 = new JLabel("Phone");
          JLabel label8 = new JLabel("Click Button to Submit Form -->");
          JTextField textfield1 = new JTextField(10);
          JTextField textfield2 = new JTextField(10);
          JTextField textfield3 = new JTextField(10);
          JTextField textfield4 = new JTextField(10);
          JTextField textfield5 = new JTextField(10);
          JTextField textfield6 = new JTextField(10);
          JTextField textfield7 = new JTextField(10);
          JButton button1 = new JButton("Submit Data");
          //textfield1.addActionListener(this);
          textfield1.addActionListener(this);
          textfield2.addActionListener(this);
          textfield3.addActionListener(this);
          textfield4.addActionListener(this);
          textfield5.addActionListener(this);
          textfield6.addActionListener(this);
          textfield7.addActionListener(this);
          button1.addActionListener(new ActionListener() { //start button1.addActionListener
          public void actionPerformed(ActionEvent a) { //start button1 actionPerformed
                    String pressed = ((JButton) a.getSource()).getText();
                    System.out.println("button press is detected " + pressed + textfield1);  //THIS SYSTEM OUT PRINT IS A TEST, IT WORKS WHEN I DON'T HAVE THE "+ textfield1" PART, IT GIVES ME THE ERROR MESSAGE POSTED ABOVE ABOUT DECLARING IT FINAL.
I'M A BEGINNER, MY GOAL HERE, IN EASY ENGLISH, IS TO GRAB THE DATA FROM EACH TEXTFIELD AND STORE THEM IN VARIABLES, OR MORE IDEALLY IN AN ARRAY SO THAT THE REST OF MY CODE BELOW CAN WRITE THEM TO FILE, I'VE BEEN TRYING THE PAST FEW DAYS ON THIS EXPERIMENTING AND ANY SUGGESTIONS WOULD BE APPRECIATED
          try {
               String directoryName = "c:\\javacode\\Notepad";
               String fileName = "program.txt";
               File output = new File(directoryName,fileName);
               output.createNewFile();
          if (! output.isFile()) {
               System.out.println("File creation of" + output.getPath() + "failed");
        return;
          BufferedWriter out = new BufferedWriter(new FileWriter(output.getPath(), true));
          String[] text = {"This is the text that will be written. \r", //we pass an array, which holds the text to append to the file
                "The text will be written to the file \r",
                "in append mode. If the file does not \r",
                "exist it will be created.\r"};  //WHAT YOU SEE HERE IS JUST A TEST, IN PLACE, I WOULD LIKE TO HAVE THE INFORMATION FOR MY TEXTFIELDS SO THAT I CAN PASS THEM THROUGH A FOR LOOP AS BELOW AND WRITE DATA FOR EACH OF THE TEXTFIELDS TO MY EXTERNAL TEXT FILE
                for(int i = 0; i < text.length; i++) { //using the length of the text message we use out.Write() to write out the data.  Notice that all of the code is placed into a try-catch block so we can check for any IOExceptions that occur
       out.write(text[i] + "\n");
          //Here I create the code to grab the actions(grab the text) from the textFields and store them into variables OR into an array
          //after I have created my container to hold the information for my various textFields, then I want to create a for loop to go through each textField and write that information to a text file, separating each textField on its own line
     out.close();
     catch(IOException d) {
     System.out.println("Error writing to file " + d);
               }  //end button1.addActionListener
          }  //end button1 actionPerformed
          );     //end actionListener statement     
          //textfield1.setSize(10, 10);
          iFrame.add(label1);
          iFrame.add(textfield1);
          iFrame.add(label2);
          iFrame.add(textfield2);
          iFrame.add(label3);
          iFrame.add(textfield3);
          iFrame.add(label4);
          iFrame.add(textfield4);
          iFrame.add(label5);
          iFrame.add(textfield5);
          iFrame.add(label6);
          iFrame.add(textfield6);
          iFrame.add(label7);
          iFrame.add(textfield7);
          iFrame.add(label8);
          iFrame.add(button1);
          iFrame.setSize(200, 500);
          iFrame.setVisible(true);
          add(iFrame);
          if (answer == "Display Data") {
          JInternalFrame iFrame = new JInternalFrame("Display Data . ", false, true, false, false);
          JTextArea text = new JTextArea();
          JScrollPane scroller = new JScrollPane();
          scroller.getViewport().add(text);
          iFrame.getContentPane().add(scroller);
          iFrame.setSize(200, 150);
          iFrame.setVisible(true);
          add(iFrame);
  public FinalProgram() {
    super ("Menu Example");
    JMenuBar jmb = new JMenuBar();
    JMenu file = new JMenu("Functions");
    JMenuItem item;
    file.add(item = new JMenuItem("Get Data"));
    item.addActionListener (this);
    file.add(item = new JMenuItem("Display Data"));
    item.addActionListener (this);
    jmb.add(file);
    addWindowListener(new ExitListener());    
     setJMenuBar (jmb);
    public static void main(String[] args) {
        FinalProgram window = new FinalProgram();
        window.setTitle("Final Program");
        window.setSize(600, 600);
        window.setVisible(true);
}

hi,
Updated Code,
import java.awt.*; //declare packages needed
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.JMenuBar;
public class FinalProgram extends JFrame
    implements ActionListener {
static JFrame frame;
          JLabel label1 = new JLabel("First Name");
          JLabel label2 = new JLabel("Last Name");
          JLabel label3 = new JLabel("Street");
          JLabel label4 = new JLabel("City");
          JLabel label5 = new JLabel("State");
          JLabel label6 = new JLabel("Zip");
          JLabel label7 = new JLabel("Phone");
          JLabel label8 = new JLabel("Click Button to Submit Form -->");
          JTextField textfield1 = new JTextField(10);
          JTextField textfield2 = new JTextField(10);
          JTextField textfield3 = new JTextField(10);
          JTextField textfield4 = new JTextField(10);
          JTextField textfield5 = new JTextField(10);
          JTextField textfield6 = new JTextField(10);
          JTextField textfield7 = new JTextField(10);
          JButton button1 = new JButton("Submit Data");
  public void actionPerformed (ActionEvent e) {
      String answer = (e.getActionCommand());
         if (answer == "Get Data") {
          JInternalFrame iFrame = new JInternalFrame("Get Data . ", false, true, false, false);
          iFrame.setLayout(new GridLayout(8,2));
          //textfield1.addActionListener(this);
          textfield1.addActionListener(this);
          textfield2.addActionListener(this);
          textfield3.addActionListener(this);
          textfield4.addActionListener(this);
          textfield5.addActionListener(this);
          textfield6.addActionListener(this);
          textfield7.addActionListener(this);
          button1.addActionListener(new ActionListener() { //start button1.addActionListener
          public void actionPerformed(ActionEvent a) { //start button1 actionPerformed
                    String pressed = ((JButton) a.getSource()).getText();
                    System.out.println("button press is detected " + pressed + textfield1.getText()); 
          try {
               String directoryName = "c:\\javacode\\Notepad";
               String fileName = "program.txt";
               File output = new File(directoryName,fileName);
               output.createNewFile();
          if (! output.isFile()) {
               System.out.println("File creation of" + output.getPath() + "failed");
        return;
          BufferedWriter out = new BufferedWriter(new FileWriter(output.getPath(), true));
          String[] text = {"This is the text that will be written. \r", //we pass an array, which holds the text to append to the file
                "The text will be written to the file \r",
                "in append mode. If the file does not \r",
                "exist it will be created.\r"};  //WHAT YOU SEE HERE IS JUST A TEST, IN PLACE, I WOULD LIKE TO HAVE THE INFORMATION FOR MY TEXTFIELDS SO THAT I CAN PASS THEM THROUGH A FOR LOOP AS BELOW AND WRITE DATA FOR EACH OF THE TEXTFIELDS TO MY EXTERNAL TEXT FILE
                for(int i = 0; i < text.length; i++) { //using the length of the text message we use out.Write() to write out the data.  Notice that all of the code is placed into a try-catch block so we can check for any IOExceptions that occur
       out.write(text[i] + "\n");
          //Here I create the code to grab the actions(grab the text) from the textFields and store them into variables OR into an array
          //after I have created my container to hold the information for my various textFields, then I want to create a for loop to go through each textField and write that information to a text file, separating each textField on its own line
     out.close();
     catch(IOException d) {
     System.out.println("Error writing to file " + d);
               }  //end button1.addActionListener
          }  //end button1 actionPerformed
          );     //end actionListener statement     
          //textfield1.setSize(10, 10);
          iFrame.add(label1);
          iFrame.add(textfield1);
          iFrame.add(label2);
          iFrame.add(textfield2);
          iFrame.add(label3);
          iFrame.add(textfield3);
          iFrame.add(label4);
          iFrame.add(textfield4);
          iFrame.add(label5);
          iFrame.add(textfield5);
          iFrame.add(label6);
          iFrame.add(textfield6);
          iFrame.add(label7);
          iFrame.add(textfield7);
          iFrame.add(label8);
          iFrame.add(button1);
          iFrame.setSize(200, 500);
          iFrame.setVisible(true);
          add(iFrame);
          if (answer == "Display Data") {
          JInternalFrame iFrame = new JInternalFrame("Display Data . ", false, true, false, false);
          JTextArea text = new JTextArea();
          JScrollPane scroller = new JScrollPane();
          scroller.getViewport().add(text);
          iFrame.getContentPane().add(scroller);
          iFrame.setSize(200, 150);
          iFrame.setVisible(true);
          add(iFrame);
  public FinalProgram() {
    super ("Menu Example");
    JMenuBar jmb = new JMenuBar();
    JMenu file = new JMenu("Functions");
    JMenuItem item;
    file.add(item = new JMenuItem("Get Data"));
    item.addActionListener (this);
    file.add(item = new JMenuItem("Display Data"));
    item.addActionListener (this);
    jmb.add(file);
    addWindowListener(new ExitListener());    
     setJMenuBar (jmb);
    public static void main(String[] args) {
        FinalProgram window = new FinalProgram();
        window.setTitle("Final Program");
        window.setSize(600, 600);
        window.setVisible(true);
class ExitListener extends WindowAdapter {
  public void windowClosing(WindowEvent event) {
    System.exit(0);
}

Similar Messages

  • Re: A problem with local variables, need help.

    I don't actually get any error with the code when
    compiling,I know. You get it when running. The error is that it doesn't behave like you want. What I was looking for was "at such and such line, I expected this variable to have this value, but it was actually this other value."
    Your explanation did clear it up though.

    http://java.sun.com/docs/books/tutorial/java/javaOO/variables.html

  • Catch-22: need to assign a local variable within an anonymous class

    static boolean showMessage(Window parent, String button0, String button1)
        throws HeadlessException {
              final Window w = new Window(parent);
              Panel p = new Panel(new GridBagLayout());
              final Button b[] = new Button[]{new Button(button0), (button1 != null) ? new Button(button1) : (Button)null};
              boolean rval[]; //tristate: null, true, false
              w.setSize(100, 50);
              w.setVisible(true);
              //add b[0
              gbc.fill = GridBagConstraints.HORIZONTAL;
              gbc.gridx = 0;
              gbc.gridy = 3;
              p.add(b[0], gbc);
              //add b[1]
              if (button1 != null) {
                   gbc.fill = GridBagConstraints.HORIZONTAL;
                   gbc.gridx = 1;
                   gbc.gridy = 3;
                   p.add(b[1], gbc);
              w.add(p);
              w.pack();
            w.setVisible(true);
            //actionListener for button 0
              b[0].addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             if (e.getSource() == b[0]) {
                                  w.setVisible(false);
                                  rval = new boolean[1];
                                  rval[0] = true;
              //actionListener for button 1
              if (button1 != null) {
                   b[1].addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent e) {
                                  if (e.getSource() == b[1]) {
                                       w.setVisible(false);
                                       rval = new boolean[1];
                                       rval[0] = false;
            while (true) {
                 try {
                      if (rval[0] == true || rval[0] == false) //should trigger NullPointerException
                           return rval[0];
                 } catch (NullPointerException e) { }
         }catch-22 is at
    rval = new boolean[1];
    rval = false;javac whines: "local variable rval is accessed from within inner class; needs to be declared final"
    How do I assign to rval if it's declared final?
    Or at the very least, how do I get rid of this error (by all means, hack fixes are okay; this is not C/C++, I don't have to use sanity checks)?
    I'm trying to make a messagebox in java without using JOptionPane and I'm trying to encapsulate it in one method.
    And I'm far too lazy to make a JNI wrapper for GTK.

    dcminter wrote:
    How do I assign to rval if it's declared final?You don't and you can't. You're not allowed to assign to the local variable of the outer class for extremely good reasons, so forget about trying.
    Or at the very least, how do I get rid of this errorIf you don't want the side effect, then just use an inner class variable or a local variable.
    If you want the side effect then use a named class and provide it with a getter and setter.
    Finally, in this specific case because you're using an array object reference, you could probably just initialise the array object in the outer class. I.e.
    // Outer class
    final boolean[] rval = new boolean[1];
    // Anonymous Inner class
    rval[0] = true; // No need to intialize the array.
    I declared it as an array so that it would be a tristate boolean (null, true, false) such that accessing it before initialization from the actionPerformed would trigger a NullPointerException.
    Flowchart:
    is button pressed? <-> no
    |
    V
    Yes->set and return
    Is there a way to accomplish this without creating a tribool class?

  • Inaccessible with local variable(non-final) via method local inner class

    Hi All,
    Usually local variables, including automatic final variable live on the stack and objects & instanace variables live on the heap.The contracts for using the method local inner class should allow merely method final variable, not non-final stack variable.
    Can anyone please clarify me ,behind the scene what is actual fact why method inner class should not access the stack(method) variable and only allow final variable?
    Is anything correlated with the stack and heap aspects?
    Thanks,
    Stalin.G

    [email protected] wrote:
    ...behind the scene what is actual fact why method inner class should not access the stack(method) variable and only allow final variable?...explained by dcminter and Jardium in [an older thread|http://forums.sun.com/thread.jspa?messageID=10694240#10694240|http://forums.sun.com/thread.jspa?messageID=10694240#10694240]:
    ...Final variables are copied into inner classes - that's why they have to be declared final; to avoid the developer making an incorrect assumption that the local variable can be modified and have the change reflected in the copy.
    When a local class uses a local variable, it doesn't actually use the variable. Instead, it takes a copy of the value which is contained in the variable at the moment the class is instantiated. It's like passing the variable to a constructor of the class, except that you do not actually declare any such constructor in your code.
    To avoid messy execution flows to be present in a Java method, the Java language authors thought it was better to allow a single value to be present in such a variable throughout all its life. Thus, the variable has to be declared final.
    ...HTH

  • Local variable can't be accessed from inner class ???????? Why ??????

    Plesae help, help, help. I have no idea what to do with this bug.........
    <code>
    for ( int i = 0; i <= 2; i++ ) {
    for ( int j = 0; j <= 2; j++ ) {
    grids[i][j] = new MyButton ();
    grids[i][j].setBorder(but);
    getContentPane().add(grids[i][j]);
    MyButton sub = grids[i][j];
    sub.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    if ( sub.getState() == 0 ) {
         sub = new MyButton( (Icon) new ImageIcon(imageFile));
         if ( imageFile.equals("cross.jpg") ) {
              sub.changeState(1);
         else {
              sub.changeState(2);
    </code>
    The compiler complains that "sub" is in the inner class, which is the ActionListener class, must be declared final. Please tell me what to do with it. I want to add an ActionListener to each MyButton Object in the array. Thanks ......

    OK, now I changed my code to this :
    for ( int i = 0; i <= 2; i++ ) {
      for ( int j = 0; j <= 2; j++ ) {
        grids[i][j] = new MyButton ();
        grids[i][j].setBorder(but);
        getContentPane().add(grids[i][j]);
        grids[i][j].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            if ( grids[i][j].getState() == 0 ) {
               grids[i][j] = new MyButton( (Icon) new ImageIcon(imageFile));
              if ( imageFile.equals("cross.jpg") ) {
               grids[i][j].changeState(1);
              else {
              grids[i][j].changeState(2);
    [/cpde]
    Thanks for your advice !!!!!!
    Now the compiler says that i and j are local variables accessed from inner classes, needs to be declared final. How can I solve this then ???

  • Can I reference a sequence object by a local variabl?

    Hi,
    I create ten sequences in database. In my form, I get a sequence number from different sequence object according to different situations.
    So can I choose one of the seuqences by refering it using a local variable ? such as :
    declare
    first_sequence varchar2(100);
    new_po number(10);
    begin
    first_sequence:='po_number';
    select first_sequence.nextval
    into new_po
    from dual;
    end;
    Thanks
    Stephen

    I cannot see this working as it will complain at compile time. The compiler will look for the envVar as an object on the DB. I believe what you need is something like DBMS_SQL or EXECUTE IMMEDIATE to do what you want.

  • Static local variable?

    Hi,
    Why a local variable can not be declared as static? What is the logic behind this static keyword?
    thks.

    Hi,
    Why a local variable can not be declared as static?
    What is the logic behind this static keyword?
    thks.In C, a static local variable is used to maintain state between function calls. In Java, the way to maintain state is with a member variable. We have no need of static local variables.
    The meaning of the static keyword is "associated with the class as a whole, rather than with any one instance."

  • How to make chart from multiple loops without local variables

    Hi,
    It is my first experience in LabView.
    I did a program that communicate with Power Supply Device via RS232, sets an output voltage and read Voltage and Current in some sort of a program: Voltage goes up, staying in some value and then goes down. So there are many FOR LOOPS that sequensed one after another.
    I need to make a 2 live Charts (one for current and second for voltage), and the only one solution that i could obtain is using local variables. BUT also I need to export my data to the file after the end of the program (with real elapsed time for collecting data points) and with the use of local variables I cannot do so. Maybe the Shift Register will work, but I could not make it work.
    Thank you for help.
    Attachments:
    test.vi ‏47 KB

    You have multiple, deeply stacked, sequential loops. Way too complicated.
    All you need is a simple state machine architecture using a single loop and a single instance of your charts. No local variables needed. Simplify!!! You could even graph both values on a single chart.
    Look at your code. It is basically repeating the same thing with slighly different inputs. You only need to change the inputs based on state, and re-use the same IO function instances. Only one instance each needed.
    (you also have some misguided autoindexing near the middle of your code. Bad!)
    LabVIEW Champion . Do more with less code and in less time .

  • How do i declare a user defined table type sproc parameter as a local variable?

    I have a procedure that uses a user defined table type.
    I am trying to redeclare the @accountList parameter into a local variable but it's not working and says that i must declare the scalar variable @accountList.this is the line that is having the issue: must declare the scalar variable @accountListSET @local_accountList = @accountListALTER PROCEDURE [dbo].[sp_DynamicNumberVisits] @accountList AS integer_list_tbltype READONLY
    ,@startDate NVARCHAR(50)
    ,@endDate NVARCHAR(50)
    AS
    BEGIN
    DECLARE @local_accountList AS integer_list_tbltype
    DECLARE @local_startDate AS NVARCHAR(50)
    DECLARE @local_endDate AS NVARCHAR(50)
    SET @local_accountList = @accountList
    SET @local_startDate = @startDate
    SET @local_endDate = @endDate
    CREATE TYPE [dbo].[integer_list_tbltype] AS TABLE(
    [n] [int] NOT NULL,
    PRIMARY KEY CLUSTERED
    [n] ASC
    )WITH (IGNORE_DUP_KEY = OFF)
    GO

    Why are you asking how to be an awful SQL programmer??  Your whole approach to SQL is wrong.
    We have a DATE data type so your insanely long NVARCHAR(50) of Chinese Unicode strings is absurd. Perhaps you can post your careful research on this? Can you post one example of a fifty character date in any language? 
    The use of the "sp_" prefix has special meaning in T-SQL dialect. Good SQL programmers do not use CREATE TYPE for anything. It is dialect and useless. It is how OO programmers fake it in SQL. 
    The design flaw of using a "tbl-" prefix on town names is called "tibbling" and we laugh at it. 
    There are no lists in RDBMS; all values are shown as scalar values. First Normal Form (1NF)? This looks like a set, which would have a name. 
    In any -- repeat any -- declarative programming language, we do not use local variables. You have done nothing right at any level. You need more help than forum kludges. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to use local variables declared in b/t the methods in other views

    Hi
    i need to use the value of the local variables declared in b/w the views in one other view,as i have manipulated the value based on some condition & want to use it in 1 more view for my req.,but that variable is not global one just for once i need to use it,and i can't again write the whole for its conditions,as its there in initialization view,which if coded again,can hit the functionality there,so is it possible to use the value of such local variables thereafter or not,if yes pls let me know,or i need to declare the global variable for this.

    hi,
    1.Declare an Attribute in Component controller.
    2. Pass the value to this Attribute in View V1.
             using :
      wd_comp_controller->Att = 'Saurav'.
    3. Now in view2 , you can access this Attribute using:
      data lv type string.
         lv = wd_comp_controller->Att .
    Here Att is my attribute of type string declared in component controller.

  • What is the need to break a VI when a local variable in read mode is unconnected?

    What's wrong with an unconnected "read" local variable?
    A control terminal (or indicator terminal for that matter) can exist on the BD without issues!
    Use case: When I create a new control, I may want to drop a few local variables in different cases of an event structure to be connected later.
    If in addition, I am planning to create a few controls, to be used in several cases, this is quicker than dealing with each case one at a time.
    I'll just grab the terminal, create a local variable for it, copy it and then paste it in all the cases I need it in.
    Then repeat with another control and finally, deal with the bunch of local variables in each case later on.
    I would like to be able to run the VI without having to treat all cases, which I can't right nowm because the VI is broken as long as there remains at least one unconnected "read" local variable.
    Again, I cannot fathom why the compiler would be unhappy with a "read" local variable unconnected to anything. Generate a copy of the data if you wish, don't use it, that's all!
    I can see the problem with a "write" local variable, although I would wish an unconnected "write" local variable would be simply ignored. And probably the same should be done with an unconnected local variable: no copy should be generated.
    Of course, a warning would be useful.

    Then put it on the IE (assuming it's not already there) and see how it fares. Personally, I think I prefer the current situation for safety (i.e don't forget to use the code you actually put in), but I wouldn't be terribly broken up if it behaved like you want.
    Try to take over the world!

  • Final attributes and local variables - performance ??

    Hi all,
    I and a colleague have done some performance testing regarding the use of final attributes and final local variables, e.g.
    with final:
    public class MyClass {
      private final int i;
      public final void myMethod() {
        final int j = 5;
        // do something with i and j
    }vs. non-final:
    public class MyClass {
      private int i;
      public final void myMethod() {
        int j = 5;
        // do something with i and j
    }I couldn't find any speed differences in a small test program, but my colleague did so in his application. Who is right ??
    Still, I will have do some formal testing next week and I will post the results.
    I'd prefer the version using final anyway because I find it better readable, but the issue I am having is whether I'll spend 2-3 days going through the program making everything final or not.

    I made some tests with final arguments to a method: I could not find any difference between final and non-final arguments. code is posted below
    import java.io.*;
    import java.net.*;
    import java.rmi.*;
    import java.util.*;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import junit.framework.*;
    import junit.extensions.*;
    public final class FinalVariablesTest extends TestCase /* from junit */ {
         * Constructors
        public FinalVariablesTest(String name) {
            super(name);
         * helper methods/classes
        protected void setUp() throws Exception {
            super.setUp();
        protected void tearDown() throws Exception {
            super.tearDown();
         * Test Suite
        public static void main(String[] args) {
         junit.textui.TestRunner.run(suite());
        public static Test suite() {
            return new TestSuite(FinalVariablesTest.class);
         * Test Cases
        /** tests the effect of passing an (final or non-final) int parameter
         to a method which uses the variable in a for loop.
         <p>
         Linux System:
         cat /proc/cpuinfo
         processor       : 0
         vendor_id       : GenuineIntel
         cpu family      : 6
         model           : 8
         model name      : Pentium III (Coppermine)
         stepping        : 1
         cpu MHz         : 501.146
         cache size      : 256 KB
         fdiv_bug        : no
         hlt_bug         : no
         sep_bug         : no
         f00f_bug        : no
         coma_bug        : no
         fpu             : yes
         fpu_exception   : yes
         cpuid level     : 2
         wp              : yes
         flags           : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr xmm
         bogomips        : 999.42
         </pre>
         <p>
         Results:
         <pre>
         java version "1.4.0"
         Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
         Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
         final     non-final
         498     500
         491     494
         491     493
         491     494
         534     494
         492     494
         491     494
         492     493
         491     494
         495     494
         4966     4944 (Totals)
         </pre>
        public final void testIntParametersToForLoop() {
         final int RUNS = 10;
         final int INNER = 1000000;
         final int OUTER = 10;
         System.out.println("-----------------------");
         System.out.println("testIntParametersToForLoop");
         for(int i=0; i<RUNS; i++) {
             outerFinalIntParametersToForLoop(INNER, OUTER);
             outerNonFinalIntParametersToForLoop(INNER, OUTER);
        private final void outerFinalIntParametersToForLoop(final int INNER,
                                       final int OUTER) {
         // with final var in for loop
         long start0 = System.currentTimeMillis();
         for(int i=0; i<OUTER; i++) {
             innerFinalIntParametersToForLoop(INNER * i);
         long end0 = System.currentTimeMillis();
         System.out.println("      final:       " +
                      ( end0 - start0 ) + " milliseconds");
        private final void outerNonFinalIntParametersToForLoop(final int INNER,
                                          final int OUTER) {
         // with non-final var in for loop
         long start1 = System.currentTimeMillis();
         for(int i=0; i<OUTER; i++) {
             innerNonFinalIntParametersToForLoop(INNER * i);
         long end1 = System.currentTimeMillis();
         System.out.println("  non final: " +
                      ( end1 - start1 ) + "       milliseconds");
        private final void innerFinalIntParametersToForLoop(final int INNER) {
         for(int i=0; i<INNER; i++) {
             int testVar = i * INNER;
        private final void innerNonFinalIntParametersToForLoop(int loops) {
         for(int i=0; i<loops; i++) {
             int testVar = i * loops;

  • I do video productions for a small local TV station. I use Final Cut Express to edit. I need a new video camera but am at a loss as to what to buy. I know I will get a digital camera but do not know the difference between just digital and digital HD.

    I do video productions for a small local TV station. I use Final Cut Express to edit. I need a new video camera but am at a loss as to what to buy. I know I will get a digital camera but do not know the difference between just digital and digital HD. Also, I can not afford an expensive camera and need some advice on which of the available cameras would be best and also work well with a Mac. One last issue, I currently use a Panasonic #CCD camera that takes a tape. When I load video to Final Cut the audio and video are out of sinc. Go figure. Can anyone help with these questions. Karen

    Hello Karen,
    If you are using Final Cut Express, then look for camcorders that are AVCHD camcorders.  Look especially for the AVCHD logo and specific mention of AVCHD in the specs.  Most of the major manufacturers produce good quality camdcorders - Canon, Sony, etc.
    Also, be aware that there are a lot of "not quite AVCHD" camcorders on the market (sometimes they say they record video as MPEG4-H.264/AVC) - buyer beware!
    Most everything you are going to find on the market today is HD, which stands for "high-def".
    Regarding your question about the Panasonic camcorder, it's best if you post that as a separate question, and please identify the specific model camcorder and the Easy Setup you are using in FCE.

  • How to declare local variables in PL/SQL stored programs

    Where do I declare local variables in a PL/SQL stored program?
    I get compiler errors with either of the options below:
    FUNCTION GET_PRINCIPAL_BALANCE (CUT_OFF_DATE IN DATE, TITLE_SN IN DATE, TOTAL_BALANCE OUT NUMBER) RETURN NUMBER IS
    TOTAL_BALANCE NUMBER;
    BEGIN
    RETURN TOTAL_BALANCE;
    END;
    FUNCTION GET_PRINCIPAL_BALANCE (CUT_OFF_DATE IN DATE, TITLE_SN IN DATE, TOTAL_BALANCE OUT NUMBER) RETURN NUMBER IS
    BEGIN
    TOTAL_BALANCE NUMBER;
    RETURN TOTAL_BALANCE;
    END;

    Your local variable cannot have the same name as the formal out parameter. This is a procedure example, but since functions should not have out parameters anyway ...
    session2> CREATE PROCEDURE p (p_id IN NUMBER, p_did OUT NUMBER) AS
      2     p_did NUMBER;
      3  BEGIN
      4     p_did := p_id * 2;
      5  END;
      6  /
    Warning: Procedure created with compilation errors.
    session2> show error
    Errors for PROCEDURE P:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    1/1      PLS-00410: duplicate fields in RECORD,TABLE or argument list are
             not permittedThe proper way to create a function would be something like:
    CREATE FUNCTION f (p_id IN NUMBER) RETURN NUMBER AS
       l_did NUMBER;
    BEGIN
      l_did := p_id * 2;
      RETURN l_did;
    END;You should really assign a value to the variable before you return it.
    John

  • Local variable for an Array of fixed size

    Hello,
    I have a two multirate loops in a VI. 
    In one loop, I want to refer an fixed sized array initialized in the other loop.
    But I coudn't name the array, so I can't refer it.
    Is there any way to refer it?
    Thanks,
    Young.

    If you need a local variable, there is no other way than to create an indicator for it.
    In LabVIEW there is no "fixed length" array : you can always add or remove an array element, and you don't need to declare it as in other languages. They are intrinsic dynamic objcets. Of course, the memory manager has to cope with this, that's why it's often better to initialize an array, to give it its final size immediately, resulting in faster running programs. However, this is only noticeable with relatively large arrays (> 10000-100000 elements).
    May be you should explain in more details what you intend to do, because trying to reproduce a C approach in LV is probably not the best thing to do. For instance, you said that you are initializing your array in a first loop. You mean that you re-initialize the array at each iteration ? I suppose no, so may be you could put the initialize step out of the loop, and wire the array to your two parallel loops.
    Remember also that local variables are not always good programming solutions, since using them will generate copies of their content each time they are refered to. And that can low down your program very significantly...
    Message Edité par chilly charly le 11-05-2005 05:05 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

Maybe you are looking for

  • 945gcm5 usb 2 does not work

    Hello I also have the same problem and did the same things that are mentioned here in another post, with no success. I laso have the latest bios update and all the drivers are up to date. It simply does not recognize USB2.0... Any sugestions?

  • No pen pressure sensitivity in CS3

    I am running both Photoshop versions CS2 and CS3 on a Macbook Pro with Leopard 10.5.6 installed. I have downloaded the latest Wacom driver for use with my Intuos2 tablet. Running CS2 the pen's pressure sensitivity is working fine. Running CS3 however

  • Adaptive RFC in webdynpro

    Hi, I developed a custom application in webdynpro and made it to work and in the mean time the sneak preview license expired. I have reinstalled the sneak preview but cannot get the application to work. I had saved the old application in my hard driv

  • Getting the error from icp report

    i am looking to take the icp report but getting below error An error has occurred. Please contact your administrator. Show Details: Error Number:70 Error Description:Permission denied Error Source:Microsoft VBScript runtime error Page On which Error

  • Incompatible control file

    I attempted to upgrade 10.2.0.1 to 11.2 but things went wrong. So, I am trying to start the source database but I get the following error: ORA-00201 control file version 11.2.0.0.0 incompatible with ORACLE version 10.2.0.1.0. Is there any way I can m