Dynamic Call to Java Class or Method

Hi All,
I have a requirement to call a Class or a Method Within the same class dynamically based on the user choice. I will give an example with how I do it in pl sql.
begin
if (choice = 1) then
execute immediate 'package.procedure1(params)';
elsif (choice = 2) then
execute immediate 'package.procedure2(params)';
else
execute immediate 'package.procedure3(params)';
end if;
end;
From the Example above, I call a program based on user choice. How Can I do the same in Java?
Thank you.
Edited by: Eric S. on Jul 6, 2011 9:52 AM

I have a requirement to call a Class or a MethodYou can call a method, but not the Class where as you can instantiate the Class.
I will give an example with how I do it in pl sql.
begin
if (choice = 1) then
execute immediate 'package.procedure1(params)';
elsif (choice = 2) then
execute immediate 'package.procedure2(params)';
else
execute immediate 'package.procedure3(params)';
end if;
end;
From the Example above, I call a program based on user choice. How Can I do the same in Java?The similar way. Here it takes the following structure.
ClassA object = new ClassA();
if(choice==1) {
      object.callMethod1();
} else if(choice==2) {
      object.callMethod2();
} else if(choice==3) {
      object.callMethod3();
} Also you can switch case instead of if else. It takes the following structure.
ClassA object = new ClassA();
switch(choice) {
case 1:  object.callMethod1(); break;
case 2:  object.callMethod2(); break;
case 3:  object.callMethod3(); break;
}I recommend you to go with the second one which using switch.

Similar Messages

  • How do you call a java class from the main method in another class?

    Hi all,
    How do you call a java class from the main() method in another class? Assuming the two class are in the same package.
    Thanks
    SI
    Edited by: okun on May 16, 2010 8:40 PM
    Edited by: okun on May 16, 2010 8:41 PM
    Edited by: okun on May 16, 2010 8:47 PM

    georgemc wrote:
    To answer your impending question, either the method you're calling has to be static, or you need an instance of that other class to invoke it against. Prefer the latterAnd to your impending question after that: no, don't use the Singleton pattern.

  • Call Java Class and Methods from ABAP

    Hi
    I install de JCo, But how i can call java class and methods from ABAP?. somebody has an example?
    The tutorial say that's is possible,  but don't explain how do that?
    Thanks.
    Angel G. Hurtado

    If you need only simple java program, you do not need to install JCo. The following codes can call java class.
    DATA: COMMAND TYPE STRING VALUE 'C:\j2sdk1.4.2_08\bin\java',
          DIR TYPE STRING VALUE D:\eclipse\workspace',
          PARAMETER TYPE STRING VALUE 'Helloworld'. "here the name of your java program
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
       EXPORTING
         APPLICATION = COMMAND
         PARAMETER = PARAMETER
         DEFAULT_DIRECTORY = DIR
       MAXIMIZED =
         MINIMIZED = 'X'     "If you need the DOS window to be minimized
      EXCEPTIONS
        CNTL_ERROR = 1
        ERROR_NO_GUI = 2
        BAD_PARAMETER = 3
        FILE_NOT_FOUND = 4
        PATH_NOT_FOUND = 5
        FILE_EXTENSION_UNKNOWN = 6
        ERROR_EXECUTE_FAILED = 7
        OTHERS = 8.
    Tell me if it works.
    Nuno.

  • PI 7.1 Access to Dynamic Configuration through Java Class

    My Current scenario involves IDCO -> FILE communications in PI 7.1 using XSL where the file name is dynamic.
    I have attempted calling a Java Class from XSL with the use SAPXMLTOOL kit option set in the adaptor and it works but I need to be able to call the transform method
    public void transform(TransformationInput arg0, TransformationOutput arg1)
    from XSL so I can access the message and update the File Name via Dynamic Configuration.
    Whilst I can call a static class with in the object I can not call transform with the correct arguments (arg0, arg1). I need access to arg0 (payload) to set/figure out the filename. I can calculate the filename in XSL and pass it to the Java but in a static method it is useless as it need to access the arg0 which is a object and obviously non-static context.
    Is this possible ? How do I get access to Dynamic Configuration from XSL through Java in 7.1 ?
    I have successfully called a static method but that is no help.
    Thanks in advance.

    Suraj,
       Unfortunately you link isnt operational but thankyou anyway, I have managed to call as Java class as per my original post, but a static method does not allow me to get a handle to the Dynamic Configuration Variables in the message.
    It seems importing the 7.0 LIBS may be an option and Im not entirely sure I have that option.
    It certainly isnt possible to use the JDK5 XML implementation to even call a static method on an Java OBJ from XSL (obviously the USE SAPXMLTOOLKIT option is there for a reason).
    I think and again I could be wrong but direct access via XSLT..
    LINK:http://help.sap.com/saphelp_nwpi71/helpdata/EN/e2/e13fcd80fe47768df001a558ed10b6/frameset.htm
    Is what Im looking for, I shall report back success or failure but the doco seems to fit the bill. Im not sure why I wanted to instatiate a sperate Java class when it can all exist in the XSLT.

  • Jsp session variable to call in  java class.

    here i am facing a problem in calling a jsp session varibale to java class.
    in my code.. i have seperate files for jsp pages and packaged java classes.
    as i am developing a web tire application. the data entered in the front end i am getting to jsp page and putting the mandatory in session to use in other pages. now here the same session vaiable i have to use/call in java class file.
    Please refer me the best method and any references on this to call the session vaiable to java class file.
    in jsp page i decleared like this:
    session.setAttribute("stuIdentification",stuid);
    this id i have to use in java class.file.
    how to call it?
    Thanks
    Kurra

    Gimbal2's got the right idea.
    The reasons for choosing point 1) are also valid. Whenever possible try and do as much code that is not specifically tied to your business objects inside your dynamic element (the jsp page) instead of your static one (the compiled class)
    this allows you to very easily update your jsp to make any changes without having to recompile class code. Recompiling seems like a little thing when you are in development but imagine if the class is executed by a business critical application that faces forward to customers, recompiling will mean shutting down your servers and that may not be an option.
    Regards,
    David

  • How can I call a java class from within my program?

    I was wondering if there's a platform independent way to call a java class from my program.

    Here's my scenario. I'm working on a platform independent, feature rich, object-oriented command prompt program. The way I'm designing it is that users can drop classes they write into my bin directory and gain access to the class through my program. For example, they drop a class named Network.class in the bin directory. They would type Network network at my command prompt and gain access to all the methods available in that class. They can then type system.echo network.ipaddress() at my prompt and get the system's ip address. I have it designed that there's a server running in the background and the clients connect to my port. Once connected the end-user can enter their user name and password and gain access to the system. When they type a command they actually call another java program which connects to my server using a seperate thread. They can then communicate back and forth. I have it set that everything has a process id and it's used to keep track of who called what program. Once the program is done it disconnects and closes. Rather than getting into the nitty gritty (I didn't want to get into heavy detail, I know how everything will work) I'm really interested in finding out how I can call a java program from my program. I don't want it to be part of the app in any way.

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • Calling a Java Class from PL/SQL

    Hai,
    I need a technique of calling a class file and invoke its
    methods written in Java by PL/SQL for my intranet development.
    PLease let me know if you have really experienced and won.
    Thanks
    JOhnson

    First, to call a Java class from PL/SQL the class needs to be
    deployed to the database. you can check the 8i documentation for
    the instructions for loading Java into the database(LoadJava).
    The document contains information on how to load the Java and
    call it from PL/SQL. The following links should help.
    Loading Java:
    http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/
    java.817/a83728/03write6.htm
    Invoking a Java Method in the database:
    http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/
    java.817/a83728/04jserv2.htm
    Gary (JDev Team)

  • I want to call External Java class from the PL/SQL

    Hi,
    I am using Oracle Apps R11i (11.5.7), I wanted to call external Java class from the PL/SQL. This external Java class is residing in another application server.
    How do I do this.
    I know one way. Develop C routine in Oracle Apps to call external java class and call this C routine from the PL/SQL.
    Is there any simple method available? or any other method?
    Thanks in advance.
    -Venkat

    First of all, this is a Java application you're talking about, right (i.e. it has a main() function)? It's not just a class that you're trying to instantiate is it? If it's an application, you obviously have to start a new virtual machine to run it (rather than using the virtual machine built into the database like stored java). I'm a little leary of your mention of an "application server" as this would more commonly mean that a virtual machine is already over there running with access to this class. In which case, you'd typically interface with SOAP or some other RPC API.
    All that aside, as long as you have physical disc access (through NFS or whatever) to the class file, you could use a java wrapper class with a system call to do this. In fact, there is a thread in just the last day or so on this very forum that has the code to do just that (see " Invoking OS Commands from PL/SQL"). However, it's worth noting that the virtual machine will be running on the database server in this case and not the application server.

  • Calling a java class from abap/bsp

    Hello,
    I am still learning ABAP. I need to call a java class (a chart drawing library) from ABAP or from a BSP. What is the best way to do that ?
    Basically I would create an object, pass data from a database and then get some binary data from that object (an image).
    Hope you can help me
    Sincerely,
    Olivier Matt

    /people/gregor.wolf3/blog/2004/08/26/setup-and-test-sap-java-connector-outbound-connection
    check the above  link and this forum too
    Call Java Class and Methods from ABAP

  • Call a java class

    I have a fairly simple problem. I am making a basic game just for a learning experience.
    Project = 2ndif
    I have 2 classes in the project GuessingGame, and Town. After I finish with GuessingGame I need it to call Town.java class. Any suggesions. I put a note where I need to call Town.java
    I'm not 100% sure on how to ask for what I need. Not too fluent with the lingo yet.
    import static java.lang.System.out;
    import java.util.Scanner;
    import java.util.Random;
    class GuessingGame {
         public static void main(String args[]) {
              Scanner myScanner = new Scanner(System.in);
              out.println("Rolling stats... ");
              //Variables for stats
              int RandomNumber = 0;
              int Strength = 0;
              int Dexterity = 0;
              int Inteligence = 0;
              int Wisdom = 0;
              int Charisma = 0;
              int Counter = 0;
              int reroll = 1;
              //Reroll if stats are not desireable
              for (reroll=reroll; reroll==1;) {
                   RandomNumber = 0;
                   Strength = 0;
                   Dexterity = 0;
                   Inteligence = 0;
                   Wisdom = 0;
                   Charisma = 0;
                   Counter = 0;
              //3D6 rolls redo 1 if its first roll
                   for ( Counter=Counter; Counter<3; Counter++ ) {
                        RandomNumber = new Random() .nextInt(6) + 1;
                        if (RandomNumber == 1) {
                             RandomNumber = new Random() .nextInt(6) + 1;
                             Strength = Strength + RandomNumber;                
              Counter = 0;
              //3D6 rolls redo 1 if its first roll
                   for ( Counter=Counter; Counter<3; Counter++ ) {
                        RandomNumber = new Random() .nextInt(6) + 1;
                        if (RandomNumber == 1) {
                             RandomNumber = new Random() .nextInt(6) + 1;
                             Dexterity = Dexterity + RandomNumber;
              Counter = 0;
              //3D6 rolls redo 1 if its first roll
                   for ( Counter=Counter; Counter<3; Counter++ ) {
                        RandomNumber = new Random() .nextInt(6) + 1;
                        if (RandomNumber == 1) {
                             RandomNumber = new Random() .nextInt(6) + 1;
                             Inteligence = Inteligence + RandomNumber;
              Counter = 0;
              //3D6 rolls redo 1 if its first roll                    
                   for ( Counter=Counter; Counter<3; Counter++ ) {
                        RandomNumber = new Random() .nextInt(6) + 1;
                        if (RandomNumber == 1) {
                             RandomNumber = new Random() .nextInt(6) + 1;
                             Wisdom = Wisdom + RandomNumber;
              Counter =0;
              //3D6 rolls redo 1 if its first roll
                   for ( Counter=Counter; Counter<3; Counter++ ) {
                        RandomNumber = new Random() .nextInt(6) + 1;
                        if (RandomNumber == 1) {
                             RandomNumber = new Random() .nextInt(6) + 1;
                             Charisma = Charisma + RandomNumber;
              //Show stats
              out.println("Strength = " + Strength);
              out.println("Dexterity = " + Dexterity);
              out.println("Inteligence = " + Inteligence);
              out.println("Wisdom = " + Wisdom);
              out.println("Charisma = " + Charisma);
              out.println("");
              out.print("Reroll stats? 1 = yes 2 = no: ");
              reroll = myScanner.nextInt();
              out.println("");
              out.println("");
              *******THIS IS WHERE I NEED TO CALL TOWN.JAVA*********
    }

    //Show stats
              out.println("Strength = " + Strength);
              out.println("Dexterity = " + Dexterity);
              out.println("Inteligence = " + Inteligence);
              out.println("Wisdom = " + Wisdom);
              out.println("Charisma = " + Charisma);
              out.println("");
              out.print("Reroll stats? 1 = yes 2 = no: ");
              reroll = myScanner.nextInt();
              out.println("");
              out.println("");
              *******THIS IS WHERE I NEED TO CALL TOWN.JAVA*********
    }It seems like you are confused as to how to use your Town class. Java gives you the freedom to run an entire program in the main method like you are doing.. even if its not elegant. However, if you are going to continue your program as you are doing it in the main method. you probably want to do something like this.
    //Show stats
              out.println("Strength = " + Strength);
              out.println("Dexterity = " + Dexterity);
              out.println("Inteligence = " + Inteligence);
              out.println("Wisdom = " + Wisdom);
              out.println("Charisma = " + Charisma);
              out.println("");
              out.print("Reroll stats? 1 = yes 2 = no: ");
              reroll = myScanner.nextInt();
              out.println("");
              out.println("");
              /*******THIS IS WHERE YOU BEGIN TO USE A TOWN*********/
                    Town town = new Town();  // creates a new town
                     /* Here you start to do whatever it is you want to do with your newly created town...*/
                     town.addNewCharacter(Strength, Dexterity, Inteligence, Wisdom, Charisma);
                     town.whateverActionYouWantToDoWithYourTown();
    }

  • How to call a java class placed in java top?

    Hi,
    Can anyone please let me know how we can call the java class placed in the java top using PL/SQL?
    Thanks,
    Bharat

    Bharat ,
    Please refer this link , you can call java static method using sql function
    http://www.stanford.edu/dept/itss/docs/oracle/10g/java.101/b12021/invokeapp.htm
    Keerthi

  • How to call a java class in a bat file

    Hi
    I need to call a Test.java class in a bat files .It refer .DOM.jar
    in C:/url; How do i call the java class i need the syntax
    Thanks lot

    assuming lanch.bat, Test.class and DOM.jar are in c:\url
    assuming %JAVA_HOME% is defined (else substitue it with your java installation directory)
    here is the content of launch.bat:
    cd C:/url (or cd c:\url ) (or cd c: followed by cd url)
    %JAVA_HOME%\bin java -classpath .;DOM.jar Test
    hop that'd help,
    marvinrouge

  • Java.lang.NoClassDefFoundError while calling a java class from BPEL

    Hi,
    I'm calling a java class to convert JSON to XML using BPEL. I have imported all the necessary jar files in the project and compiling done successfully.
    But at runtime , i get the java.lang.NoClassDefFoundError: net/sf/json/JSON error.
    For this i placed all the necessary jars under FUSION_HOME/Oracle_SOA1/soa/modules/oracle.soa.ext_11.1.1/ path and restarted the server.
    But still i'm getting the same error at runtime.
    Did i missed any step? Let me know the procedure to solve this.
    Do i have to run ant or edit Manifest file after placing the jar?
    in one site i find we have to place the jars under <DOMAIN HOME>/lib directory. Is this correct?
    We are using SOA suite 11.1.1.6.
    Thanks,
    Terry

    Hi Karan,
    I have done placing the jars at FUSION_HOME/Oracle_SOA1/soa/modules/oracle.soa.ext_11.1.1/ and ran ant  -f build.xml .The build was successful without any error.
    I have even placed the jars in <DOMAIN HOME>/lib (/us2001/fmw/11.1.1.6/user_projects/domains/ohsdomain/lib) and did a server restart.
    After these activities, when i execute the composite, i still get the error in em console,
    Message
    got RuntimeException
    Supplemental Detail
    oracle.fabric.common.FabricException: Could not create object of class 'packageName.className'; nested exception is:
    java.lang.NoClassDefFoundError: net/sf/json/JSON
    at oracle.integration.platform.blocks.wsif.WsifReference.request(WsifReference.java:698)
    at oracle.integration.platform.blocks.mesh.SynchronousMessageHandler.doRequest(SynchronousMessageHandler.java:139)
    at oracle.integration.platform.blocks.mesh.MessageRouter.request(MessageRouter.java:182)
    Any help on this.
    Thanks,
    Terry

  • Calling a java class in JSP in Weblogic 5.1

    Hi
    I am trying to call a java class in a jsp page. But it is giving an error:
    Compilation of 'C:\weblogic\myserver\classfiles\jsp_servlet\_knet\_buy.java' failed:
    C:\weblogic\myserver\classfiles\jsp_servlet\_knet\_buy.java:79: cannot access jsp_servlet._knet.e24PaymentPipe
    probably occurred due to an error in /knet/buy.jsp line 25:
    e24PaymentPipe pipe = new e24PaymentPipe();
    Is this a problem bcos of the wrong path of the class file which i am calling?
    Please help this is urgent

    Hello All
    As I tried to deploy the easiest project (dummy.war) on WebLogic 8.1.5, There is only one class (without package) Login.class
    *********** Listing of the dummy WAR ***********
    META-INF/
    META-INF/MANIFEST.MF
    WEB-INF/
    WEB-INF/classes/
    WEB-INF/classes/Login.class
    WEB-INF/web.xml
    index.jsp
    login.jsp
    ************ Output of deployment from Admin Console****************
    Log:     
         A log of the task's activities.
    [Deployer:149033]preparing application dummy on intranetAdmin
    [Deployer:149033]prepared application dummy on intranetAdmin
    [Deployer:149033]activating application dummy on intranetAdmin
    [Deployer:149033]failed application dummy on intranetAdmin
    [Deployer:149034]An exception occurred for task [Deployer:149026]
    Deploy application dummy on intranetAdmin.:
    Exception:weblogic.management.ApplicationException: start() failed.
    Module: dummy Error: weblogic.management.DeploymentException:
    [HTTP:101216]Servlet: "index" failed to preload on startup in Web application:
    " dummy ".
    weblogic.servlet.jsp.CompilationException: Compilation of D:\apps\wlsapp\
    INTRAN~1\.\intranetAdmin\.wlnotdelete\extract\intranetAdmin_ dummy _ dummy
    \jsp_servlet\__index.java failed.
    D:\apps\wlsapp\INTRAN~1\.\intranetAdmin\.wlnotdelete\extract\
    intranetAdmin_dummy_dummy\jsp_servlet\__index.java:22: '.' expected
    import Login; //[ /login.jsp; Line: 8]
    ^
    1 error
    at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:478)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:246)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:196)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.
    java:3430)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.
    java:3387)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext
    .java:3373)
    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:3356)
    at weblogic.servlet.internal.WebAppServletContext.setStarted(WebAppServletContext.java:
    6208)
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:864)
    at weblogic.j2ee.J2EEApplicationContainer.start(J2EEApplicationContainer.java:2134)
    at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2175)
    at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.
    activateContainer(SlaveDeployer.java:2520)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer
    .java:2438)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2155)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2254)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2149)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.
    java:2401)
    at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:
    883)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:591)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:500)
    at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    Caused by: java.io.IOException: Compiler failed executable.exec
    at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvoker.java:470)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:328)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:336)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:321)
    at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:451)
    ... 22 more
    - with nested exception:
    [java.io.IOException: Compiler failed executable.exec]
    I put this class into a dummy package named sample, changed package declaration within this class and changed import statement within jsp pages like this :
    <%@ page import="sample.Login " %>
    <jsp:useBean id="logUsr" scope="session" class="sample.Login" />
    When I did like this, everything is ok. No more exception.
    If my application has so many java classes under WEB-INF/classes/ without creating package, it may be so inconvenience.
    Please kindly let me know why this exception (class not found exception) occurred.
    And what is the solution? I cannot deploy the application successfully yet.
    many thanks,
    Zin Ko Win

Maybe you are looking for

  • Where Did my File Go?

    Why is it that every time I sit down for a session with my Adobe products, it seems that I am searching my computer many many times for where Adobe stores my files. For example, if in Photoshop and I Save for Web and Devices, the default directory is

  • HFM 11.1.2 and IE8

    I saw a post that said HFM 11.1.2 does support IE8. Does anyone know where I can find an Oracle document that states this? Thanks!

  • Probabally old question, but why can't I get Full Screen?

    Hi, I have the latest Quicktime, upgraded to Quicktime Pro...installed and registered but still no full screen. At Best I can few 3/4 screen. What do I need to do to fix? My old Windows Media was a true full screen....Is Apples? Thanks, Bill

  • Arch + gnome|kde against other distros

    Arch for me is a perfect distro in that sense, that I know exactly, where all configuration is stored, what every file means and where to dig in case of problems. But this is true only if I don't use major DEs, such as gnome or kde. So I want to ask

  • 3rd party browser support

    Since I've installed Mavericks, I've notice that Google Chrome doesn't seem to work as well. Anyone else having a similar issue?