• Post Reply Bookmark Topic Watch Topic
  • New Topic

Differentiate the System classes and user defined classs  RSS feed

 
Vimlesh Kumar Patel
Greenhorn
Posts: 20
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q. > How Can I differentiate the System classes and user classes in my program written below by another program?

/**
* Employee Class containing all non-primitive data types.
*
*/


Can someone tell me any Technique that will decide which one of the fields (Integer, Address, DOB, String, Float) are user defined type.
(Note: An outsider class should used that will identify the Java classes and the user-defined classes.)
 
Joseph Mokenela
Ranch Hand
Posts: 71
Eclipse IDE Hibernate Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you take a look at the Java Documentation to have a grasp of Java classes and how they work together.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

This forum is for discussion of the Ranch itself; I shall try moving you to a more appropriate location.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The predefined classes in Java® are not called System classes. System classes run the computer.
You could try xxx.getClass().getName() and look at the package name in the class name, where xxx is any field which is a reference type. You can find the package name by finding the last index of "." and then substring(0, index). That will throw a nice Exception if you have no package names and index is −1
 
Vimlesh Kumar Patel
Greenhorn
Posts: 20
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Friends! finally I got the solution. now I can differentiate between built-in classes and user-defined classes.
 
Vimlesh Kumar Patel
Greenhorn
Posts: 20
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code which will differentiate the Types.


This can be tested with my Employeee class which is written previously.

Please suggest me Ideas if something better can be done with these techniques.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vimlesh Kumar Patel wrote:Please suggest me Ideas if something better can be done with these techniques.

I fear that it will only work for final classes (like String), since otherwise you can have a List<Supertype> and then store subtypes in it, so it will return the result for whatever subtype object you happened to get when you ran it.

There is a web page out there that does offer a solution for this that uses proper Types (java.lang.reflect.Type), but it's quite involved, so I've never really given it much thought. I've also forgotten where I saw it (Alzheimers), but if I remember, I'll post it.

Perhaps the question you should be asking yourself is: Why would I need this? Java Generics isn't a 100% solution, but when I find myself obsessing about things like this, it's usually because I'm not thinking things through properly - or sometimes overthinking them.

Winston
 
Vimlesh Kumar Patel
Greenhorn
Posts: 20
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Friends a got the solution. I have also used (java.lang.reflect.Type) that works fine.

Thank you all.


Vimlesh Patel
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!