aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper class" Watch "Wrapper class" New topic
Author

Wrapper class

pravin kumar
Ranch Hand

Joined: Nov 03, 2005
Posts: 30
public class Lukeg{
public static void main(String argv[]){
Lukeg lg = new Lukeg();
lg.go(argv);
}
public void go(String[] argv){
Integer wiNumber = new Integer(argv[0]);
int i = wiNumber.intValue();/// here
i = i * 2;
System.out.println(i);

}
}

[b]In above code how come value of i (in bold i) becomes 1 which in results in 2 as final output
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Could you clarify your question? argv[0] is the first entry after the class name on the command line when you interpret it.
pravin kumar
Ranch Hand

Joined: Nov 03, 2005
Posts: 30
Integer wiNumber = new Integer(argv[0]);

what is value of wiNumber here?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
wiNumber is not a primitive data type, it's an object reference. Integer is a subclass of Number which defines various methods, intValue(), byteValue(), shortValue(), doubleValue(), etc. So wiNumber itself does not have a value. It is a reference to an object which should have at its core an int.

However, there is no way to know what that int value will be unless you know what is being sent it on the command line. args[0] (or whatever you call the String array parameter in your main method) refers to the first String sent it on the command line when the program is interpreted.
pravin kumar
Ranch Hand

Joined: Nov 03, 2005
Posts: 30
well probably it may sounds stubborn but i just want to know how come value of the i=1 here in the example


Integer wiNumber = new Integer(argv[0]);
int i = wiNumber.intValue();/// here
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You would have to do something like this.

java Lukeg 1
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The program itself will throw a RuntimeException if you don't include at least one token on the command line.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper class
 
Similar Threads
overloading
equals()
GC Question from Marcus Green
Var args question...
5 Golden Rules of widening, boxing & varargs