Can ne 1 answer this interesting question!!! ?

Hi,
I have the name of the method in a String format. I want this information to get evaluated as a method/function. How can I do that?
For example, I have a string named "setName" and another string "str". I want this information to get evaluated as :- setName(str), ie. string 'setName' should get interpreted as a method name 'setName( )'. 'setName(String str)' is a method in the same class.
Thanks!
-Vaibhav.

Hi...
import java.lang.reflect.*;
public class Test {
     public Test (String setName, String str) {
          try {
               Method m = this.getClass ().getMethod (setName, new Class [] {str.getClass ()});
               m.invoke (this, new Object [] {str});
          catch (Exception e) {}
     public static void main (String [] args) {
          Test t = new Test ("setName", "Rick");
          System.out.println (t.getName ());
     public void setName (String name) {
          _name = name;
     public String getName () {
          return _name;
     String _name = "Boab";
[\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Can't anyone answer this simple question?

    Guys,I want to know whether a GUI which is made using Swing can write files to disk,or ,in another way--does Swing support writing files to disk?(This is becoz applets do not support this feature)
    Thannks in advance,
    Avichal167

    One thing to note...
    Because the previous example is simple, I handled all the File IO operations in the same class as the GUI ...
    You can how ever have the File IO done in a different class and tie it in to your GUI class...
    Example... GUISample.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class GUISample extends JFrame implements ActionListener{
            private JTextArea jtxArea;
            private JButton jbtn;
            private String[] bText = {"Read","Write"};
            private boolean bState = true;
            private FileHandler handler;
         public GUISample(){
                 super("GUI Sample");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLayout(new BorderLayout());
              jtxArea = new JTextArea(15,20);
              jtxArea.setEditable(true);
              jbtn = new JButton(bText[0]);
              jbtn.addActionListener(this);
              getContentPane().add(jtxArea,BorderLayout.CENTER);
              getContentPane().add(jbtn,BorderLayout.SOUTH);
              pack();
              setVisible(true);
              handler = new FileHandler(); // instantiates FileHandler
         /* both method from FileHandler return Strings to be displayed in the JTextArea */
         public void readAndDisplay(){
              jtxArea.setText(handler.readTheFile()); // calls method from FileHandler
         public void writeToFile(){
              jtxArea.setText(handler.writeTheFile(jtxArea.getText())); // calls method from FileHandler
         public void actionPerformed(ActionEvent ae){
                if ((ae.getSource() == jbtn)&&(bState)){
                      bState = false;
                      jbtn.setText(bText[1]);
                      readAndDisplay();
                 else{
                           bState = true;
                           jbtn.setText(bText[0]);
                           writeToFile();
         public static void main(String[] args){
                 GUISample gspl = new GUISample();
    }Example... FileHandler.java
    import java.io.*;
    public class FileHandler {
    private String theData;
    public String readTheFile(){ // reads and returns data or message
             try{
                 File afile = new File("test.txt");
                     FileInputStream fis = new FileInputStream(afile);
                      try{
                           byte[] strBuff = new byte[(int)afile.length()];
                           fis.read(strBuff);
                           try{
                                theData = new String(strBuff);
                                fis.close();
                           }catch(NullPointerException npe){theData = "Null Pointer Exception";}
                       }catch (IOException ioe){theData = "IO Exception";}
               }catch (FileNotFoundException fnfe){ theData = "File Not Found";}
         return theData;
         public String writeTheFile(String data){ // writes and returns a message
             try{
                 File afile = new File("test.txt");
                     FileOutputStream fos = new FileOutputStream(afile);
                   try{
                           try{
                           fos.write(data.getBytes());
                           fos.close();
                           theData = "File Saved";
                    }catch(NullPointerException npe){theData = "Null Pointer Exception";}
                       }catch (IOException ioe){theData = "IO Exception";}
               }catch (FileNotFoundException fnfe){theData = "File Not Found";}
               return theData;
    }and of course you can use the same Test.txt file...
    As you can see from this example, I have one class create and handle the GUI and the second class handles all the File IO operations...
    So to better answer your first question, Swing and AWT and Applets can be used to create GUIs... and as far as File IO, all three can have code or be couples with a class that does File IO operations...
    The only restriction is with Applets where by default the SecurityMananger does not allow File IO operations...
    Notice the word "default", this means Applets are capable of doing File IO, if you do some extra coding and policy work... ( my terminology may be off on this)
    But as stated earlier, I am not well versed enough in Applets to give you assistance in creating a Signed Applet that can... soon I will, just not at this time...
    - MaxxDmg...
    - ' He who never sleeps... '

  • What  are the advantages over sql in pl/sql...can you please answer this?

    Hi,
    what are the main differences between sql and pl/sql...why v are using pl/sql rather then sql...can you please answer this question?

    SQL is used to access the database. PL/SQL is a programming language where SQL is seamlessly integrated. In order to access the database in PL/SQL, you have to use SQL.
    Think of it as two pieces of software, two "engines". If you want to interact with the database, then performance wise it's best to use only one engine (SQL only), instead of two (PL/SQL and SQL). If a PL/SQL program executes a SQL statement, it does a "context switch", i.e. saving its state in PL/SQL before giving control to the SQL engine and vice versa. This is quite fast, but do a lot of them and it is slow, so beware of programming SQL statements inside loops.
    Another way to put it: SQL is a fourth generation language (4GL) where you tell what you want, not how. The software, the optimizer, will decide for you how to process the statement. PL/SQL is a third generation language (3GL), or at least the PL-part is, where you describe how things should be processed. Leading to more code and more control. With every Oracle release, SQL becomes more powerful and the optimizer gets better, so using SQL is increasingly important.
    For complex processing, using PL/SQL is still necessary. But use it with care.
    Hope this helps.
    Regards,
    Rob.

  • Hello! my problem at jump of paid games I can't remember answers to confidential questions. you can cancel or step by step describe what to do? thanks

    hello! my problem at jump of paid games I can't remember answers to confidential questions. you can cancel or step by
    step describe what to do? thanks

    The Best Alternatives for Security Questions and Rescue Mail
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for
            support and service.
        c. Rescue email address and how to reset Apple ID security questions

  • Can't remember answers to security questions.How do I reset the security questions?

    Can't remember answers to security questions.How do I reset the security questions?

    1)  Apple ID: All about Apple ID security questions
    If necessary...
    2)  See Here... ask to speak with the Account Security Team...
    Apple ID: Contacting Apple for help with Apple ID account security
    3)  Or Email Here  >  Apple  Support  iTunes Store  Contact

  • I forgot to answer account security, so how can I find answers or change questions and new answers

    I forgot to answer account security, so how can I find answers or change questions and new answers
    Can you help me ,please???

    From a Kappy  post
    The Three Best Alternatives for Security Questions and Rescue Mail
       1. Use Apple's Express Lane.
    Go to https://expresslane.apple.com ; click 'See all products and services' at the
    bottom of the page. In the next page click 'More Products and Services, then
    'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Forgotten Apple
    ID security questions' and click 'Continue'. Please be patient waiting for the return
    phone call. It will come in time depending on how heavily the servers are being hit.
    2.  Call Apple Support in your country: Customer Service: Contact Apple support.
    3.  Rescue email address and how to reset Apple ID security questions.
    A substitute for using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

  • I can't remember answers from security questions... Please help me....apple support don't answer.(((

    I can't remember answers from security questions... Please help me....apple support don't answer.(((

    1. See my User Tip for some help: Some Solutions for Resetting
        Forgotten Security Questions: Apple Support Communities.
    2. Here are two different but direct methods:
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for
            support and service.
    3. For other queries about Apple ID see Frequently asked questions about Apple ID.
    4. Rescue email address and how to reset Apple ID security questions
    5. For online assistance use Apple - Support - Express Lane

  • Can any body answer this-Want to set the cursor position in textfield.

    i want my cusor position in textfield at the initial position which will come by default.
    but when i'm using the textfields in an inner class i'm getting the cursor position at the end of the text in text filed.pls can any body answer this.
    thanks in advance.
    if want run this example.
    import java.awt.*;
    import java.awt.event.*;
    class Testing extends JFrame implements ActionListener
         Container cnt;
         JButton jd;
         JTextField jt1;
         JTextField jt2;
         Testing()
              cnt = getContentPane();
              cnt.setLayout(new FlowLayout());
              jd = new JButton("OK");
              //jd.setBounds(50,50,100,30);
              cnt.add(jd);
              jd.addActionListener(this);
         public void actionPerformed(ActionEvent ae)
              Object but = ae.getSource();
              System.out.println("in action 00000");
              if(but.equals(jd))
                   System.out.println("in action ");
                   call();
                   return;
         void call()
              System.out.println("in action 1111111111");
              Inner inn = new Inner();
              inn.jdlg.show();
         public static void main(String s[])
              JFrame jf = new Testing();
              jf.setSize(200,200);
              jf.show();
         class Inner
              JDialog jdlg;
              //JTextField jt1;
              //JTextField jt2;
              Container cnt;
              Inner()
                   jdlg = new JDialog();
                   JLabel jla = new JLabel("Label");
                   jt1 = new JTextField();
                   jt2 = new JTextField(5);
                   cnt = jdlg.getContentPane();
                   cnt.setLayout(new FlowLayout());
                   cnt.add(jt1);
                   cnt.add(jt2);
                   jt1.setText("aaaaaaaa");
                   jt2.setText("bbbbbbbb");
                   System.out.println("the text "+jt1.getText());
                   jdlg.setSize(200,200);

    JTextFiled.setCaretPosition(0);

  • HT1491 How can I change answer to security questions?

    I tried to purchase apps on my new ipad, because it is a new device, itunes asked me to answer the security questions I chose when I originally setup my account. I seem to have forgotten the answer for them. How can I reset or change these answers to purchase apps on my new ipad?

    If you have a rescue email address set up on your account then you can try going to https://appleid.apple.com/ and click 'Manage your Apple ID' on the right-hand side of that page and log into your account. Then click on 'Password and Security' on the left-hand side of that page and on the right-hand side you might see an option to send security question reset info to your rescue email address.
    If you don't have a rescue email address then go to Express Lane  and select 'iTunes' from the list of 'products' in the middle of the screen.
    Then select 'iTunes Store', and on the next screen select 'Account Management'
    Next choose 'iTunes Store Account Security' and fill in that you'd like your security questions/answers reset.
    You should get an email reply within, I think, about 24 to 48 hours (and check your Spam folder as well as your Inbox)

  • Can not rember answer to security questions

    I need to use my Itune account but don´t remember answer to security questions.

    http://support.apple.com/kb/ht5312

  • Can someone please answer this question!!  re:  bootcamp 3.0 from dvd

    does anyone know if bootcamp 3.0 drivers are the same on all OEM DVD's?
    the reason i'm asking is because i had to do a bootcamp install for a friend on her macbook late 2009 and she didn't give me her dvd, so i pulled bootcamp 3.0 off of my macbook pro (mid 2009) install dvd. i've done the 3.1 64 bit update as well, and manually installed some drivers to get the sound and network adapter working.
    i know supposedly the dvd's are machine specific, and i know that with windows 7 x64 there are lots of outdated drivers, and i know the two machines have some hardware differences...
    but it also looks like bootcamp 3.0 has bundled all kinds of extra drivers just in case, so it's hard to tell if each dvd has it's own bootcamp 3.0 that's machine-specific.
    reason i'm asking is that after all the hacks and workarounds, i've got windows 7 x64 basically running ok on this macbook unibody white, but it doesn't seem to work as perfectly as a similar install i did on a macbook pro 15". for example, the trackpad...i don't have functionality for expose for example like i do on the mbp 15. and no headphone audio.
    so i'm wondering if i'm missing some machine specific drivers from my friend's dvd that are not on my MBP dvd..., even though both show "bootcamp 3.0"
    thanks.

    yes, but my point is if they updated Bootcamp on a newer DVD, would it still be called Bootcamp 3.0??
    i'm using my mid 2009 MBP dvd to install Bootcamp 3.0 on a late 2009 white macbook because my friend never gave me her dvd and she lives half way across the city (13 million people).
    i'm not into hacking things, but i haven't seen a single post in this forum where anyone successfully installed Bootcamp with Windows 7 x64 on any machine without having to screw around with drivers to get sound or network adapter working.
    i've posted several questions regarding various things without getting much of an answer.
    i've done many bootcamp installs that seem to function perfectly, but for some reason this one is giving me problems (windows 7 x64 on a white macbook).
    i'm asking general questions now because i suspect maybe the initial windows bootcamp 3.0 install (with subsequent 3.1 update) isn't giving me all the drivers i need.
    i can't confirm this 100%, but i'm still without headphone sound and some other things seem to me a little off. NOBODY that i know of has gotten the correct sound driver from the dvd to work with windows 7, everyone seems to have to install something newer...and from what i've read, the 3.1 update doesn't solve everyone's problems.
    that's why i'm wondering about the specifics of the dvd. if her OEM dvd and her version of bootcamp 3.0 is what's needed from the start, i won't proceed any further and do a complete mac os x and bootcamp clean install from scratch as soon as i get her dvd, but i'm not sure if it will make a difference or not.
    thanks.

  • Stupid question; you can probably all answer this

    I come from a different DBMS and I have never seen the word "enable" used this way:
    CREATE TABLE "CUSTOMERS"
    (     "CUSTOMERID" NCHAR(5) NOT NULL ENABLE,
         "COMPANYNAME" NVARCHAR2(40) NOT NULL ENABLE,
         "CONTACTNAME" NVARCHAR2(30),
         "CONTACTTITLE" NVARCHAR2(30),
    What does the word "enable" mean used within the create statement this way?
    Thanks!

    As I know
    ENABLE
    enables an integrity constraint.
    DISABLE
    disables an integrity constraint.
    You can enable and disable constraints with the ENABLE and DISABLE keywords of the CONSTRAINT clause. If you define a constraint but do not explicitly enable or disable it, Oracle enables it by default.
    As a general practice Enable is not used in Create statment coz Oracle enables it by default. If u ommit the Enable word from your statment then it will also produce same results.
    Regards
    Hafeez
    [email protected]

  • Maybe someone can answer this odd question...

    I've had an iBook G4 since November and this question has been killing me ever since: What are the two little hinged corner pieces on the charger for???
    When I plug my iBook into the wall, the module that actually plugs into the wall has two little corner pieces that swing out, almost like hooks. What are these for?!?!?!
    This very serious question has plagued me from day one. Thanks!

    Wow... Thanks for that enlightenment.... I never even considered the possibilities of the charging module...

  • Can somebody please answer this question about muse

    here is the thread to my original question.
    http://forums.adobe.com/thread/1290038
    Ben
    Thank you

    To be more specific, my question was will having two of these scripts work? And does it make a difference if there is a return space between the two scripts? I am not a coder and don't understand. Can it be explained in a simple step by step process? The properties box would be open, Then paste googles code? hit return, paste Bing's code. if by hitting return closed the properties dialog box, I could possibly re-open, insert curser a line below googles code then paste?
    sorry to be such a newby
    Ben

  • Can someone please answer this question..... I've asked 15 times with NO answer

    I have a php results file and html index file - and I just want the results to run..
    I learned that this is not possible in BC and that there might be a way to do something different.   ANY HELP?  PLEASE? 

    1128CreativeSolutions wrote:
    I have a php results file and html index file - and I just want the results to run..
    I learned that this is not possible in BC and that there might be a way to do something different.   ANY HELP?  PLEASE? 
    Can't run PHP or any other server side scripts on BC. Please tell us more about your requirement and we may find a BC solution for you.
    Cheers,
    -mario

Maybe you are looking for

  • Powerbook G4 sleeping on the job

    Is it possible to have the G4 notebook not go to sleep when you close the lid but instead have it keep running. I have not been able to find any setting for that Thanks In advance

  • Disc encoding problems?

    Two separate problems: 1/  I downscaled a short PAL 50i widescreen HDV video from CS4 to MPEG-2 DVD using "Use Maximum Render Quality" in Export Settings. The audio was PCM. I used VBR 2 Pass, Min bitrate 2.8, Max bitrate 8, Target bitrate 7, M frame

  • Cost center assigment cycle

    Hi friends,               Can any one help me in this issue? I have created assignment cycle where the sender is a cost center and the receiver is different WBS elements and a cost center, I would like to know if there is any possibility that the val

  • How to display list of TCodes with Change Documents enabled

    Hi I have 42 transaction codes (e.g. QA11, QA12, QE51N, QE01, QE02, MM01, MM02) and I want to verify if "change document" logging is enabled for the critical data elements in these transactions.  I'm aware that you can individually check "change docu

  • Remove the 'Master Password'

    I've searched to see if this topic has been raised in the forums, but I am unable to locate a similar question - which I find amazing. Once the Master Password has been set, the only option via the 'File Vault' area is to change the password. I am ke