Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links


Get Object Class Name At Runtime In Java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 22-02-2010
Member
 
Join Date: Nov 2009
Posts: 880
Get Object Class Name At Runtime In Java

Sponsored Links
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.

Reply With Quote
  #2  
Old 22-02-2010
Member
 
Join Date: May 2008
Posts: 2,000
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());
}
}
Reply With Quote
  #3  
Old 22-02-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,989
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.
Reply With Quote
  #4  
Old 22-02-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,278
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); 
      }
   }
}
Reply With Quote
  #5  
Old 22-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,382
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();
}
Reply With Quote
  #6  
Old 22-02-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,507
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());
  }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Get Object Class Name At Runtime In Java"
Thread Thread Starter Forum Replies Last Post
Getting HP AIO Device object server register class object failed message on my system Donoho Hardware Peripherals 6 06-06-2011 01:34 AM
Converting java class to java bean class Ucchal Software Development 6 09-08-2010 10:24 AM
Runtime error 429: Activex Component Can't create object Hina Naz Vista Help 2 01-06-2010 04:00 AM
Solution for Runtime Error 429 : ActiveX Component Can't Create Object Shell Tips & Tweaks 2 25-12-2008 02:01 PM
Object test = new Object() <-- Java, best way in C++ ADISH Software Development 3 25-10-2008 02:32 PM


All times are GMT +5.5. The time now is 11:54 AM.