473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

type wrappers in java

3 New Member
what is meant by the term type wrappers .And what is their us in java programming .
For example
import java.util.*;
import javax.swing.JOp tionPane;
public class Numyears
{
public static void main(String[]args)
{
GregorianCalend ar current=new GregorianCalend ar();
int currentYear;
int birthYear;
int numYears;
birthYear=Integ er.parseInt(JOp tionPane.showIn putDialog
(null,"in what year were you born?",JOptionP ane.QUESTION_ME SSAGE));
currentYear=cur rent.get(Calend ar.YEAR);
numYears=curren tYear-birthYear;
JOptionPane.sho wMessageDialog( null,"you will turn"+numYears+ "years old",JOptionPan e.INFORMATION_M ESSAGE);
system.exit(0);
}
}
Aug 14 '07 #1
2 1558
JosAH
11,448 Recognized Expert MVP
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
etiainen
40 New Member
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
2315
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 discouraged, please let me know. At the same time, please then let me know which of the many PHP groups to post to. :) ) In PHP5, you can provide "type hints" for functions, like this:
0
1102
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
3501
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 (from GUIs built with wxPython) and publish realtime data updates to them. Any advice on where to start? Thanks. A.B.
2
1317
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: http://home.cogeco.ca/~ve3ll/jatutor5.htm#tw Thanks!
1
1645
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 code which works well. I understand the basic concept: our code is unmanaged, Windows Forms is Managed and Unmanaged may not call Managed code. I read about Wrappers, PInvoke, Runtime Callable Wrappers for COM and about It just
1
6877
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 a dialog box which says "One or more custom wrappers for COM components have been installed on your machine after you added references to those COM components. These wrappers may provide additional capabilities not offered by the auto-generated...
10
2590
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 to be used as a Type structure. The background: I was beaten many times (it surely is not my exclusive experience) by functions which return and accept void*. There are such functions,
3
22836
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, what are my options? Will I have to install db2 connect on every client machine that needs to connect to the DB2 servers? Is the DB2 Connect freely available or will we have to purchase it? I have also read on this group that we can install DB2...
1
1057
by: sn20063757 | last post by:
what is meant by the term type wrappers in java.What is their use in java programming
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.