Execute method by the string name

Well,
I want execute a method , just knowing the string name of her and your class too:
public class A
public static void Kick()
public class B
final String methodToBeExecuted="Kick";
Or on the same class too.
This is possible?
(In C I could use functions pointers on an array)
A solution can use @Anotation ou "Reflection"
Thanks

i've never seen anything like that, my advice is to
look closer at your design because your problem is
very easy to circumventOk but this is not a desing problem.
It's just a performatic problem.
Im coding an emulator and need to handle opcode.
swicth (opcode)
case 0x1:
  method1();
case 0xA:
  methodA();This code (one processor that have 256 instructions) can produce a slow program and change it to a thing like this:
final String instruction = "method" + opcode;Is very very very fast... and build an emulator we nedd to forget a little about the patterns and good pratices and make performatic things.
understood?

Similar Messages

  • Applet with 2 methods with the same name in ie

    Hi,
    I have a problem with the Java 1.5 plugin for Internet Explorer .
    When my Applet contains 2 methods with the same name but not the same return type, ie does not take the good return type.
    Here is an exemple :
    * Class TestApplet
    package test.applet;
    import java.applet.Applet;
    public class TestApplet extends Applet {
         public void init() {
              System.out.println("init()");
         public void start() {
              System.out.println("start()");
         public String test(String s) {
              System.out.println("test(String) :" + s);
              return s;
         public boolean test(int i) {
              System.out.println("test(int) :" + i);
              return true;
    }I have 2 methods test(), one returns a String and the other a boolean.
    I use the following html code :
    <html>
    <head>
    <script>
    function test() {
         alert(document.DataAccess.test("hello"));
    </script>
    </head>
    <body>
    <applet WIDTH="500" HEIGHT="200" ID="DataAccess" NAME="DataAccess" CODE="test.applet.TestApplet">
    </applet>
    <div onclick="test()">test</div>
    </body>
    </html>
    When I click on "test", the alert show "true" instead of "hello".
    The problem only occurs with a JVM 1.5. It work fine with JVM 1.4.
    Any idea ? Is it a bug ?
    Thanks.

    In your javascript method:
    function test() {
    alert(new String(document.DataAccess.test("hello")));
    MSJVM and SUN jre use different conversion from javaScript objects to Java.
    if you call from javaScript:
    document.getElementById("myApplet").myMethod(22);
    The method in MSJVM should look like this:
    public whatever myMethod(Double d);
    and SUN jre:
    public whatever myMethod(Integer i);
    The best thing to do is this:
    public whatever myMethod(Object o);
                   int col = 0;
                   if (o.getClass().getName().toLowerCase().indexOf("integer") != -1) {
                        col = ((Integer) o).intValue();
                   } else {
                        col = ((Double) o).intValue();
                   }

  • How can I execute method of Component for name

    Hello,
    My program has JInternalFrame with some components. Write me please - how can I execute method of Component for name of Component ?
    Like this:
    ... findObject("jTextArea1").cut();
    Thank you in advance.

    just cycle through the container's components until
    you find one where getName equals "jTextArea1"Thank you for your answer.
    I'm creating components in runtime (I add panel+JTextArea in JTabbedPane) and I don't know how many components will be in JTabbedPane.
    I know only it's names.
    I wan't to execute metod JTextaRea_n_.cut() via using JTextaRea_n_.Name.
    How ?

  • 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.

  • What does the trim() method of the String class do in special cases?

    Looking here ( String (Java Platform SE 7 ) ), I understand that the trim() method of the String class "returns a copy of the string, with leading and trailing whitespace omitted", but I don't understand what the last special case involving Unicode characters is exactly.
    Looking here ( List of Unicode characters - Wikipedia, the free encyclopedia ), I see that U+0020 is a space character, and I also see the characters that follow the space character (such as the exclamation mark character).
    So, I decided to write a small code sample to try and replicate the behaviour that I quoted (from the API documentation of the trim method) in the multi-line comment of this same code sample. Here is the code sample.:
    public class TrimTester {
        public static void main(String[] args) {
             * "Otherwise, let k be the index of the first character in the string whose code
             * is greater than '\u0020', and let m be the index of the last character in the
             * string whose code is greater than '\u0020'. A new String object is created,
             * representing the substring of this string that begins with the character at
             * index k and ends with the character at index m-that is, the result of
             * this.substring(k, m+1)."
            String str = "aa!Hello$bb";
            System.out.println(str.trim());
    However, what is printed is "aa!Hello$bb" (without the quotes) instead of "!Hello$" (without the quotes).
    Any input to help me better understand what is going on would be greatly appreciated!

    That's not what I was thinking; I was thinking about the special case where the are characters in the String whose Unicode codes are greater than \u0020.
    In other words, I was trying to trigger what the following quote talks about.:
    Otherwise, let k be the index of the first character in the string whose code is greater than '\u0020', and let m be the index of the last character in the string whose code is greater than '\u0020'. A new String object is created, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m+1).
    Basically, shouldn't the String returned be the String that is returned by the String class' substring(3,9+1) method (because the '!' and '$' characters have a Unicode code greater than \u0020)?
    It seems to not be the case, but why?

  • Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain

    Hi All,
      I have created a custom web part in VS 2008 for Share point server 2010 with DevExpress v12.2.17, and deployed as Sandboxed solution. when i add that web parts in web part zone i am getting the error as "Web Part Error:
    Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. ".
    If there is any way to get detailed error either log file or event viewer.
    Kindly advice to find the cause of the problem.
    Thanks,
    Selvakumar.S

    Hello,
    Are you impersonating your code? Have you tried to debug your code by attaching SPUCHostService.exe? if not please do so.
    You also need to check ULS log for more information about this error. Here is one ref link if this could help
    http://sohilmakwana.wordpress.com/2013/11/29/sandbox-error-unhandled-exception-was-thrown-by-the-sandboxed-code-wrappers-execute-method-in-the-partial-trust-app-domain/
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Execute method to a string written in another string

    Hi all,
    I need help...!!
    I must call a function/method on a string written in another string like this:
    String s1 = "GR0000";
    String s2 = "substring(0,s1.length()-2)";
    I want execute
    s1.substring(0,s1.length()-2)
    from s1,s2, how can i do it?
    Thank you in advice!!!

    Hi all,
    I need help...!!
    I must call a function/method on a string written in
    another string like this:
    String s1 = "GR0000";
    String s2 = "substring(0,s1.length()-2)";
    I want execute
    s1.substring(0,s1.length()-2)
    from s1,s2, how can i do it?
    Thank you in advice!!!Advance.
    I assume that you want the equivalent of a javascript eval() function ?
    Seek for it not in java! What you want is a script interpreter. What you could do is wrap the string in a string representing a java class, write that string to disk as a java file, compile it, have the ClassLoader suck it up and execute it. Viola. The jsp-way; the hard way, but the only way.
    If I'm wrong about your intentions, then tell me. I can't seem to figure it out totally. But good luck anyway.

  • Problem in executing jar when the folder name has empty space

    Hi,
    I need to run my java swing application on double clicking the jar file. It works fine when the file path has no empty spaces in the folder name. It doesnt open when the folder name has spaces in between them. Can anyone let me know how to resolve it.
    String workingDir = new File("SwingApplication").getAbsolutePath();
    String cmd = "java -jar " ++workingDir ++"/SwingApplication.jar";
    Runtime.getRuntime().exec(cmd);This works fine when the SwingApplication.jar is inside for eg: c://{color:#ff0000}RunApplication{color}/SwingApplication.jar
    but the application doesnt open if the file path is c://{color:#0000ff}Run Application{color}/SwingApplication.jar

    javaquests wrote:
    ..ProcessBuilder pb = new ProcessBuilder("java -jar");
    pb.directory(new File(workingDirPath + "/SwingApplication.jar"));
    Process p = pb.start();
    . but getting an exception
    java.io.IOException: Cannot run program "java -jar" (in directory "C:\Run Application\SwingApplication.jar"): CreateProcess error=267, The directory name is invalidWhile..
    C:\Run Application\..might be a directory, is..
    C:\Run Application\SwingApplication.jar?
    I was thinking something more like this (untested)..
    String path = workingDirPath + "/SwingApplication.jar";
    String[] command = {
         "java",
         "-jar",
         path
    ProcessBuilder pb = new ProcessBuilder(command);
    Process p = pb.start();BTW - when posting code, code snippets, HTML/XML or input/output, please use the code tags. The code tags protect the indentation anf formatting of the sample. To use the code tags, select the sample and click the CODE button.

  • Output in word file: Methods or the class name required

    Hi Gurus,
    I am trying to get output of the program in a word document directly without any Script or Report in between.
    Steps i follow are:
    Fetching the data
    Invoking word
    Writing the data into the word file created using methods like 'tablegridlines', 'insert' etc.
    When i get this data in the word file , in between every two lines i get one empty (extra) line.
    What can i do to remove that extra line in between. Everything has to be done in my own program using methods.
    Is there any method to delete the line comming between two lines i have created.
    Is there any method to convert the layout of the word file created to "Landscape".
    I would appreciate if somebody could tell me the class which has the methods like 'tablegridlines'
    'insert' 'viewheaderfooter' etc which are used for word output in this case.
    The object that i have created is of the type ole2_object.
    Helpful answers would certainly be rewarded.
    Thanks
    Suruchi
    Edited by: Suruchi Mahajan on May 14, 2008 6:04 AM

    Hi All,
    For the possible methods ,search in table OLELOAD.
    Regards
    Suruchi

  • How to implement the String class "split()" method (JDK1.4) in JDK 1.3

    is it possible , with some code, to implement the split() method of the String class......which is added in JDK1.4 ..... in JDK1.3
    would be helpful if anyone could suggest some code for this...

    Here it is
    public static String[] split(String source, char separ){
    answer=new Vector();
    int position=-1, newPosition;
    while ((newPosition=source.indexOf(separ,position+1))>=0){
    answer.add(source.subString(position+1,newPosition));
    position=newPosition;
    } //while
    answer.add(source.subString(position+1,source.length-1);
    return (String[])(answer.toArray());
    } //split

  • Setting up the File Name of email Attachment from Received File Name

    Hello All,
    I have to send the Received File in attachment to an Email if there is any exception. Here I can attach the file, but I cannot set the file name of attachment as the Received File Name. Is there anyway of doing this without using custom pipeline component.
    Here I am using the Orchestration and SMTP Adapter.Any help is greatly appreciated.
    Thanks

    It might work if you use a custom pipeline component on your send port and in the Execute method populate the MIME.FileName property of the body part.
    Something like:
    public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
    string filename = inmsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties");
    inmsg.BodyPart.PartProperties.Write( "FileName", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "filename);
    return inmsg;
    You can take reference from similar post here
    SMTP - Setting attachment filename
    Anther good article with MIME is here
    Setting attachment filename with the SMTP Adapter
    For MIME case your SMTP message construct statement would be like below
    multipartMessage.MessagePart_1= InMSG;
    multipartMessage.MessagePart_2="This is message part2 as a string";
    multipartMessage(SMTP.Subject) ="Email From Dynamic Port";
    multipartMessage(SMTP.From) ="[email protected]";
    multipartMessage(SMTP.SMTPHost) ="yoursmypserver.com";
    multipartMessage.MessagePart_2(MIME.FileName) = "Attachment_Name";
    multipartMessage(SMTP.SMTPAuthenticate) =0;
    Thanks
    Abhishek

  • Custom pipeline component creates the folder name to archive messages

    Hi 
    I have an requirement that a BizTalk application is receiving untyped messages and at the receive location the pipeline have to archive the incoming message with the specifications:
    suppose I have an xml like
          <PurchaseOrder>
            <OrderId>1001</OrderId>
            <OrderSource>XYZ</OrderSource>
            <Code>O01</Code>
          </PartyType>
    In the pipeline component it has to read this xml and have to use OrderSource value 'XYZ' to create a archival folder and the message have to archive with file name '%MessageId%'
    It has to be done by writing custom pipeline component where I am not familiar with c# coding, Can anyone please how to implement mechanism.
    Thanks In Advance
    Regards
    Arun
    ArunReddy

    Hi Arun,
    Use
    BizTalk Server Pipeline Component Wizard to create a decode pipeline component for receive. Install this wizard. This shall help you to create the template project for your pipeline component stage.
    Use the following code in the Execute method of the pipeline component code. This code archives the file based with name of the file name received.
    public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
    MemoryStream tmpStream = new MemoryStream();
    try
    string strReceivedFilename = null;
    DateTime d = DateTime.Now;
    try
    //Get the file name
    strReceivedFilename = inmsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();
    if (strReceivedFilename.Contains("\\"))
    strReceivedFilename = strReceivedFilename.Substring(strReceivedFilename.LastIndexOf("\\") + 1, strReceivedFilename.Length - strReceivedFilename.LastIndexOf("\\") - 1);
    catch
    strReceivedFilename = System.Guid.NewGuid().ToString();
    originalStream = inmsg.BodyPart.GetOriginalDataStream();
    int readCount;
    byte[] buffer = new byte[1024];
    // Copy the entire stream into a tmpStream, so that it can be seakable.
    while ((readCount = originalStream.Read(buffer, 0, 1024)) > 0)
    tmpStream.Write(buffer, 0, readCount);
    tmpStream.Seek(0, SeekOrigin.Begin);
    //ToDo for you..
    //Access the receive message content using standard XPathReader to access values of OrderSource and construct file pathAccess the receive message content using standard XPathReader to acceess values of OrderSource and contruct the file path
    string strFilePath = //Hold the value of the file path with the value of OrderSource
    string strCurrentTime = d.ToString("HH_mm_ss.ffffff");
    strFilePath += "\\" + strReceivedFilename + "_";
    FileStream fileStream = null;
    try
    System.Threading.Thread.Sleep(1);
    fileStream = new FileStream(strFilePath + strCurrentTime + ".dat", FileMode.CreateNew);
    catch (System.IO.IOException e)
    // Handle the exception, it must be 'File already exists error'
    // Wait for 10ms, change the file name and try creating the file again
    // If the second 'file create' also fails, it must be a genuine error, it'll be thrown to BTS engine
    System.Threading.Thread.Sleep(10);
    strCurrentTime = d.ToString("HH_mm_ss.ffffff"); // get current time again
    string dtcurrentTime = DateTime.Now.ToString("yyyy-MM-ddHH_mm_ss.ffffff");
    fileStream = new FileStream(strFilePath + strCurrentTime + ".dat", FileMode.CreateNew);
    while ((readCount = tmpStream.Read(buffer, 0, 1024)) > 0)
    fileStream.Write(buffer, 0, readCount);
    if (fileStream != null)
    fileStream.Close();
    fileStream.Dispose();
    if (originalStream.CanSeek)
    originalStream.Seek(0, SeekOrigin.Begin);
    else
    ReadOnlySeekableStream seekableStream = new ReadOnlySeekableStream(originalStream);
    seekableStream.Position = 0;
    inmsg.BodyPart.Data = seekableStream;
    tmpStream.Dispose();
    catch (Exception ex)
    System.Diagnostics.EventLog.WriteEntry("Archive Pipeline Error", string.Format("MessageArchiver failed: {0}", ex.Message));
    finally
    if (tmpStream != null)
    tmpStream.Flush();
    tmpStream.Close();
    if (originalStream.CanSeek)
    originalStream.Seek(0, SeekOrigin.Begin);
    return inmsg;
    In the above code, you have do a section of code which will access the receive message content using standard XPathReader to access values of OrderSource and construct the file path. I have
    commented the place where you have to do the same. You can read the XPathReader about here..http://blogs.msdn.com/b/momalek/archive/2011/12/21/streamed-xpath-extraction-using-hidden-biztalk-class-xpathreader.aspx
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Re: getting the file name from a dynamic web server

    On a related note, how do I get the information from the:
    URLConnection.getContent ()
    method?
    I mean I create URL object, then
    I create a URLConnection object by doing the following from my URL object (urlObject):
    URLConnection con = urlObject.openConnection()
    Then when I get the content from the URLConnection:
    Object contentReturned = con.getContent();
    I check the class name:
    System.out.println("con.getContent class name :"+contentReturned.getClass().getName());
    The class name that is returned is:
    sun.net.www.protocol.http.HttpURLConnection
    But when I tried to cast the returned object to a java.net.HttpURLConnection it threw an exception.
    So basically my question is how do I access the information in either the URL.getContent or the URLConnection.getContent methods?
    Thanks,
    Tim

    could someone tell me how the URL.toString() text is generated. I realize in the doc's it says it calls the toExternalForm method, but then my question is where does the method toExternalForm get its text/data?
    In the javadoc's it says the information returned from the toExternalForm method is:
    The string is created by calling the toExternalForm method of the stream protocol handler for this object.
    How can I access this.
    Basically when toString is called, there is some information in the text returned - something like this:
    sun.net.www.protocol.http.HttpURLConnection:http://static.webserver.com/kuki/foofi1.mpg
    and instead of parsing this string, I would like to get the
    http://static.webserver.com/kuki/foofi1.mpg
    portion of the string from whatever source the toExternalForm method used.
    Thanks,
    Tim

  • Getting the string value of a step in Test stand 3.1

    Hi All , can anyone advise whicn control I use to retrieve the string value of the STEP name using v3.1.
    It was the sequence context in earlier versions.
    thanks dht

    I'm assuming you want the step's name as a string? Inside TestStand there is the NameOf function that can be used with any TestStand object. i.e.
    Locals.mystring = NameOf(RunState.PreviousStep) or something like this� You can access this function outside of TestStand by using the PropertyObject.Evaluate() method.
    You could also use the TS API (in TS or in LV or someplace else) to start with a Step object, turn it into a PropertyObject, and then get its property �Name� which will return the string name of the step.
    Third option off the top of my head is to explore the Hidden Properties of TestStand, that you have to enable by going through the Configure menu. There�s a knowledge base about it somewhere on the NI website if you�re curious. If you remember browsing fo
    r the step name via a sequence context/expression browser before now, it was probably hidden properties that you were using.
    Cheers!
    Elaine R.
    www.bloomy.com
    Cheers,
    Elaine R.
    www.bloomy.com

  • Question about the String class

    Did I understood the JLS/Javadoc properly if I say that the String class has got an internal pool of String objects (therefore I expect this pool to be stored in some sort of static variable)?
    Looking at the intern() method in the String class, this is declared as native, which make me think the whole pooling thing is managed internally by the JVM.
    Does this mean that, if there is only a String class per JVM and String literals (or better Strings that are values of constant expressions) are pooled in the String class, the more String constants are around the bigger the String class object becomes?

    Did I understood the JLS/Javadoc properly if I say
    that the String class has got an internal pool of
    String objects (therefore I expect this pool to be
    stored in some sort of static variable)?Yes.
    Looking at the intern() method in the String class,
    this is declared as native, which make me think the
    whole pooling thing is managed internally by the JVM.The intern() method is implemented in some programming language. If you happen to have a Java runtime where it is written as a native method, it is probably implemented in C or C++. Not a terribly important detail.
    Does this mean that, if there is only a String class
    per JVM and String literals (or better Strings that
    are values of constant expressions) are pooled in the
    String class, the more String constants are around
    the bigger the String class object becomes?The String.class object (of type java.lang.Class) as such doesn't "grow", but some memory structure somewhere will contain interned String literals. Probably a hash table of some sort. Yes indeed: if you have String literals in your program, those literals are stored in the computer's memory during runtime so that they can be accessed by the executable program code.

Maybe you are looking for

  • New VCA no longer working with corporate firewall...

    Old version of VCA worked great.  New version has become useless when at work - when I need to monitor calls to the home.  The VCA client no longer shows in-coming calls nor does it maintain call logs in real-time.  Any ideas or suggestions?

  • Bw-ip file upload in BW 7.3

    Hi Friends I am using BW 7.3 and i am unable to find Planning Sequence/Function File Upload . Is it available standard planning sequence for file upload in BW 7.3. Pl. advise Rgds Sri G

  • 10.6.8 and Creative Cloud

    I have tried at least 10 times to download InDesign CS6 without any success. At the very end of the download it gives me an installation error, and I've retried WAY too many times. Any help? Running on 10.6.8 because I don't want to lose Quark 6.5 at

  • LDAP-help-urgent

    How can we check authentication using LDAP server and JSP

  • Audio drops and cracks and odd sounds upon export...

    working on CS4, on my mac powerbook. upon exporting the audio has issues it doesn't in the project editing/CS4. I've used crossfades, exponential fades to be specific... and even when I delete them, I have issues with clips I've never used them on. t