How to convert a String variable as class name and method name?

i have two classes
class Student
public String insertStudent(String sname)
{ return("Student has been inserted ");     }
class Teacher
public String execute(String methodName, String className)
{  //return statement of the method 'insertStudent' in the class 'Student'; }
}Now, i have a class with the main method. Here, i would like to call the method *'insertStudent'* of class *'Student'*
using the method *'execute'* of class *'Teacher',* passing the method-name and the class-name (viz. insertStudent, Student) as the
String parameter.
Can anyone please help me out. Thanks
regards,
chinglai

You should have just added that as a comment on your [initial posting|http://forums.sun.com/thread.jspa?threadID=5334953] instead of starting a new thread.
Now, i have a class with the main method. Here, i would like to call the method 'insertStudent' of class 'Student'using the method 'execute' of class 'Teacher', passing the method-name and the class-name (viz. insertStudent, Student) as the
String parameter.
Why oh why? What do you want to achieve?
Let me tell you: there is a way to do what you try to do, but it's not recommended and should be used only very sparingly. Especially not in anything like your code, that resembles normal business logic (as opposed to an application framework such as Spring, for example).
Can you explain what exactly you want to do with that? Why should a Teacher be able to call any random method ony any other class. And what good would that do?

Similar Messages

  • How to convert a String Variable to a Number and retain decimal place

    Hello!
    Here is my problem!
    I am receiving information from a source that I cannot control.  It is sending me Numbers in to form of strings.
    Ex: 12,200.49
    I have tried usingval() but only get " 12 " because it stops when it see a comma or period.
    I have also tried using Replace() to remove the comma and period, but then my number grows, because the last two digits are now part of the number and no longer behind a decimal point.
    Here is some example code
    <cfset Price = "12,200.49">
    <cfoutput>
    #val(Price)#
    <cfset Price = '#Replace(Price,",","","ALL")#'>
    <BR />
    #val(Price)#
    <cfset Price = '#Replace(Price,".","","ALL")#'>
    <BR />
    #val(Price)#
    <cfset Price = #NumberFormat(Price, "_____.__")#>
    <BR />
    FINISHED WITH #Price#
    </cfoutput>
    The output of the above code is this:
    12
    12200
    1220049
    FINISHED WITH 1220049.00
    So, you can see that 12,200.49 is now 1,220,049.00 because the two digits where added.
    What I would like to finish with is a String "12,200.49" that is now a Number like this $12,200.49
    Please help!!!

    HI
    try this
    <cfoutput>
        <cfset t="12,200.49">
        <cfset Price = Replace(t,",","","ALL")>
    #DollarFormat(Price )#
    </cfoutput>

  • How to get class name and method name within a class method?

    Hi,
    In a java class, is it possible to get its class name and the class method?
    Please advise.
    Thank you.

    I mean whether there's any built-in command that will
    return the class name instead of code it ourself, for
    easier maintenance.
    Possible?
    this.getClass().getName();

  • How to convert an int variable into String type

    hi everybody
    i want to know how to convert an interger variable into string variable
    i have to implement a code which goes like this
    Chioce ch;
    for(int i=0;i<32;i++)
    // here i need a code to convert the int variable i into a string variable
    ch.add(String variable);
    how do i convert that int variable i into a String type variable??
    can anyone help me?

    Different methods:
    int a;
    string s=a+"";or
    String.valueOf(int) is the better option because Int.toString() generated an intermediate object to get the endresult
    Ema

  • How to convert a string value to date

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    In your post you ask how to convert a string value to a date.  The value returned from the Get-AdUser is already a date.  It does not need to be converted.
    Bill has sshown one way to convert a date to a string and there are other methods.  You need to clarify your question.
    If you are really trying ot convert strings to dates then you can start with this:
    [datetime]'01/21/1965 13:33:23'
    Most date strings aer autodetected by the class.
    ¯\_(ツ)_/¯

  • How to convert a String to an Icon

    Hello,
    I'm trying to figure out how to convert a String (specifically one letter) to an Icon for a JTree. The program I am working on uses .png files for the icons at the moment, with each .png being a single uppercase letter. However, recent discussion has us wanting to change to something more dynamic, since we anticipate needing new letters in the near future.
    My task is to modify the current codebase so that the Icons used to identify nodes in the tree are created from a Font within code, rather than reading in .png files. I have done some experimenting with creating a Label with just that String, setting the font and trying to extract the image using calls like createImage(int width, int height) and so on, but so far to no avail.
    If I could figure out how to at least convert the String to an image, I could probably make it work (since I can play around with creating an ImageIcon with that image). Thanks in advance for any help.
    Allan

    Here is some quick and dirty code:
    import java.awt.*;
    import javax.swing.*;
    public class BasicIcon implements Icon {
        private String text;
        public BasicIcon(String text) {
            this.text = text;
        public int getIconWidth() {
            return 16;
        public int getIconHeight() {
            return 16;
        public void paintIcon(Component c, Graphics g,  int x, int y) {
            Color old = g.getColor();
            g.setColor(c.getForeground());
            g.drawString(text, x, y+13);
            g.setColor(old);
        public static void main(String[] args) {
            JPanel cp = new JPanel();
            for (char ch = 'A'; ch < 'F'; ++ch) {
                cp.add(new JButton("letter " + ch, new BasicIcon(String.valueOf(ch))));
            JFrame f = new JFrame("BasicIcon");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(cp);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }One thing that could be improved is the vertical positioning of the letter in the Icon.
    The x,y values passed into paintIcon are the upper-left hand corner of the icon,
    but the y value needed by drawString is the position of the String's baseline.
    To do it right, use one of Font's getLineMetrics methods and play around with ascent.

  • How to convert a String("yyyy-mm-dd") to the same but in Date format ?

    Hi,
    can anyone plz tell me how to convert a String to a date format.I'm using MSACCESS database.I want to store this string in the database.So i need to convert it to a date format since the table is designed such a way with date/time type for date field.I used SimpleDateFormat ,but i can't able to convert.The code is given below:
    coding:
    public String dateconvertion(String strDate)
    try
    SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdfSource.parse(strDate);
    SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd ");
    strDate = sdfDestination.format(date);
    catch(ParseException pe)
    System.out.println("Parse Exception : " + pe);
    return(strDate);
    }

    i used prepared statement even now i am getting error like this.....
    i have included the prepared statement package also...
    my coding:
    ResultSet rsdatetemp = null;
    PreparedStatement ps = null;
    String query ="select distinct itemcode from sales where bill date between ? and ?";
    ps = precon.prepareStatement(query);
    ps.setDate(1,d1);//d1 and d2 are in date format
    ps.setDate(2,d2);
    rsdatetemp = ps.executeQuery();
    error :
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(1,d1);
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(2,d2);

  • How to convert a string from upper case to lower case in FOX formula

    Hi Experts,
    How to convert a string from upper case to lower case in FOX formula?
    Thanks,
    Cheers!!!
    PANKAJ

    The last result.append( c ) should be:
    result.append( Character.toLowerCase(c) );

  • How to convert a string from lower case to upper case withour using transla

    Hi all,
    how to convert a string from lower case to upper case withour using translate,
    Thanks in Advance,
    Reddy

    Refer to this related thread
    Re: hi guys this very urgent please help

  • How to convert a String to an array

    Can somebody tell me how to convert a String to an array

    ronisto wrote:
    Can somebody tell me how to convert a String to an arrayI assume you mean to convert it into an array of the individual characters that comprise the String.
    Can you not simply look at the API documentation? Nothing in the String API jumps out at you?
    http://java.sun.com/javase/6/docs/api/index.html

  • How to swap two string variables without using a 3rd variable?

    How to swap two string variables without using a 3rd variable?
    ex.
    A = "aa"
    B = "bb"
    Result required
    A = "bb"
    B = "aa"
    Thanks

    How to swap two string variables without using a 3rd
    variable?
    Something like this.
    Append A with B (so A equals "aabb")
    Set B equal to a substring of A starting with the first character and ending at A's length minus B's length. (So B equals "aa")
    Set A equal to a substring of A starting from B's length and ending at the end of A. (So A equals "bb")

  • How to get the class name and field name dynamically

    Hi
    I have a class (ex: Contract) the fields (ex : a,b,c) .i need to get the class name and field name dynamically
    ex
    if( validation file for the field Contract.a){
    return contract.a;
    }else if(validation file for the field Contract.b){
    return contract.b;
    how to pass the field name and object dynamically
    Please help me .............
    Thanks in Advance..
    Edited by: 849614 on Aug 11, 2011 6:49 AM

    YoungWinston wrote:
    maheshguruswamy wrote:
    Agreed, but IMO, i still feel its best if there is no tie in between consumer class level details and the database it talks to. A service layer is needed in between them.Sounds like you've done a bit of this before. Me, I've either been a modeller/DBA, doling out data, or a nuts and bolts programmer (and actually more toolmaker than apps, but did a bit of that too).
    Do you know of a good book about the "middle ground" (ie, these service layers)? I understand it empirically, but haven't had a lot of exposure to it.
    Winston
    Edited by: YoungWinston on Aug 11, 2011 10:34 PM
    PS: Apologies. Edited my previous post, presumably while you were composing your reply, when I finally realized what '.filed' meant.Most of my work is in web development, never been a DBA :) . The biggest 'concern' in my shop is 'separation of concerns'. The UI group reports up to a different IT head, the DB group reports up to a different IT head and so on. The looser the coupling between these systems, the lesser the project costs (Integration, QA etc) are. Martin Fowler's books contain good information about separation of concerns in an enterprise environment. The two books which i recommend are
    [url http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420]Enterprise Application Architecture and
    [url http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683/ref=pd_sim_b_1]Enterprise Integration Patterns

  • Customize class members and methods showed by IDE

    Is anyway to customize the output of the class members and methods show by IDE when you code a class?
    In detail:
    If you have a class A:
    A myClass = new A();
    and you tipe myClass.
    then the IDE show you a list of class members and methods in a Dialog Box....
    can you customize these????????
    I want to set another output for these....
    Thanks!

    That's not the meaning of the question.....
    When someone work with a Java IDE and are editing source, the IDE help you writing code showing you the members and methods of the object that you are working on, like these:
    a.------------------------
    | void setX(int x) |
    | void setY(int y) |
    These information is provided by the IDE. I think that it makes a special type of introspection on classes ..... but a really strong one, because it can access to private members and methods....
    I want to customize these behaviour....... and i want the IDE's show only the strings that i want....
    For exemple:
    a.------------------------
    | to establish X |
    | to establish Y |
    Thanks!

  • Track public classes, interfaces and methods by ID

    Hi All,
    I'm wondering whether there is a tool to assign a unique ID to classes, interfaces and methods (eg. within Javadoc) and track these IDs.
    The reason I'd need such a feature is that I'd like to do requirements tracking in an easy but complete way. I have a document containing functional specifications (with IDs) and on the other side there is the source code; where the javadoc of the public methods and classes is my software specification. What I now want to do is make a link between the IDs in the functional spec to the IDs in the sofware spec (ie. the source code).
    Does anybody know of such a tool (commercial or not)?
    Thanks,
    Daniel

    I'm a bit confused as to whether or not I understand you correctly. Please tell me if the following pseudocode is somewhat like the solution you are looking for:
    class MethodFunctionality {
       private Class methodClass;
       private String methodSignature;
       private List methodFunctions;
        *   Returns true if the method is used for the specified
        *   requirement, false otherwise.
       public boolean fulfills(int requirementId) {
          if methodFunctions.contains(requirementId)
             return true;
          else
             return false;
       public String getMethodSignature() {
          return this.methodSingature;
       public Class getMethodClass() {
          return this.methodClass;
        *   Returns an array with IDs of each functional
        *   requirement covered by the method.
       public int[] getCoverage() {
          return this.methodFunctions;
    class ClassFunctionality {
       private Map methodDetails;
       private List classFunctions;
       public MethodFunctionality getMethodDetails(String methodSignature) {
          return (MethodFunctionality) this.methodDetails.get(methodSignature);
        *   Returns true if the class is used for the specified
        *   requirement, false otherwise.
       public boolean fulfills(int requirementId) {
          if classFunctions.contains(requirementId)
             return true;
          else
             return false;
        *   Returns an array with IDs of each functional
        *   requirement covered by the class.
       public int[] getCoverage() {
          return this.classFunctions;
    }Mapping classes and methods to functionality like this would both allow you to query each class and method for all the functional requirements they claim to cover and would allow you to collect all classes and methods involved for a particular functional requirement.

  • How to add a service account in SQL Server to display the "Service Account Name" and "Display Name"

    Can someone
    help with steps on how to add the following in SQL Server 2012 environments?<o:p></o:p>
    "Service Account Name" and "Display Name"<o:p></o:p>
    Your help will be greatly appreciated.<o:p></o:p>
    leonie6214

    Hello,
    Is the following article what you are looking for?
    http://msdn.microsoft.com/en-us/library/ms345578.aspx
    If not, could you explain a little bit more what you want to accomplish?
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

Maybe you are looking for

  • Windows 7 XP Mode BIOS set up?

    Anybody using the beta version of Windows XP mode under Windows 7? I got as far as verifying that my processors do in fact allow for "hardware virtualization" but when I attempted to follow instructions to enable this feature, I could only find instr

  • Administrative user can't access other accounts or delete remote login

    I have the administrative user account on my iMac at home. My daughter can't remember the new password I assigned her and needs me to change it. When I log into system preferences/accounts, it shows that I am the administrative user. However, when I

  • Merging data without MobileMe

    I have a MacBook, an iMac and a iPhone 3Gs. Currently, I use MobileMe to sync my calendars and contacts over all three devices, but it's time to renew and frankly, it's a bit above my budget. I know that if I want to merge things that I've entered in

  • Migration Characterset Issue

    Hi, I am involved in a Data Migration project. The database version I am using is Oracle 10.2.0.5 and the NLS_CHARACTERSET is set to UTF8 on the database. The requirement is to provide the data extract in Unicode for the new databse. I have set the N

  • TOP questions - start here

    My Nokia device is not functioning properly. Always make sure that you have the latest software version in your Nokia device. You can update the software yourself using Nokia Software Updater, Nokia's free PC software. Learn more and download Nokia S