Finding the class to which an object belongs

Let us have an object.
How can one find whether it is an
instance of an user defined class
or the one defined in any one of
java.* packages?
Thanks in advance.

Two ways:
1. You can use Java Reflection API (see Java tutorial).
2. Short and simple way:
Object x = new java.util.ArrayList();
if (x instanceof java.util.Collection) {
System.out.println("Bingo!");
} else {
System.out.println("Impossible!!!");
if (x instanceof Integer) {
System.out.println("Impossible!!!");
Basically, it will never print out "Impossible!!!"
I don't recomends using .getClass().getName().equals( some class name ), it is dirty. Keyword instanceof works for inheritance using class/ abstract class and interface.
rgds,
Alex

Similar Messages

  • 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

  • From which table I can find the "Class type" and "Class" of the material?

    From which table I can find the "Class type" and "Class" of the material?
    Thanks in advance for the answers....

    Hi,
    try following table
    KSSK     Material number to class     
    KLAS     Class description     
    KSML     Characteristic name     
    CABN/CABNT     Characteristic name description     
    CAWN/CAWNT     Characteristic name
    [http://www.sap-img.com/materials/classification-view-of-material-master.htm]
    [http://wiki.sdn.sap.com/wiki/display/ERPLO/FrequentlyUsedTables]
    Regards
    kailas Ugale

  • Which Table, can I find the class and characteristic assigned to equipment.

    Hi all,
    I have assigned a characteristc to a class.
    And assigned this class to an equipment.
    Now in which table can i find the class assigned to this equipment.
    What is the logic to find the class and characteristic.
    Thanks in advance.
    Piyush

    Hi,
    As per above post, you can find classes. To find characteristics, Give EQUNR value in OBJEK field in AUSP table & get the ATINN value.
    Give ATINN value in ATINN field in CABN table & get ATNAM field value.
    In AUSP table, you can get the values against each characteristics as well.
    Regards,
    Maheswaran.
    Edited by: Maheswaran.K on Apr 19, 2011 9:28 AM

  • FM/Class to find the class and characterstics for a given material

    Hi All,
    Is there any Class/FM to find the class and characterstics for a given material.I tried some BAPI_OBJCL* BAPI's but lot of the BAPI's need classnum as input parameter. But i need a BAPI or tables or class which can give the class and its characterstic values for a given material.

    Hi Ben
             Try ..
    BAPI_OBJCL_GETCLASSES
    BAPI_OBJCL_CREATE

  • How can we find the Idoc number which posts the material document in SAP

    Hi All,
    How can we find the Idoc number which posts the material document in SAP. We could not able to find the IDOC number from the material document which was posted by Idoc.
    Thanks
    Chandru

    Hi,
    In MIGO you can go to service of object(Just above show overview) and check 5th option workflow you will find the idoc number.
    regards
    suresh

  • Cannot find the class file

    Hi All,
    Can any one help me regarding the issue?
    Error:
    package com.support.misc.feedback
    I am getting the following error for the above line. But I have created the Hierarchy in folder structure. But still it is throwing the error.
    1. Cannot find the class file for com.sapportals.htmlb.page.DynPage
    2. This compilation unit indirectly references the missing type com.sapportals.htmlb.page.DynPage (typically some required class file is referencing a type outside the class path)     FeedbackBean.java
    Thanks in Advance.
    Message was edited by: Gowsika Kannan

    Hi Gowsika,
    the class needed is located in htmlb.jar which can be found under <irj-root>/WEB-INF/portal/portalapps/com.sap.portal.htmlb/lib
    You need to integrate this jar in your .classpath
    Hope this helps,
    Robert
    PS: Please do not post the same question 3 times

  • 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();
    }

  • Cannot find the class!! - URGENT!!!

    I have an JSP archive and I�m using the Tomcat 4. I did a class named ConnectionBean that connect with a database.
    when i start my JSP, the Apache server show me an error page that say it�s impossible to find the class "ConnectionBean". I tryed to put it in the same directory of the JSP file, but happened the same error.
    I tryed to put it in the directory "apache tomcat 4\lib\" but i have the same error.
    I tryed to put it on the directory "jre\lib\ext\ of my JVM, but i have the same error!
    Please, somebody can help me to do my JSP find this class?
    Thanks for all

    after you compile your class you should put the .class in the WEB-INF/classes/ directory
    lets suppose that you wrote in the top of your class
    package com.mydbconnection
    this means that your class should be in
    WEB-INF/classes/com/mydbconnection/MyClass.class
    in your JSP have been like this
    <jsp:useBean id="DBConn" scope="page" class="com.mydbconnection.MyClass" />
    hope this help enough :)

  • Cannot find the class file for com.sap.portal.services.api.connectorgateway

    Hi,
    I was trying the "How to BI JAVA SDK in a Portal iView and get the following error.
    The project was not built since its classpath is incomplete. Cannot find the class file for com.sap.portal.services.api.connectorgateway.IConnectorGatewayService. Fix the classpath and try rebuilding this project.
    I have the following in my portalapp.xml file
    <property name="SharingReference" value="com.sap.portal.ivs.connectorservice"/>
    and i have also added the jar file "com.sap.portal.ivs.connectorservice_api" in the set of lib's
    Has some faced a similar issue? or can someone suggest how I could possibly resolve this.
    Thanks,
    Smitha

    Hi Smitha:
       My webdynpro dc was build failed for "This compilation unit indirectly references the missing type com.sap.engine.services.webservices.espbase.client.dynamic.content.GenericObject (typically some required class file is referencing a type outside the classpath)".
    How should i do?  Thank you!

  • TS1424 there are 43 available apps' update  which couldn't be made with my current account. How i can find the account with which i bought them in order to update them

    there are 43 available apps' update  which couldn't be made with my current account. How i can find the account with which i bought them in order to update them

    Use get info in iTunes on your Mac.

  • How can i find the file to which Session Manager has saved my session ?

    How can I find the file to which Session Manager has saved my session ?
    == This happened ==
    Every time Firefox opened
    == User Agent ==
    Opera/9.80 (Windows NT 6.0; U; en) Presto/2.5.24 Version/10.53

    From
    http://support.apple.com/en-us/HT4946
    Where your backups are stored
    The folder where your backup data is stored depends on your computer's operating system. Make sure the backup folder is included in your data-backup routine. iTunes places the backup files in these places:
        Mac: ~/Library/Application Support/MobileSync/Backup/
        The "~" represents your Home folder. If you don't see Library in your Home folder, hold Option and click the Go menu.
        Windows Vista, Windows 7, and Windows 8: \Users\(username)\AppData\Roaming\Apple Computer\MobileSync\Backup\
        To quickly access the AppData folder, click Start. In the search bar, type %appdata%, then press Return.
        Windows XP: \Documents and Settings\(username)\Application Data\Apple Computer\MobileSync\Backup\
        To quickly access the Application Data folder, click Start, then choose Run. In the search bar, type %appdata%, then click OK.
    See here for how to backup
    Back up and restore your iPhone, iPad, or iPod touch using iCloud or iTunes - Apple Support

  • How can I find the yahoo toolbar which contains "identity safe" which contains all of my passwords?

    I can't find the yahoo toolbar which included identity safe, where all my automatic passwords were located.

    While Finder is active, press Command-F (Find in the File menu).
    In that window you can set search criteria. In the second sub-toolbar should be a couple of buttons representing pulldown menus; by default, the first usually shows "kind". Click that one.
    In the menu that opens, if "Size" or "File Size" is not available, select "Other". Then in the new window select "Size" or "File Size" and okay the window. From then on that choice will be available in the first pulldown menu.
    You can use that to search your drive.
    Note - by clicking the "+" button at the far right of the strip containing the pulldown menus, you can add additional search criteria, thus restricting a search to exactly what you want.

  • InCopy workflow in InDesign: Is there a way to find the document in which an ICML file has NOT been checked IN again before saving the doc?

    The situation:
    We are working with the InCopy feature (checking in and checking out ICML files).
    The problem:
    I might have saved a document with an ICML file still checked out.
    The question:
    Is there a way to find out which document was saved with the ICML file still checked out?
    or in other words:
    Is there a way to find the document in which an ICML file has NOT been checked IN again before saving the doc?
    Thanks for any help!

    Hello Sumit Singh,
    thank you for your answer and your reasonable recommendation. Unfortunately, this only works when the ICML content is used in one INDD file. In our case, we use ICML content in multiple docs (various manuals with the same safety instructions, warranties, adresses etc.).
    So, is there a way to trace back where an ICML has been used?
    Is it possible to find out in which document the ICML is still checked out?

  • Need  to find the class type for a material

    Hi all,
    i need to find the class type for the material.
    is there any FM or the table where i have both MATNR and KLART fileds.
    Kindly reply asap.
    Thanks
    Sri

    Hi,
    There can be multiple class types assigned to a material. You can view this in the classification tab in the material master transaction.
    You can pass the MATNR to OBJEK field of KSSK table after using neccessary converison Exit to get KLART(Class Type). It will return you a 3 digit Class type. You can find the description of the class from the class type master table TCLA.
    Hope this helps.
    Edited by: Priyabrata Samanta on Feb 11, 2008 11:43 PM

Maybe you are looking for

  • Home Office Server setup question: re RAID or not on Mac Mini Server

    I recently purchased a Mac Mini with OS X Server (10.6) for my home office. I also have an AEB. Is there any point in configuring the 2 500G disks as a RAID 1 setup? Given Time Machine backup and an inability to easily open it up and replace in case

  • Import Spreadsheet returns error

    Hi, I'm trying to import excel spreadsheet. For one file it works and for another it doesn't. On examination I found that the one that doesn't work has got filters applied on some of it's columns. Is this the reason that it doesn't work. Can anybody

  • File delete error k3 note k50a40 Indian version

    In Indian version of k3 note files downloaded by uc browser getting automatically deleted along with sometime whole internal memory. Is their any way to resolve this problem , I also replaced it once but I think it is compatibility issues. APPS NOT W

  • Which types of errors occured in "source system"?

    hi which types of errors occured in "source system"? how will correct it? send me data on it

  • Installing Old Version of iLife?

    If I were to install iLife 06 from its install disk on a MBP that had iLife 09 pre installed, does the old version over-write the newer one? (I seem to recall that when I upgraded from 06 to 08 on my iMac, at least some of the files were over-written