Passing values between methods in the same class

Hi,
How to pass internal tables or values between methods in the same class.
How to check if the internal method in another method is initial or not.
How to see if the method has already been executed.
Thanks.

Just declare the internal table as an attribute in the class - that way every method in this class has access to it.
Since any method has access to all class attributes you can easily check if the internal table is initial or not.
I am not aware of any standard functionality if a method has already been executed or not, one way would be to declare a class attribute for each method and set it once the method has been executed. That way every method in that class would know which method has already been executed or not.
Hope that helps,
Michael

Similar Messages

  • Accessing a private variable from a public method of the same class

    can anyone please tell me how to access a private variable, declared in a private method from a public method of the same class?
    here is the code, i'm trying to get the variable int[][][] grids.
    public static int[][] generateS(boolean[][] constraints)
      private static int[][][] sudokuGrids()
        int[][][] grids; // array of arrays!
        grids = new int[][][]
        {

    Are you sure that you want to have everything static here? You're possibly throwing away all the object-oriented goodness that java has to offer.
    Anyway, it seems to me that you can't get to that variable because it is buried within a method -- think scoping rules. I think that if you want to get at that variable your program design may be under the weather and may benefit from a significant refactoring in an OOP-manner.
    If you need more specific help, then ask away, but give us more information please about what you are trying to accomplish here and how you want to do this. Good luck.
    Pete
    Edited by: petes1234 on Nov 16, 2007 7:51 PM

  • How does a method extend another method in the same class ??

    hi everybody, I want to know if it is possible to have such code as:
    void foo(){
    // foo process
    void bar <<extend>> foo{
    //foo process
    //bar process
    thanks for helping me

    Since you want different names for each of your so-called "child" methods, then neither overloading nor overriding in a subclass will work as each relies on the same method names. Perhaps the following will suffice:
    public class MyClass
       //some stuff
       private myMethodThatDoesSomeStuff()
          //do some stuff that all the other methods must also do
       private methodA(int q, byte z)
          myMethodThatDoesSomeStuff();
          // continue with this method.
       private methodL(short v, float g23)
          myMethodThatDoesSomeStuff();
          // continue with this method.
    }If not, you need to do some design work.

  • Having trouble passing values between methods

    So if this isnt the right spot for this.
    Anyhow any coments on where I went wrong or need to fix will be apriciated.
    So I got two methods that return a value (getHour() and getMinute(). The values that are returned I am tring to pass into showTime. However it doesn't seem to work as all I get is zero's.
    I've done a search around on the net and Im starting to thing my intellagnce is limited.
    import java.util.Scanner;
    public class First
    static int sH, sM;
        public static void main(String args[]){
            getHour();
            getMinute();
           showTime(sH,sM);
        static int getHour(){
            Scanner input = new Scanner(System.in);
            System.out.println("Please enter the hour: ");
            int setHour = input.nextInt();
            if(setHour <= 24){
                System.out.println("You entered " +setHour+ " for the hour.");
            }else{
                System.out.println("Please enter the hour number from 0 to 24");
                getHour();
         return sH;
         static int getMinute(){
            Scanner input = new Scanner(System.in);
            System.out.println("Please enter the minutes: ");
            int setMinute = input.nextInt();
            if(setMinute <= 60){
                System.out.println("You entered " +setMinute+ " for the minutes.");
            }else{
                System.out.println("Please enter the hour number from 0 to 60");
                getMinute();
            return sM;
        private static void showTime(int sH, int sM){
              System.out.println(+sH+":"+sM);
    }

    Hi,pls compare ur coding with the one i have posted below. In your code, the variables sH and sM are still in initialised state(value =0) and its not assigned with the values returned by getHour and getMinute methods. This is why the shoTime method returned zero. Hope i helped you.
    import java.util.Scanner;
    * @author Jaison KS-IT
    public class First {
    static int sH, sM;
    public static void main(String args[])
    getHour();
    getMinute();
    showTime(sH,sM);
    static int getHour(){
    Scanner input = new Scanner(System.in);
    System.out.println("Please enter the hour: ");
    int setHour = input.nextInt();
    if(setHour <= 24){
    System.out.println("You entered " setHour " for the hour.");
    sH = setHour;
    }else{
    System.out.println("Please enter the hour number from 0 to 24");
    getHour();
    return sH;
    static int getMinute(){
    Scanner input = new Scanner(System.in);
    System.out.println("Please enter the minutes: ");
    int setMinute = input.nextInt();
    if(setMinute <= 60){
    System.out.println("You entered " setMinute " for the minutes.");
    sM = setMinute;
    }else{
    System.out.println("Please enter the hour number from 0 to 60");
    getMinute();
    return sM;
    private static void showTime(int sH, int sM){
              System.out.println(+sH+":"+sM);
    }

  • Running different set of methods on the same class via threads

    Hello all,
    I have this issue that I am trying to deal with. It looks pretty simple to me, but maybe just a mental block I guess :)
    Now the code below will give you an idea of what I am trying to achieve. I am not sure if its possible or if there is some other better way to do this. Any help will be appreciated.
    Thanks
    public class TestClass extends Thread{
         public TestClass(){
         // Assume something goes in here.
         public void abc(){
              System.out.println("In abc");
         public void xyz(){
              System.out.println("In xyz");
         public void run(){
         //What do I put here, since my call is specific.
         public static void main(String args[]){
              TestClass t1 = new TestClass();
              t1.start();// I want t1 to call only abc()
              TestClass t2 = new TestClass();
              t2.start();// I want t2 to call only xyz
    }Edited by: mikkin on Mar 12, 2009 3:00 PM

    kogose wrote:
    you can use the Reflection API to make the desired method an instance variable:Whoa, that's a pretty big case of over-engineering (or under-engineering, depending on how you look at it) and abuse of Reflection. The real problem in the original post is that Thread isn't being used properly. You almost never want to subclass Thread, for reasons like these: your runnable target should be separate from the thread. I would organize your code like this:
    public class TestClass {
       public TestClass() {
          // Assume something goes in here.
       public void abc() {
          System.out.println("In abc");
       public void xyz() {
          System.out.println("In xyz");
       public static void main(String args[]) {
          final TestClass t1 = new TestClass();
          final TestClass t2 = new TestClass();
          new Thread(new Runnable() {
             public void run() { t1.abc(); }
          }, "t1Thread").start();
          new Thread(new Runnable() {
             public void run() { t2.xyz(); }
          }, "t2Thread").start();                   
       }

  • Passing Parameter between Methods

    I have some problems because i don't really know how to pass parameter between methods in a java class.
    How can i do that? below is the code that i did.
    I want to pass in the parameter from a method called dbTest where this method will run StringTokenizer to capture the input from a text file then it will run storeData method whereby later it will then store into the database.
    How can i pass data between this two methods whereby i want to read from text file then take the value to be passed into the database to be stored?
    Thanks alot
    package com;
    import java.io.*;
    import java.util.*;
    import com.db4o.ObjectContainer;
    import com.db4o.Db4o;
    import com.db4o.ObjectSet;
      class TokenTest {
           private final static String filename = "C:\\TokenTest.yap";
           public String fname;
         public static void main (String[] args) {
              new File(filename).delete();
              ObjectContainer db=Db4o.openFile(filename);
         try {
            String fname;
            String lname;
            String city;
            String state;
             dbStore();
            storeData();
         finally {
              db.close();
         public String dbTest() {
            DataInputStream dis = null;
            String dbRecord = null;
            try {
               File f = new File("c:\\abc.txt");
               FileReader fis = new FileReader(f);
               BufferedReader bis = new BufferedReader(fis);
               // read the first record of the database
             while ( (dbRecord = bis.readLine()) != null) {
                  StringTokenizer st = new StringTokenizer(dbRecord, "|");
                  String fname = st.nextToken();
                  String lname = st.nextToken();
                  String city  = st.nextToken();
                  String state = st.nextToken();
                  System.out.println("First Name:  " + fname);
                  System.out.println("Last Name:   " + lname);
                  System.out.println("City:        " + city);
                  System.out.println("State:       " + state + "\n");
            } catch (IOException e) {
               // catch io errors from FileInputStream or readLine()
               System.out.println("Uh oh, got an IOException error: " + e.getMessage());
            } finally {
               // if the file opened okay, make sure we close it
               if (dis != null) {
                  try {
                     dis.close();
                  } catch (IOException ioe) {
                     System.out.println("IOException error trying to close the file: " +
                                        ioe.getMessage());
               } // end if
            } // end finally
            return fname;
         } // end dbTest
         public void storeData ()
              new File(filename).delete();
              ObjectContainer db = Db4o.openFile(filename);
              //Add data to the database
              TokenTest tk = new TokenTest();
              String fNme = tk.dbTest();
              db.set(tk);
        //     try {
                  //open database file - database represented by ObjectContainer
        //          File filename = new File("c:\\abc.yap");
        //          ObjectContainer object = new ObjectContainer();
        //          while ((dbRecord = bis.readLine() !=null))
        //          db.set(fname);
        //          db.set(lname);
        //          db.set(city);
            //          db.set(state);
    } // end class
         Message was edited by:
    erickh

    In a nutshell, you don't "pass" parameters. You simply call methods with whatever parameters they take. So, methods can call methods, which can call other methods, using the parameters in question. Hope that makes sense.

  • How do I call methods with the same name from different classes

    I have a user class which needs to make calls to methods with the same name but to ojects of a different type.
    My User class will create an object of type MyDAO or of type RemoteDAO.
    The RemoteDAO class is simply a wrapper class around a MyDAO object type to allow a MyDAO object to be accessed remotely. Note the interface MyInterface which MyDAO must implement cannot throw RemoteExceptions.
    Problem is I have ended up with 2 identical User classes which only differ in the type of object they make calls to, method names and functionality are identical.
    Is there any way I can get around this problem?
    Thanks ... J
    My classes are defined as followes
    interface MyInterface{
         //Does not and CANNOT declare to throw any exceptions
        public String sayHello();
    class MyDAO implements MyInterface{
       public String sayHello(){
              return ("Hello from DAO");
    interface RemoteDAO extends java.rmi.Remote{
         public String sayHello() throws java.rmi.RemoteException;
    class RemoteDAOImpl extends UnicastRemoteObject implements RemoteDAO{
         MyDAO dao = new MyDAO();
        public String sayHello() throws java.rmi.RemoteException{
              return dao.sayHello();
    class User{
       //MyDAO dao = new MyDAO();
       //OR
       RemoteDAO dao = new RemoteDAO();
       public void callDAO(){
              try{
              System.out.println( dao.sayHello() );
              catch( Exception e ){
    }

    >
    That's only a good idea if the semantics of sayHello
    as defined in MyInterface suggest that a
    RemoteException could occur. If not, then you're
    designing the interface to suit the way the
    implementing classes will be written, which smells.
    :-)But in practice you can't make a call which can be handled either remotely or locally without, at some point, dealing with the RemoteException.
    Therefore either RemoteException must be part of the interface or (an this is probably more satisfactory) you don't use the remote interface directly, but MyInterface is implemented by a wrapper class which deals with the exception.

  • How to Differntiate between two instances of the same class ????

    I don't even know if my question makes sense or not ??
    I don't have any code written for it yet.. but its the most critical task for me..
    Q ??
    say i have multiple objects running of the same class on the same box.
    sth like a CPU can have multiple ports. The port class is intantiated
    to create every new port for CPU as required.
    Now i have to differntiate multiple ports on that box and give
    accordingly its statistics back to CPU. sth like how many acces to
    ports, how much bandwidth available, how many bits.. i know how to
    calculate statistics of ports but i don't know how to differentiate
    between multiple ports ??
    Eg: Number of sessions created on oneport is 14 and other is 25. Then i
    have to give differnt statistics of these 2 ports back to CPU.
    I hope all this made some sense ???
    Thank youuuuu....reply back if u need some more details....
    Edited by: javanewbie83 on Jun 16, 2008 4:28 PM

    javanewbie83 wrote:
    I don't even know if my question makes sense or not ??
    I don't have any code written for it yet.. but its the most critical task for me..
    Q ??
    say i have multiple objects running of the same class on the same box.
    For an example: (its just a correlation to my project.. its actually not CPU and port numbers.. sorry if u misunderstand...)
    sth like a CPU can have multiple ports. The port class is intantiated
    to create every new port for CPU as required.
    Now i have to differntiate multiple ports on that box and give
    accordingly its statistics back to CPU. sth like how many acces to
    ports, how much bandwidth available, how many bits.. i know how to
    calculate statistics of ports but i don't know how to differentiate
    between multiple ports ??
    Eg: Number of sessions created on oneport is 14 and other is 25. Then i
    have to give differnt statistics of these 2 ports back to CPU.
    I hope all this made some sense ???
    Thank youuuuu....reply back if u need some more details....Simply repeating your unclear original post does not magically make it clear.

  • Use context to pass value between JPF and Java Control

    hi,
    Can we use context to pass value between JPF and Java Control? It works if i m using InitialContext in the same machine but i dun think it will works if i put Web server and application server in different machine. Anyone have an idea how to do it?
    I also want to get the method name in the onAcquire callback method. Anyone knows how to do this?
    thks
    ?:|

    Hi.
    Yoy can the next options for make this:
    1. Pass your values in http request.
    example: http://localhost/index.jsp?var1=value1&var2=value2&var3....
    2. You can use a no visible frame (of height or width 0) and keep your variables and values there using Javascript, but of this form, single you will be able to check the values in the part client, not in the server. Of this form, the values of vars are not visible from the user in the navigation bar.
    Greeting.

  • How to pass values between views in FPM - GAF

    Hi Experts ,
    i have a doubt in FPM how to pass values between views .
    For Example:  i am having 2 views -  1 ) overview , 2 ) edit  using  the GAF
    in 1st view (overview ) i have a table displaying the employee details , i will select a single employee from that table for editing .
    how to pass the selected employee details to the 2 nd view (edit ) .
    Thanks & regards
    chinnaiya P

    Hi chinnaiya pandiyan,
    Please follow below steps:
    1. To achieve this u need to create two context nodes in the component controller.
    2. Say one is EMPLOYEE_DATA and other is SELECTED_DATA.
    3. Set the Cardinality of EMPLOYEE_DATA to 0..n and SELECTED_DATA to 1..1.
    4. Add same attributes to both nodes. (probably all those fields that are required in table and/or in edit view.
    5. Map both these nodes to OVERVIEW view.
    6. Map only SELECTED_DATA node to EDIT view.
    7. Create table in OVERVIEW view based on EMPLOYEE_DATA node.
    8. Create edit form in EDIT view based on SELECTED_DATA node.
    9. While navigating from OVERVIEW view to EDIT view, read the selected element of EMPLOYEE_DATA node and copy it to an element of SELECTED_DATA node. This should be written in PROCESS_EVENT method of component controller inherited from FPM component.
    10. Now u got the selected data in SELECTED_DATA node which will be displayed in EDIT view.
    Regards,
    Vikrant

  • Passing values between event structure cases

    Hello everybody,
    I have a question concerning the event structure  - how to pass values (let's say a string / the state of a boolean control / the value of a numeric control value / an array of numeric values) between event cases ?
    There seem to be 2 situations here  :
    - when you need to pass the value of the control that triggers an event;
    - when you need to pass the value of a control which is modified in an event case.
    I have read the documentation but i still do not understand very clearly how to do this. Maybe you can point me in the right direction (maybe some threads on the forum that i have missed).
    Thank you very much !!
    (KUDOS for everyone who is interested in this )

    AndreiN2014 wrote:
    - when you need to pass the value of the control that triggers an event;
    - when you need to pass the value of a control which is modified in an event case.
    The first question isn't worded very well.  What exactly are you looking to do?  Are you looking for an event that specifically relates to that control?  If so, just drop it inside of the event and wire it.  Are you looking to trigger multiple events from the same control?  Ie, you hit the control, event1 is triggered which then triggers event2 ... ?  If so, you might consider taking a look at a different architecture.  I can think of very few cases where I'd prefer do this over something like having the button trigger a state and using the state machine architecture. 
    Others have pointed out the Shift Register.  This is the typical way to pass values between one iteration of a loop to another.  We can assume you have some sort of loop outside of the event structure to make it run a second time.  Put a shift register on this loop and the value wired into it will pass each iteration.  But, if it's just a random control, you can also just leave that outside of the event structure and wire it in as well.  This will provide the new value to the next occurrence of the event structure.
    You really need to define your problem before trying to solve it.

  • To call methods inside the same application is possible to use RMI ?

    hello,
    What I should like to know is if RMI can easily be used to implement comunication (calling methods) inside classes that are part of the one same application... This should be a restrict case to use RMI...
    The reason to do it come from the need to use the instance of a class knonwing it only as Object... This can be good to do if some code is used for general pupose in many different contexts.
    In this case you can pass to the "server class" a parameter 'o' of type Object (all the classes extend Object) of the "customer class" to get back informations if some elaboration happen inside the "server class"...
    This purpose is generally implemented with event listeners, but perhaps it could be done easily using RMI too (I dont know it...).
    Using RMI in this simple situation, don't should require anything of complicate (stub, .... mashalling parametres....) to have the reference to method of the "customer class" to call. The "server class" already recives a reference of the "customer class" how parameter of type Object, and the mame of the method too.
    I propose a simple thoeric example to explain really what I said before:
    Class Server {
        String methodName;
        Object obj;
        pubic Server( Oject o , String metName){  // constructor
            obj = o;
            methodName = metName;
            // some thing is done and, at last, the method callbakMethod() is executed
            callbakMethod();
        }// constructor
        public void callbakMethod(){ // this method have the purpose to call customerMethod()
              Class c = owner.getClass();                            
              Method m = null;
                  try {
                          m = c.getMethod("callBackMethod",null);     
                         * // (1)
                          // I think that here we could have the possibility to call
                          // the method  customerMethod() belonging to class Customer..
                          // I don't know if it possible and  ...  (and if it is possible) I am not able to do it*
        }// callbakMethod()
    }  // class Server
    Class Custmer{
        public Customer() { // constructor
              Server s = new Server (this, "customerMethod");
        } // constructor
        customerMethod() {    // I would this method is called from class Server
            // do some thing.....
        }  //customerMethod
    }  // class CustomerMy ask is: it is possible to call customerMethod() from the Server class ?...
    If the aswer is yes, I wold know the sintax to use to do it, please.
    thank you
    regards
    tonyMrsangelo

    RMI doesn't help you in the slightest here. You can just realize it all using local method invocation. All RMI does is to make that remote. If the objects aren't remote there is no point.

  • Passing values between jsp and php

    hi there, is it possible to pass values between jsp and
    php? i really need to find out the way if there is
    any. thanks in advance
    -azali-

    Yes, there are a few ways to do this.
    1) Think about using Cookies.
    2) Maybe use a Redirect passing the values in the Query string.
    3) Retain the data in a repository in the back end.
    4) Using Hidden fields within your pages.
    I am sure you can use these Idea's for a base to develop other methods on how to pass values back and forth from JSP -> PHP and vice versa.
    -Richard Burton

  • Navigate between 2 reports and pass values between 2 different columns

    Hello
    I have a question about navigating from 1 report to another while passing the value from column 1 to column 2 in the second report...
    In OBIEE 11G, I create action link on report 1, column 1 and this action link is navigate to BI Content and the destination is report 2. Now report 2 has column 2, which is an alias of column 1 from report 1, from user's point of view they are the same, but from OBIEE point of view they are different.
    My action link is able to navigate to report 2, however, the value in column 1 which I clicked to execute the navigation, does not get passed to column 2 in report 2..
    Is there a way around this issue?
    Let me know if I need to provide more clarification
    Thanks

    Thank you Anirban
    I think this is the best solution you just provided.The current post and the post at below looks same
    Navigate from report to dashboard and  pass values between different column
    is it not answered?
    Thanks :)
    Edited by: Srini VEERAVALLI on May 7, 2013 3:07 PM

  • Forms6i- how do i pass values between two forms

    Forms6i- passing values between forms
    I have two forms. FORM1 does a call_form to FORM2.
    How do i send values from FORM1 over to FORM2?
    I want the 2 values in FORM1 to be passed top FORM2 and displayed as a TEXT ITEM.
    But i don't know what is involved in passign vales between forms.

    Define Parameters in Form2, and pass parameters with the same name from Forms1 with the parameter list option of your call_form built-in.
    It is in the online help.

Maybe you are looking for

  • Get date from portal in a web dynpro?

    hi all, how get date from portal in a web dynpro??? thanks.

  • Hook_URL issue in Punchout Catalog in ECC 6.0

    Hi Gurus, Now i am working on Punchout Catalog Procurement scenario. 1)I have 2 vendors to which the Punchout needs to set up. I have completed the settings for one Vendor and it is working very fine without any issues. 2)But when i use the same for

  • How to view your newly created webservice in dynamo administrator??

    hi everyone, i newly created a webservice for getGiftlistId and i can successfully see that in my dynadmin webservice Registry . but when it comes to accessing that getGiftlistId.wsdl i could not able to find the URL fo the same. For example we have

  • Inporting JVC HD6 to Final Cut Pro???

    Hi, I just purchased a JVC HD6 camcorder and want to know the easiest/best way to import the footage into FCP. I have the first version of Studio (FCP 5?) and a MacPro that's running OS 10.4+. JVC's .MOD files have thrown me for a loop. Any and all h

  • Announcement:  WLS 6.1

    The beta program is now over. BEA WebLogic Server 6.1 is available for download from BEA's web site: http://commerce.bea.com/downloads/products.jsp Thank you for your participation in the beta program. Your input helps BEA improve their products. Lau