This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data type in java

 
kamalkant rajput
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I wanted to know is there any API in java by which I can know the type of data is coming e.g. whether it is Integer,String ,Boolean etc.
thanks in advance
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "the data that is coming" - where is it coming from? In what format? Apparently not from inside of a JVM?
 
kamalkant rajput
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply,
My problem is like that suppose i am having a class from which i am getting an object but i don't what is data type of member variables.
I wanted to know the data type of member variables.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean the method returns a java.lang.Object? You can get at the class name through obj.getClass().getName() - that'll return the fully qualified class name.

You can also check for particular classes as follows:
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A major point of Object-Oriented programming is that you DON'T know the types of the instance variables.

the Java introspection APIs could help you out, but you should probably be solving your problem in some other way,

if you want more detailed answers, provide an example of the problem you are having,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic