How to find the class name, the location from where it invoked a method

Hi,
I have a class A. The caller calls A.someMethod(), whenever this method is invoked, I want to find out the caller info, which class invoked this method, from where this class was loaded (may be the jar file name). Any help will be appreciated.
Thanks.

However since version 1.4 there is an easier way to extract that information from the Throwable:
java.lang.Throwable
public StackTraceElement[] getStackTrace()
Provides programmatic access to the stack trace information printed by printStackTrace(). Returns an array of stack trace elements, each representing one stack frame.

Similar Messages

  • How to find out class name

    Hi folks,
    Can anybody help me, I got stuck on this problem.
    I need to find out the className of the class, which is specified
    by ordinary filename.
    In other words:
    User gives me filename (something.class) and I need to find out
    classname (I just need to create an instance of this class)
    Thanks a lot.
    sgtPepper

    This will read the class name from a class file.
    * @author Ian Schneider
    public class JavaClassName {
        public static void main(String[] args) throws Exception {
            DataInputStream din = new DataInputStream(new FileInputStream(args[0]));
            int cafebabe = din.readInt();
            if (cafebabe != 0xcafebabe)
                throw new Exception("Not class file");
            din.skip(4);
            int cnt = din.readShort() - 1;
            Object[] info = new Object[cnt];
            for (int i = 0; i < cnt; i++) {
                int b = din.readByte();
                switch (b) {
                    case 1:
                        info[i] = din.readUTF(); break;
                    case 3: case 4: case 9: case 10: case 11: case 12:
                        din.skip(4); break;
                    case 5: case 6:
                        i++;
                        din.skip(8); break;
                    case 7: case 8:
                        info[i] = Short.valueOf(din.readShort()); break;
                    default:
                        assert false;
            din.skip(2);
            int off = din.readShort();
            Number ptr = (Number) info[off - 1];
            System.out.println(info[ptr.intValue() - 1]);
            din.close();
    }

  • How to find the class name of the  BO

    HI
      How to find out a class for a business object.
    For example for the Business Object FORMABSENC i want to find out the class name.
    iam not able to find out from se24 or swo1.
    Or please suggest me how can i use the method createbapistructure of this businessobject.
    Regards
    vijaya

    Hello Vijay
    When you double-click on "method" AbsenceForm.CreateBapiStructure (transaction SWO1) and switch to tab ABAP you see (on ERP 6.0) that the field Name is empty meaning this BO "method" has not yet been implemented.
    Other methods are implemented by modules of function group SWXA. Checking package SWX you will see that there are no suitable classes around for this object.
    Final remark: Methods of business objects has just a semantic meaning and has nothing to do with object orientation (i.e. classes).
    Regards
      Uwe

  • How to get the class name  static method which exists in the parent class

    Hi,
    How to know the name of the class or reference to instance of the class with in the main/static method
    in the below example
    class AbstA
    public static void main(String[] args)
    System.out.println(getXXClass().getName());
    public class A extends AbstA
    public class B extends AbstA
    on compile all the class and run of
    java A
    should print A as the name
    java B
    should print B as the name
    Are there any suggestions to know the class name in the static method, which is in the parent class.
    Regards,
    Raja Nagendra Kumar

    Well, there's a hack you can use, but if you think you need it,Could you let me the hack solution for this..
    you probably have a design flaw and/or a misunderstanding about how to use Java.)May be, but my needs seems to be very genuine..of not repeat the main method contents in every inherited class..
    The need we have is this
    I have the test cases inheriting from common base class.
    When the main method of the test class is run, it is supposed to find all other test cases, which belong to same package and subpackages and create a entire suite and run the entire suite.
    In the above need of the logic we wrote in the main method could handle any class provided it knows what is the child class from which this main is called.
    I applicate your inputs on a better way to design without replicating the code..
    In my view getClass() should have been static as the instance it returns is one for all its instances of that class.
    I know there are complications the way compiler handles static vars and methods.. May be there is a need for OO principals to advance..
    Regards,
    Raja Nagendra Kumar
    Edited by: rajanag on Jul 26, 2009 6:03 PM

  • How to get the Class name of an API method?

    Like most of us, it's difficult to know where every method within a Java class is. Also, many of the same methods are scattered throughout Java Classes. I know of two methods that retreive this... getClass().getName(). But, you must have an object to use these. Is there a way to find out what Class contains a method or Class variable thru an Applet or Java Application?? Obviously, I can look at API Docs; but this takes time.
    Tks Randy

    RajEndiran wrote:
    Can anyone please let me know how we can get the class name of a page or region in oracle apex?What do you mean with class name? The name of the template (e.g. the css style class name)?
    I would also like to know how we get the DOM object ID for particular item.Use firebug or inspect the source code of the rendered page to see the object IDs. Other then then, the typical ID of page items is the name of the item. For regions you can set your own ID.

  • How to find workarea ID for the work area name.

    Hi Experts..
    How to find workarea ID for the work area name.(Work area name CCIHT_WAH-WAID and I want to fetch characteristic data from table AUSP matching the OBJEK field,but I only have Work area name).Can anybody help me to find tables or relationship between Workarea ID and Workarea name for the same.I am using TCODE - CHIB02.Once I select a workarea and click on IHS Data button,I get data for that workarea.I need to find where this data comes from and How is this fetched.
    Points would be rewarded for helpful answers..
    Thanks
    Kunal Halarnakar

    U want to fetch the workarea description ?
    we can fetch it from CCIHT_WALD table with the RECN value.
    The informations are stored in AUSP table with the characterstic(ATINN) value.

  • How to find out table name for the field in the webUI

    Hi.
    I am in CRM2007.
    So i go to the transaction code    BSP_WD_CMPWB
    In that i provide the component name as CRM_UI_FRAME.
    I press the Test button.
    So, it opend the WebUI.
    I want how to find out table of the particular input field?
    I mean from which table the data is retrived how to find out?
    When i enter some thing in the input field how to find out in which table that data is stored?
    By pressing F2 on the input field it opend View and Component Name.
    I want find out table of that particular field. How to find it?
    If anybody know about this explain it with Screen shorts if possible.
    Thank You.
    Krishna. B.

    hi
    goto tx genil_model_browser. Suppose you want to find fields reated to your order header eg sold to name. In component set write all and press F8. Then goto access object and in access object click on node BTAdminH. Click on attribute structure. Here you will find structure and attributes. If you click relationship then you will see all the relationship wrt btadminh. open any r/s that you require. and click on other object and attribute. You will get to know the structure.
    Best regards
    Pankaj kumar

  • How to find out what are the functions supported by string class

    Hi,
    Can any one let me know how to find what are all the functions supported by the string class in standard(STL) library on solaris.
    Regards,
    Vignesh

    1. Any C++ textbook that covers the Standard Library will tell you about the standard string class. A good tutorial and reference for the entire Standard Library is "The C++ Standard Library" by Nicolai Josuttis, published by Addison Wesley.
    2. WIth Sun C++, the command
    man -s3C++ basic_string
    provides documentation for the default libCstd version of the Standard Library.
    3. You could look at the <string> header itself. I don't recommend that approach.

  • How to get the class name of a page in oracle apex

    Hi All,
    Can anyone please let me know how we can get the class name of a page or region in oracle apex? I would also like to know how we get the DOM object ID for particular item.
    I appreciate any help on this.
    Regards
    Raj

    RajEndiran wrote:
    Can anyone please let me know how we can get the class name of a page or region in oracle apex?What do you mean with class name? The name of the template (e.g. the css style class name)?
    I would also like to know how we get the DOM object ID for particular item.Use firebug or inspect the source code of the rendered page to see the object IDs. Other then then, the typical ID of page items is the name of the item. For regions you can set your own ID.

  • How to find out query name using Elements of the query builder.

    Hi SDNers,
    how to find out query name using Elements of the query .
    thanks,
    satyaa

    Hi,
    For having a look at the relation between BEx tables,check the link below:
    http://wiki.sdn.sap.com/wiki/display/BI/ExploretherelationbetweenBEx+Tables
    -Vikram

  • Find the Class Name in a static method

    Hi All,
    I am trying to find the class name inside the static main method. I want to write one main method that loads an instance of the class. Other folks have suggested tricks with the security manager or creating an Exception to look at the stack trace, but these methods don�t reflect the inheritance. I want SUBCLASSES to be able to run from the command line using the inherited main method.
    public static void main(String args[]){
          JPanel thisJPanel = (JPanel) Class.forName(????).newInstance();
    }Any Ideas

    I want
    SUBCLASSES to be able to run from the command line
    using the inherited main method.Someone pointed this out already but more directly, static methods are not inherited.
    The behavior you desire ca be achieved using the Factory pattern.
    The idea of being able to subclass an application is a little bizarre. Why don't you just do something like this:
    public static void main(String[] args){
        // check that there is at least one parameter 
        JPanel thisJPanel = (JPanel) Class.forName(args[0]).newInstance();
    }

  • How to know the class name in .ser file?

    Hi,
    I have a .ser file, could any expert help me to find out all the classes in the .ser file? Thanks!

    If you have written them as Object, then you can just read them one by one with an ObjectInputStream and when you have the object, you can print out the class name:
    Object o = in.readObject();
    if (o != null)
      System.out.println(o.getClass().getName());
    else
      System.out.println(null);

  • How to i get the class name ? please help me

    hi friends
    i want to know how to get the class name from my java program
    public class sample
    public static void main(String args[])
    how to i get sample.
    please help me.
    thanks in advance                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I can't recall which forum member gave the following solution, but it works
    in static contexts and it's copy-and-paste friendly -- you don't hard-code the
    name of the class, only a dummy class that you use to make this hack work:
    public class Foo {
        private static class Dummy{}
        public static void main(String[] args) {
            Class cls = Dummy.class.getEnclosingClass();
            String name = cls.getName();
            System.out.println(name);
    }

  • 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

  • Query to find the class name that has the maximum number of students ?

    I need the query to find the [class Name] which has the most number of students. please look below at the tables
    Students Table                                                                     
    StudentId     StudentName  ClassID                                    
    1                  xxx                   1                                           
    2                  yyy                   1                                           
    3                  zzz                   1  
    4                  fff                    2
    5                   ttt                  2
     Classes Table
     ClassID          ClassNane
     1                    CSHARP
     2                    JSHARP
    The result should be : CSHARP
    since there are 3 students in CSHARP and 2 students in JSHARP class
    Appreciate your help
    Thanks

    Try:
    DECLARE @Classes TABLE (
    ClassID INT identity(1, 1) PRIMARY KEY
    ,ClassName VARCHAR(50)
    INSERT INTO @Classes (ClassName)
    VALUES ('CSharp')
    ,('JSharp')
    DECLARE @Students TABLE (
    StudentID INT identity(1, 1) PRIMARY KEY
    ,StudentName VARCHAR(10)
    ,ClassID INT
    INSERT INTO @Students (
    StudentName
    ,ClassID
    VALUES (
    'xxx'
    ,1
    'yyy'
    ,1
    'zzz'
    ,1
    'fff'
    ,2
    'ttt'
    ,2
    SELECT TOP (1)
    WITH TIES C.ClassName
    FROM @Classes C
    INNER JOIN @Students S ON C.ClassID = S.ClassID
    GROUP BY C.ClassID
    ,C.ClassName
    ORDER BY COUNT(S.StudentID) DESC
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

Maybe you are looking for