aspose file tools*
The moose likes Beginning Java and the fly likes Integer class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Integer class" Watch "Integer class" New topic
Author

Integer class

Ramakrishnan Ponmudi
Ranch Hand

Joined: Apr 20, 2004
Posts: 72
what value Integer.TYPE can contain?
why it is of type java.lang.Class?
what is the use of this TYPE class variable - explain detail.
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Integer is basically a wrapper class. It can hold the value of any int type variable.
At some places we require the Integer instead of int.
Suppose i have a class as following
Class A{
Integer var1; //here i used Integer instead of int
String var2;
public void setVar(Object obj){ //I don't know what type of value the user will provide
if(obj instanceof Integer){
var1 = obj;
}else if(obj instanceof String){
var2 = obj;
}
}
}
In the above scenerio i shall have to use the Integer class instead of int.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

The APIs in the java.lang.reflect package let you investigate a class at runtime to determine its methods, fields, superclass, etc. A java.lang.reflect.Field object, for instance, represents a specific member or class variable or a specific class. Field has a getType() method which returns java.lang.Class; this Class object represents the type of the field. For reference types (i.e., Object and all its subclasses) there's already a Class object to use; in the past, though, there were no Class objects to represent the primitive types. So in JDK 1.1, when java.lang.reflect was added, the Class constants TYPE in Integer, Short, Byte, Long, Character, Float, and Double were added to serve this purpose. There's also a Void class, whose purpose is mainly to serve as a container for the Class object which represents "void" (used by the java.lang.reflect.Method class to represent a void return value.)


[Jess in Action][AskingGoodQuestions]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

I'm going to move this to the Java In General(beginner) forum, seeing as though you have several other threads there of a very similar nature.


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integer class
 
Similar Threads
check this qn
Page 414 - HFSJ
wrapper classes
Return type of MyClass.class
type attribute of jsp:useBean action