gkaindia.com

Home > > Dynamic Call to Java Class or Method

Dynamic Call to Java Class or Method

Advertisement
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
Advertisement
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.
Read the other 15 answers
Hi I want to call a method from a class,which class is loaded dynamically. Consider a classA and ClassB.. ClassB contains a method showvalue() which returns a String value. I want to load a ClassB dynamically in ClassA,and call the method showvalue()
I was asked following in the interview- What things are dynamically loaded in Java? How can we change this behaviour so as to load things statically? Can anybody clarify this for me or give some reference URLs etc? Thanks in advance.I was asked follo
I want to call a specified method of one class dynamically. I use the method "getMethod()" in package "java.lang.Class" to get method and "invoke()" in " java.lang.reflect.Method " to invoke method. The problem is a
Hello Experts, I tried to integrate WebCenter Content with Autovue ,the integration was good untill i get this error while trying to open a dwg file checked in Content Server using View in Autovue option in Actions : java.lang.NoSuchMethodException:
hello everybody, I want to make dynamic reports in Java. Report contain data and images with good layout.. such as crystal reports presentation.. Reports fields decided at run time or we can say that it is generated according to user requirement... c
Hi , oracle apps version : 11.5.10.2 and database version 11.2.0.2. OS version Solaris Sparc 64 Bit. We were performing a cloing activity on a new server and now while opening forms we are getting the following error : error:java.lang.Double:method p
Hi, I've been trying to use the java.sql.Blob methods instead of the "Oracle Extensions" so that people w/o Oracle (using MySQL etc.) can still use my code. Problem: trying to get the OutputStream to write to the Blob. As of JDK1.4, java.sql.Blo
java.lang.NoSuchMethodError: java.lang.Float: method parseFloat(Ljava/lang/String;)F not found WHAT WOULD MAKE THIS HAPPEN. THIS SEEMS TO WORK IN JDK1.3.1 BUT NOT IN BLACKDOWN 1.1.3_V3 THIS IS MY CODE: try{ DecimalFormat dfp = new DecimalFormat( "0.0
Hi guys!           How can we access java control source methods that are defined in java control projects within jsp.I am getting error when I tried to call java control source's methods in scriptlet of JSP page.Any help/suggestion is appreciated.  
Hi I work on a project that use java api version 1.2, after the deployment of the web application and using it I have had the following error message: [Mon Oct 16 11:52:51 GMT 2006] Memory used: 24467288 Error: org.epoline.soprano.Csstart: A fatal er
This is probably a FAQ, but I am finding it impossible to construct a search which answers this question for me. How do I call java.lang.reflect.Method.invoke on a static (e.g. class) method? Is it even possible? Thanks, dwhIs this of any help? http:
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. HurtadoIf you need only simple java program, you do not need to
Does java.util.Properties methods load & store produce & load platform independent code?You mean that it is better to use loadFromXML(InputStream in) and storeToXML(OutputStream os, String comment) methods of this class in order to have platform i
I want to create dynamic images in java servlet. Can servlet create dynamic images that based on the input data files? The results can be displayed in GIF, JPG..format? how can this be done? any example in internet? What OS do I need to install and w
After using jexegen from microsoft to make EXE. I receive this error when i execute the my EXE : java.lang.NoSuchMethodError: java/util/Vector method revove... Any body know why? If i execute from JBuilder i have no problem!hi, i don't have much expe
Hi , Why java allows start method only once for thread . suppose Thread t = new Thread(); t.start(); say at later stage if again we call t.start() IllegalStateException is thrown , even though isAlive method returns false. Hence the question , why st
Why objects are dynamically created in java even if dynamically created object requires more space & more memory references as compared to static object?I don't even know where to start... KAMAL.MUKI wrote: Why objects are dynamically created in java
how to define linklist object and to build dynamic array in java?with so little information, all one can do is pointing you to : http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html http://java.sun.com/j2se/1.5.0/docs/api/java/util/Array
Hi, Is every method of java a Virtual method ? Can any methods be overridden ? Is that making use of double pointer ? Edited by: shyam1 on Sep 22, 2010 10:44 PMshyam1 wrote: jverd wrote: shyam1 wrote: Hi, Is every method of java a Virtual method ?Eve