Results 1 to 6 of 6

Thread: Get Object Class Name At Runtime In Java

  1. #1
    Join Date
    Nov 2009
    Posts
    877

    Get Object Class Name At Runtime In Java

    Hello, I am learning java programming language. I have search for the code which will provide me help for Getting Object Class Name At Runtime. If you know the details or solution from which I can achieve it, then please help me to get that. I will be thankful to you.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Get Object Class Name At Runtime In Java

    Hey, simply make use of the program below and get your problem solved:
    Code:
    import javax.swing.text.html.HTML;
    import java.lang.management.RuntimeMXBean;
    public class CheckAtRuntime 
    {
    public static void main (String args[]) 
    {
    HTML HObj = new HTML();
    System.out.println("Class object From HTML using getClass method = " + HObj.getClass());   
     try 
    {
    System.out.println("Class object From HTML using Class.forName method = " + Class.forName("javax.swing.text.html.HTML"));       
    } 
    catch (Exception e) 
    {
    e.printStackTrace();
     }
    System.out.println("Class object From HTML name using getName method = " + HObj.getClass().getName());
    System.out.println("RuntimeMXBean Class Object using RuntimeMXBean.class = "+ RuntimeMXBean.class);    
    try 
    {
    System.out.println("RuntimeMXBean Class Object using Class.forName method = "+ Class.forName("java.lang.management.RuntimeMXBean"));       
    } 
    catch (Exception e) 
    {
    e.printStackTrace();
     }
    System.out.println("RuntimeMXBean Class Object name using getName method = "+ RuntimeMXBean.class.getName());
    }
    }

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Get Object Class Name At Runtime In Java

    Hello, if you are making use of the java programming language then you will able to fine the way to enable to get the object class name at runtime. If you know the method getClass() in java then you can simply use it in your program and get solved your problem. For that you just need to call the getClass() method on the class object. After calling the getClass() method you just need to use the call to the method getName() in your program. And from that you can get the name of the object class.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Get Object Class Name At Runtime In Java

    If you want to get the type name at runtime in c# then you can use the program of code below:
    Code:
    using System;  
    class Testing
    {
       class check 
       {    
          static void ShowTypeInfo (object obj) 
          { 
          Console.WriteLine ("type name = {0}, 
             full type name = {1}", obj.GetType(), 
             obj.GetType().FullName ); 
          } 
          public static void Main()
          { 
             long LType = 99; 
             Testing ex= new Testing(); 
     
             ShowTypeInfo (ex); 
             ShowTypeInfo (LType); 
          }
       }
    }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Get Object Class Name At Runtime In Java

    Hey, I have got the program below. So, just check it, whether it is useful to you or not:
    Code:
    public void checking()
    {
    Long nlong = null;
    addParameter(nlong);
    }
    public void addParameter(Object value) 
    {
    String pType = value.getClass().getName();
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Get Object Class Name At Runtime In Java

    Hello, I have the solution program for your finding Object class name at runtime. You can use the below program and solve your problem. So, just make use of it.
    Code:
    import java.lang.Class;
    public class runtime
    {
      public runtime()
    {
        System.out.println("In Constructor");
      }
      public static void main(String args[])
      {
        runtime obj = new runtime();
        System.out.println("Object's Class name =>"+ obj.getClass().getName());
      }
    }

Similar Threads

  1. Replies: 6
    Last Post: 06-06-2011, 01:34 AM
  2. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  3. Replies: 2
    Last Post: 01-06-2010, 04:00 AM
  4. Replies: 2
    Last Post: 25-12-2008, 03:01 PM
  5. Object test = new Object() <-- Java, best way in C++
    By ADISH in forum Software Development
    Replies: 3
    Last Post: 25-10-2008, 02:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,486,716.61574 seconds with 17 queries