473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

type wrappers in java

what is meant by the term type wrappers .And what is their us in java programming .
For example
import java.util.*;
import javax.swing.JOptionPane;
public class Numyears
{
public static void main(String[]args)
{
GregorianCalendar current=new GregorianCalendar();
int currentYear;
int birthYear;
int numYears;
birthYear=Integer.parseInt(JOptionPane.showInputDi alog
(null,"in what year were you born?",JOptionPane.QUESTION_MESSAGE));
currentYear=current.get(Calendar.YEAR);
numYears=currentYear-birthYear;
JOptionPane.showMessageDialog(null,"you will turn"+numYears+"years old",JOptionPane.INFORMATION_MESSAGE);
system.exit(0);
}
}
Aug 14 '07 #1
2 1542
JosAH
11,448 Expert 8TB
Pardon my blindness but I don't see any wrappers in your code.

kind regards,

Jos

ps. for a good wrapper/decorator example see all the InputStream classes.
Aug 14 '07 #2
Yeah, you didn't use any wrappers in your example but still...
They can be used to make objects out of your primitives. This is useful if you are using some non generic collections (those without <T>) or if you in any way intend to pass your primitive value to a method expecting an object.

example:

Expand|Select|Wrap|Line Numbers
  1. //...
  2. int somePrimitive=1;
  3. java.util.ArrayList aList=new java.util.ArrayList();
  4.  
  5. //the right way:
  6. aList.add(new Integer(somePrimitive));
  7.  
  8. //this would cause an exception:
  9. //aList.add(somePrimitive);
  10. //...
  11.  
ou yeah, AND they can be used as mentioned in previous post to wrap the functionality of a more general type, as in:

Expand|Select|Wrap|Line Numbers
  1. DataInputStream dis=new DataInputStream(new FileInputStream("someFile.txt"));
  2.  
Aug 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Terje Slettebø | last post by:
Hi. I'm new here, and sorry if this has been discussed before; I didn't find it searching the PHP groups. (I've also read recommendations to cross-post to the other PHP groups, but if that is...
0
by: Stubber1960 | last post by:
Hi guys, Can anyone recommend any Java libraries for wrapping COM? I've looked at Jacob (http://danadler.com/jacob/), but it appears to be a dead project. Thanks, Stubbier
18
by: Adrian B. | last post by:
Does anyone know of a framework or library that will enable me to use publish/subscribe comms? I want to create a server (using Python) running on a Unix box that will accept client connections...
2
by: John Smith | last post by:
Hey folks, Is it possible to create Type Wrappers in C#? If so, how do you do it? For those not sure of what I mean, here's a quick link on Type Wrappers in Java:...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
1
by: TC | last post by:
Every time I open my project, I get a warning which says "There are updated custom wrappers available for the following referenced components: Office." When I double-click on the warning, I get...
10
by: Yevgen Muntyan | last post by:
Consider the following macro: #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type))) The intent is to wrap raw memory allocation of N bytes into a macro which returns allocated chunk of memory...
3
by: Anoop | last post by:
Is it true that there are no type 4 jdbc drivers to connect to a DB2 server v7.1? The DB2 server is hosted on ACF2 (OS/390). We would be connecting from windows and solaris boxes. If it is true,...
1
by: sn20063757 | last post by:
what is meant by the term type wrappers in java.What is their use in java programming
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.