Fundamental Question about int vs Integer

I don't really understand what the difference is between using the "int" keyword and using the Integer type. I've come to realise that "int" cannot be null whereas Integer can be null but why isn't int just an Integer type? Like an alias of sorts. I realise this a fairly basic question but I'm sure I'm not the only one pondering this :)

I'm not sure if the autoboxing stuff in 1.5 affects
this at all or not, but one key difference between
objects and primitives is that primitives get passed
by value, whereas objects are passed by reference.
NOOOOOOOOOOOOOO!
Wrong. Wrong. Wrong. Wrong. Wrong.
Everything in Java is passed "by value". Everything.
Pass-by-value
- When an argument is passed to a function, the invoked function gets a copy of the original value.
- The local variable inside the method declaration is not connected to the caller's argument; any changes made to the values of the local variables inside the body of the method will have no effect on the values of the arguments in the method call.
- If the copied value in the local variable happens to be a reference (or "pointer") to an object, the variable can be used to modify the object to which the reference points.
Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory.... The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
-- James Gosling, et al., The Java Programming Language, 4th Edition

Similar Messages

  • A question about immutable object: Integer

    import java.lang.Integer;
    public class ImmutableObject {
         public void changeImmutable(Integer x){
              x = x+1;
              System.out.print(x );          
    public static void main(String[] args){
         Integer x = new Integer(1);
         ImmutableObject i= new ImmutableObject();
         i.changeImmutable( x);
         System.out.print( x);     
    Hello everyone,
    Why the output of the program above is 21 rather than 22?
    Is it because of +? Can anyone tell me about this?
    Thanks a lot.
    Kolapig

    Isn't it call-by-reference? All parameters to methods are passed "by value." In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter's value without affecting values in the code that invoked the method. For example:
    class PassByValue {
        public static void main(String[] args) {
            double one = 1.0;
            System.out.println("before: one = " + one);
            halveIt(one);
            System.out.println("after: one = " + one);
        public static void halveIt(double arg) {
            arg /= 2.0;     // divide arg by two
            System.out.println("halved: arg = " + arg);
    }The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:before: one = 1.0
    halved: arg = 0.5
    after: one = 1.0You should note that when the parameter is an object reference, the object reference -- not the object itself -- is what is passed "by value." Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show the distinction:
    class PassRef {
        public static void main(String[] args) {
            Body sirius = new Body("Sirius", null);
            System.out.println("before: " + sirius);
            commonName(sirius);
            System.out.println("after:  " + sirius);
        public static void commonName(Body bodyRef) {
            bodyRef.name = "Dog Star";
            bodyRef = null;
    }This program produces the following output: before: 0 (Sirius)
    after:  0 (Dog Star)Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.
    The following diagram shows the state of the variables just after main invokes commonName:
    main()            |              |
        sirius------->| idNum: 0     |
                      | name --------+------>"Sirius"       
    commonName()----->| orbits: null |
        bodyRef       |______________|At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the "after" line would say "null". However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.
    Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
    -- Arnold, K., Gosling J., Holmes D. (2006). The Java� Programming Language Fourth Edition. Boston: Addison-Wesley.
    ~

  • Fundamental Question about Lightroom and saving images

    I have to laugh as I get ready to pose this question because I've been working with the program for two weeks with Scott Kelby's book and with Lynda.com, and I'm still profoundly confused about what is happening to the photo. To wit: I open a camera raw file in lightroom and start playing with it, even taking snapshots at various stages along the way. If I don't export the photo to Photoshop and save it there, what becomes of these changes? Do they stay with the photo always? Do they disappear when I shut down the program? There's no SAVE button with Lightroom which just plain flummoxes me! Can anyone 'splain this to me, please? Thanks.

    To clarify. Nothing happens to your originals. Lightroom stores the edits in a database (and if you wish alongside the original in a xmp sidecar file) as a set of instructions that the program uses to recreate the end product by following the instructions. These instructions are changed in the database while you're changing parameter values in Lightroom, so there is no need to save. Also, Lightroom stores a history of changes you did, so you can always go back. Both Lightroom and Adobe's camera raw plugin for photoshop can be used to follow the set if instructions. This way, you always get the highest fidelity image and you can always go back to your development choices without loosing any quality or having to dig up backups. Because of this, you can create multiple virtual copies with different development approaches without having to make a copy of the original and therefore saving you gobs and gobs of disk space. When you need a file for consumption such as a jpeg for a web page, simply export a copy, which burns in your development changes in a developed copy (just like printing a negative would have in the olden days) and trash the copy when you're done with it. You can always recreate it very quickly. This is a radically different approach than you're probably used to.

  • Question about "int scope" parameter in oracle.ldap.util.Util.getEntryDetails()

    List,
    What are the possible values for "scope" in oracle.ldap.util.Util.getEntryDetails(DirContext ctx, String base, String filter, int scope, String[] attrList)? Are there any constants?
    Thanks in advance.
    Leandro.

    I found it out...
    0 - SCOPE_BASE
    1 - SCOPE_ONELEVEL
    2 - SCOPE_SUBTREE
    Thanks any way.
    Leandro.
    Ps.: I didn't understand why this numbers aren't constants in the Util class. (Or why they aren't in the doc)

  • Fundamental question about initializers

    There appear to be three different ways (maybe more) to initialize instance (not static) variables in a newly-constructed object. I was hoping someone could shed some light on the differences between them.
    // 1. In the constructor:
    class Foo {
      Bar barInstance;
      Foo() {
        barInstance = new Bar();
    // 2. In the initializer itself:
    class Foo {
      Bar barInstance = new Bar();
    // 3. In a nonstatic initializer block:
    class Foo {
      Bar barInstance;
        barInstance = new Bar();

    If a constructor is defined as possibly throwing an exception, say for instance, FileWriter, you can not use the form
    class Foo
      PrintWriter pw = new PrintWriter( new FileWriter("c:\\foo"));
    }Normally you would do this in a constructor, but if you are implementing an anonymous class, you need this form.
    button.addActionListener( new ActionListener()
           PrintWriter pw = null;
           try {
               pw = new PrintWriter( new FileInputStream( "c:\\foo" ));
           catch (Exception e) {
               pw = System.out;
       public void actionPerformed( ActionEvent ae )
           pw.println( "Ouch" );

  • Fundamental question about EDD - why localized? Will this cause problems in other languages?

    Hi,
    I am running a German version of FrameMaker. All commands in the EDD appear in German. What happens when someone uses the EDD with an English or Chinese version of FrameMaker? Will this work as well?
    If editors have a look at the EDD, do they see German commands or commands in their own language?
    Can I simply change to English instead of German commands? 
    Thanks for your reply.
    Apollo102

    Hi Apollo,
    the EDDs are based on a Meta-EDD, that carries the whole localization of the EDD structure and the EDD structure itself.
    This Meta-EDD is the elemcat file Lynne mentioned. If you replace it with a version that is localized in some other language, your standard EDD will take over that localization.
    You could even modify the Meta-EDD to suit your EDD building needs better (I already saw some approach into that direction) or you could localize your EDDs to some completely different and yet unsupported language if you liked (Klingon EDD style, qapla'!).
    The localization in itself is bound to the file where you embed the EDD (or Meta-EDD), so everyone who opens the EDD will find the language used for the original.
    -Alex

  • Question about size of ints in Xcode

    Hello. I have a a few quick questions about declaring and defining variables and about their size and so forth. The book I'm reading at the moment, "Learn C on the Mac", says the following in reference to the difference between declaring and defining a variable:
    A variable declaration is any statement that specifies a variables name and type. The line *int myInt;* certainly does that. A variable definition is a declaration that causes memory to be allocated for the variable. Since the previous statement does cause memory to be allocated for myInt, it does qualify as a definition.
    I always thought a definition of a variable was a statement that assigned a value to a variable. If a basic declaration like "int myInt;" does allocate memory for the variable and therefore is a definition, can anyone give me an example of a declaration that does not allocate memory for the variable and therefore is not a definition?
    The book goes on, a page or so late, to say this:
    Since myInt was declared to be of type int, and since Xcode is currently set to use 4-byte ints, 4 bytes of memory were reserved for myInt. Since we haven't placed a value in those 4 bytes yet, they could contain any value at all. Some compilers place a value of 0 in a newly allocated variable, but others do not. The key is not to depend on a variable being preset to some specific value. If you want a variable to contain a specific value, assign the value to the variable yourself.
    First, I know that an int can be different sizes (either 4 bytes or 8 bytes, I think), but what does this depend on? I thought it depended on the compiler, but the above quote makes it sound like it depends on the IDE, Xcode. Which is it?
    Second, it said that Xcode is currently set to use 4-byte ints. Does this mean that there is a setting that the user can change to make ints a different size (like 8 bytes), or does it mean that the creators of Xcode currently have it set to use 4-byte ints?
    Third, for the part about some compilers giving a newly allocated variable a value of 0, does this apply to Xcode or any of its compilers? I assume not, but I wanted to check.
    Thanks for all the help, and have a great weekend!

    Tron55555 wrote:
    I always thought a definition of a variable was a statement that assigned a value to a variable. If a basic declaration like "int myInt;" does allocate memory for the variable and therefore is a definition, can anyone give me an example of a declaration that does not allocate memory for the variable and therefore is not a definition?
    I always like to think of a "declaration" to be something that makes no changes to the actual code, but just provides visibility so that compilation and/or linking will succeed. The "definition" allocates space.
    You can declare a function to establish it in the namespace for the compiler to find but the linker needs an actual definition somewhere to link against. With a variable, you could also declare a variable as "extern int myvar;". The actual definition "int myvar;" would be somewhere else.
    According to that book, both "extern int myvar;" and "int myvar;" are declarations, but only the latter is a definition. That is a valid way to look at it. Both statements 'delcare' something to the compiler, but on the second one 'define's some actual data.
    First, I know that an int can be different sizes (either 4 bytes or 8 bytes, I think), but what does this depend on? I thought it depended on the compiler, but the above quote makes it sound like it depends on the IDE, Xcode. Which is it?
    An "int" is supposed to be a processor's "native" size and the most efficient data type to use. A compiler may or may not be able to change that, depending on the target and the compiler. If a compiler supports that option and Xcode supports that compiler and that option, then Xcode can control it, via the compiler.
    Second, it said that Xcode is currently set to use 4-byte ints. Does this mean that there is a setting that the user can change to make ints a different size (like 8 bytes), or does it mean that the creators of Xcode currently have it set to use 4-byte ints?
    I think that "setting" is just not specifying any option to explicitly set the size. You can use "-m32" or "-m64" to control this, but I wouldn't recommend it. Let Xcode handle those low-level details.
    Third, for the part about some compilers giving a newly allocated variable a value of 0, does this apply to Xcode or any of its compilers? I assume not, but I wanted to check.
    I don't know for sure. Why would you ask? Are you thinking of including 45 lines of macro declarations 3 levels deep to initialize values based on whether or not a particular compiler/target supports automatic initialization? Xcode current supports GCC 3.3, GCC 4.0, GCC 4.2, LLVM GCC, CLang, and Intel's compiler for building PPC, i386, and x86_64 code in both debug and release, with a large number of optimization options. It doesn't matter what compiler you use or what it's behavior is - initialize your variables in C.

  • Questions about user-defined functions

    Hello all,
    I've got some questions about user-defined function in a message mapping:
    1) How can I get the current date/time in format yyyy-mm-dd hh:mm:ss ? What is the java code for this?
    2) I want to use the StreamTransformation constant TIME_SENT, only this is not in the right time-zone.
    It is GMT and it should be CET (1 hour difference). How can I convert this in Java?
    Can somebody help me with this?
    Thanks in advance.
    Kind regards,
    Marco van Iersel

    Hi Marco,
    If the date format is fixed as you have mentioned,please use this:
                                    String test = "2009-03-27 23:15:30";
              String test1 = test.substring(11,13);
              if(!test1.equals("23"))
              int a = Integer.parseInt(test1);
              int b = a+1;
              System.out.println("b"+b);
              String c = Integer.toString(b);
                                    test = test.substring(0,10)+" " + c + test.substring(13,19);
                                    return test;
              if(test1.equals("23"))
              test = test.substring(0,10)+ " 00" + test.substring(13,19);
              return test;
                                    else return "";
    Kindly let me know if this works.
    Thanks.
    Regards.
    Shweta

  • Question about the links that include parameters...

    Hello,
    I use this:
    <a href="inserer_devis.jsp?firstparameter=<%= rs.getString(1)%>&secondparameter=<%= rs.getString(2)%>">to have a link that gives parameters to the other JSP.
    My question is:
    On the other JSP, when I use request.getParameter("firstparameter"), what is the thing that I get: is it a string, a char, ...??
    And how can I convert it to a float or an int?
    I have problems with integer.parseint() and float.parsefloat(), it tells me "NumberFormatException: null". The compiler thinks that my parameter is not a good int (or float).
    Thank you.
    Romain.</a>

    Request.getParameter always returns a String (see the javadocs).
    To convert a String to an int use Integer.parseInt(StringToParse);
    To convert a String to a Float usse Float.parseFloat(StringToParse);
    just see the javadocs for more information

  • Question about the Documentat​ion Tags for Source Code

    Hello,
    I have a question about CVI's automatic source code documentation. My problem is that is seems like you need to write all documentation for a specific tag on one line. If you don't, a line break will be inserted when the documentation is displayed. Suppose I want to write a large amount of documentation for the function itself, using the HIFN tag. If I don't want linebreaks to be forced in the documentation, I need to write all this documentation on one single line, which kinda messes up my code. If I split the documentation over several HIFN tags, the documentation displayed to the user might look messed up because of all the linebreaks. Is there any escape character I can put at the end of a line, allowing me to split the documentation of several HIFN lines without forcing linebreaks in the documentation?
    Thanks!
    GEMIDIS - Innovating Display Technology
    HQ Ghent, Belgium

    This information is certainly useful. Note, however, that it can also be found in the documentation
    Tag
    Description
    /// HIFN help text
    Specifies the help text for the function. Use multiple /// HIFN tags to display help text for the function on separate lines. To separate help text with an empty line, use /// HIFN on a line by itself. You also can use HTML tags, but you must enclose the tags in <HTML><BODY></BODY></HTML> tags.
    Example
    /// HIFN SampleFunction returns the value of a control.
    int SampleFunction (int controlID, ctrlType controlType, char label[], double *value)
         SomeAction;

  • Basic questions about programing for J9 VM

    I need to create a java application to run on a Pocket PC 2003 OS and I'm limited to using IBM's Websphere J9 Virtual Machine. I'm new to using java in this capacity and therefore have lots of questions which I'm guessing are pretty basic. Despite my best efforts, I've found very little to help me online. Below are a couple questions I have that I'm hoping someone can help me with. Even better, if you know of any resources that could help me with these and other questions, I'd love to have them. Thanks in advance.
    1. I'm using standard AWT for the GUI but I'm having problems getting frames, dialogs, etc., to come up in anything less then full screen. setSize() and resize() have no effect, even if I extend the frame and override the setMinimumSize, setPreferredSize, setMaximumSize methods. What do I need to do to get a child window to appear in something less than full screen?
    2. I'd like to be able to add menu's to the buttom toolbar (with the keyboard) but have no idea how I would add something to it. Can someone point me in the right direction?
    3. When my application gets an iconified event I go ahead and call a System.exit() to exit the application. This doesn't kill the java VM though, which continues to run in the background (taking up plenty of memory). If I run my application using the J9w.exe so that it runs without the console, then not only does the VM continue to run, but I have no way to stop it (the running program list can't see it). Since each time I run my application it starts a new VM, it only takes a couple of times before I'm out of memory and have to do a soft reset of the PDA to make things right. Can I kill the VM when I kill my application?
    4. I learn best by looking at example code, but have been unable to find any code people are running on J9. I have the GolfScoreTracker installed and running on my PDA, but the jar file contains only the classes. Since it's supposed to be a demo, I had hoped that the source code would be included, is that hoping too much or is the source code available somewhere? In addition, if you know of any applications out there with available source code that are known to run well on a PocketPC J9 environment I'd appreciate the link.

    Hi there, I saw your questions, im currently developing a java pocket pc application as well and here's what i go so far:
    AWT seem to be hard to use on pocket pc, instead i recommend that you use SWT, which is a technology developed by eclipse. It's already installed on the eclipse plugins, you just need to download the jar and dll files for the pocket pc. They are available at: http://www.eclipse.org/downloads/index.php
    I assume that you already have the J9 working on your device. So you only need to copy the SWT.jar file and the swt-win32-3064.dll to the folder containing the .class files on your device.
    Now, on your java IDE(im using eclipse) Add the SWT.jar library to your project which should be on C:/eclipse/plugins/org.eclipse.swt.win32_3.0.2/ws/win32/swt.jar or something like taht depending on your eclipse root.
    Now you are ready to code some SWT, here is a sample program from Carolyn MacLeod, i modified a few things so it could run on the pocket pc but it's almost the same. Once you coded in eclipse run it, then copy the class file from your desktop to your device(There should be like 4 or 5 classes like sample.class, sample$1.class etc. copy all of them) where you put the jar and dll files(If program does not run you may try to rename the dll file for swt-win32-3050.dll instead of 3064.dll). Now after you have everything set up you need to create the lnk file in order to run the program. On your desktop create a new textfile and write the following on it:
    255#"\Archivos de Programa\J9\PPRO10\bin\j9w.exe" "-jcl:PPRO10" "-cp" "\My
    Documents\Java\swt.jar" ;\My Documents\Java" sample
    Paths depend on your install, and the place where you put your classes and jar file. path for j9w is usually "\Program Files\J9\PPRO10\bin\j9w.exe", and the last word should be the classname.
    Currently this form only displays an image on a canvas, click on the browse button and choose a pic and it will display on the canvas. Im trying to connect the form to an oracle database but no success yet on the device.
    Hope it helps, if you have any questions about the code or something, and I know the answer, please feel free to ask.
    See ya
    import org.eclipse.swt.*;
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.events.*;
    import org.eclipse.swt.graphics.*;
    public class sample {
    static Shell shell;
    static Display display;
    static Text dogName;
    static Text textdb;
    static Combo dogBreed;
    static Canvas dogPhoto;
    static Image dogImage;
    static List categories;
    static Text ownerName;
    static Text ownerPhone;
    static String[] FILTER_EXTS = {"*.jpg"};
    public static void main(String[] args) {
    display = new Display();
    shell = new Shell(display, SWT.RESIZE | SWT.CLOSE);
    Menu menu = new Menu(shell, SWT.BAR);
    shell.setText("Dog ShowS Entry");
    shell.setMenuBar(menu);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    shell.setLayout(gridLayout);
    new Label(shell, SWT.NONE).setText("Dog's NameS:");
    dogName = new Text(shell, SWT.SINGLE | SWT.BORDER);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    gridData.widthHint = 60;
    dogName.setLayoutData(gridData);
    new Label(shell, SWT.NONE).setText("Breed:");
    dogBreed = new Combo(shell, SWT.NONE);
    dogBreed.setItems(new String [] {"Collie", "Pitbull", "Poodle", "Scottie"});
    dogBreed.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    Label label = new Label(shell, SWT.NONE);
    label.setText("Categories");
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    new Label(shell, SWT.NONE).setText("Photo:");
    dogPhoto = new Canvas(shell, SWT.BORDER);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = 60;
    gridData.verticalSpan = 3;
    dogPhoto.setLayoutData(gridData);
    dogPhoto.addPaintListener(new PaintListener() {
    public void paintControl(final PaintEvent event) {
    if (dogImage != null) {
    event.gc.drawImage(dogImage, 0, 0);
    categories = new List(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    categories.setItems(new String [] {
    "Best of Breed", "Prettiest Female", "Handsomest Male",
    "Best Dressed", "Fluffiest Ears", "Most Colors",
    "Best Performer", "Loudest Bark", "Best Behaved",
    "Prettiest Eyes", "Most Hair", "Longest Tail",
    "Cutest Trick"});
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    gridData.widthHint = 60;
    gridData.verticalSpan = 4;
    int listHeight = categories.getItemHeight() * 12;
    Rectangle trim = categories.computeTrim(0, 0, 0, listHeight);
    gridData.heightHint = trim.height;
    categories.setLayoutData(gridData);
    Button browse = new Button(shell, SWT.PUSH);
    browse.setText("BrowsePic");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.widthHint = 60;
    browse.setLayoutData(gridData);
    browse.addSelectionListener(new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
              FileDialog dialog = new FileDialog(shell, SWT.OPEN);
              dialog.setFilterExtensions(new String[] {"*.*"});
              String fileName = dialog.open();
    if (fileName != null) {
    dogImage = new Image(display, fileName);
    shell.redraw();
    Button delete = new Button(shell, SWT.PUSH);
    delete.setText("No action");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    gridData.widthHint = 60;
    delete.setLayoutData(gridData);
    delete.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent event) {
    Button enter = new Button(shell, SWT.PUSH);
    enter.setText("No action");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.horizontalSpan = 3;
    enter.setLayoutData(gridData);
    enter.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent event) {
         shell.open();
         while (!shell.isDisposed()) {
              if (!display.readAndDispatch())
                   display.sleep();
         display.dispose();
    if (dogImage != null) {
    dogImage.dispose();
    }

  • Question about createXAQueueSession()

    Hi,
    I have a question about createXAQueueSession() method in javax.jms.XAQueueConnection class.
    Followings are from the the JMS 1.1 API:
    createQueueSession
    public QueueSession createQueueSession(boolean transacted,
    int acknowledgeMode)
    throws JMSException
    Creates an XAQueueSession object.
    Specified by:
    createQueueSession in interface QueueConnection
    Parameters:
    transacted - usage undefined
    acknowledgeMode - usage undefined
    Returns:
    a newly created XAQueueSession
    Throws:
    JMSException - if the XAQueueConnection object fails to create an XA queue session due to some internal error.
    The signature says it returns QueueSession but the javadoc says it returns XAQueueSession.
    And XAQueueSession is not subclass of QueueSession.
    Can anybody clarify the meaning of this method?
    Thnaks.
    yaluruns from www.tmaxsoft.com

    I would say it means what you think it means and not what it says. It looks to me as if the programmer used the copy-and-paste antipattern when coding the two methods, and didn't fix the copied javadoc correctly.
    PC&#178;

  • Question about opening sockets

    Hello I have some questions about using sockets.
    I made a program which works with sockets.
    I have a class which contains this
    static byte[] send(byte outbuf[], int len, byte recbyt[], long recip[])
            InetAddress dst = InetAddress.getByName(sendip);
            DatagramPacket request = new DatagramPacket(outbuf, len, dst, sendportint);
            DatagramSocket socket = new DatagramSocket();       
    socket.send(request);
      DatagramPacket packet = new DatagramPacket(inbuf, inbuf.length);
    socket.receive(packet);
      }In another class I call this method like this
    for(int i=0;i<rows;i++)
    send(byte outbuf[], int len, byte recbyt[], long recip[])
    }As you can see it opens a socket when sending something but never close. Does this mean that evrytime I call send it opens a new socket??
    So that if rows is 500 after this loop 500 socket are opened??
    When I place close.socket after socket.receive() it works the same. Is this better or not??

    What do you mean with this line
    Method ends, Socket gets GCed and closes on GCDo you mean when the method ends the socket closes??
    And what is GC?

  • Question about Java's HttpServer: Threading? Backlog?

    Hello,
    I have two questions about Java's HttpServer (com.sun.net.httpserver). From the JavaDoc:
    >
    Management of threads can be done external to this object by providing a Executor object. If none is provided a default implementation is used.
    >
    How can I get information about the default implementation in 1.6.0_13? Do you know the behavior? From my observations, the default implementation uses no Threads, meaning every request is handled in the same Thread, this results in handling the requests to the HttpServer one after another.
    Is this right?
    The second question is about this, also from the JavaDoc:
    >
    When binding to an address and port number, the application can also specify an integer backlog parameter. This represents the maximum number of incoming TCP connections which the system will queue internally. [...]
    >
    When setting the backlog to -1, it uses the systems default backlog. How can I determine the systems default backlog? Can some lines of Java code reveal it (there is no getBeacklog() method)? Or is it up to the Operating System (we use Redhat Linux)?
    Thanks a lot for your help!
    Regards,
    Timo

    How can I determine the systems default backlog?You can't. There is no API for that even at the C level.
    Can some lines of Java code reveal itNo.
    Or is it up to the Operating System (we use Redhat Linux)?Yes. Linux provides a large default. It seems to be at least 50 on most platforms. This is not something you should be worrying about.

  • Question about the EDT

    Hi everybody,
    Here my issue: I have to write a little something about EDT and the use of SwingUtilities to avoid common issues with the use of Swing. Sure of my knowledge I wrote a little exemple using a progressBar to show how it doesn't work when you don't use SwingUtilities :
    import javax.swing.JDialog;
    import javax.swing.JProgressBar;
    public class UITesting{
        public static void          main                                            ( String[] args ) {
            JProgressBar    jProgressBar    =   new JProgressBar(0, 100) ;
            jProgressBar.setValue(0);
            jProgressBar.setStringPainted(true);
            JDialog         dialog          =   new JDialog() ;
            dialog.setSize(400, 70) ;
            dialog.setContentPane(jProgressBar) ;
            dialog.setLocationRelativeTo(null) ;
            dialog.setVisible(true);
            int flag = 0 ;
            for (int i = 0 ; i < 100000 ; i++) {
                System.out.println(i);
                if ( i%1000 == 0 ) {
                    jProgressBar.setValue(++flag);
                    System.out.println("Increase ProgressBar " + flag);
    }And surprise (at least for me)... it's working... means that my ProgressBar increase well...
    So I write an exemple closer to reality
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    public class UITesting{
        public static void          main                                            ( String[] args ){
            final JProgressBar    jProgressBar    =   new JProgressBar(0, 100) ;
            jProgressBar.setValue(0);
            jProgressBar.setStringPainted(true);
            JButton         start           =   new JButton("Start") ;
            start.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int flag = 0 ;
                    for (int i = 0 ; i < 100000 ; i++) {
                        System.out.println(i);
                        if ( i%1000 == 0 ) {
                            jProgressBar.setValue(++flag);
                            System.out.println("Increase ProgressBar " + flag);
            JPanel          panel           =   new JPanel() ;
            panel.add(start) ;
            panel.add(jProgressBar) ;
            JDialog         dialog          =   new JDialog() ;
            dialog.setSize(400, 70) ;
            dialog.setContentPane(panel) ;
            dialog.setLocationRelativeTo(null) ;
            dialog.setVisible(true);
    }That time it's perfect, the ProgressBar doesn't work, it going from 0 to 100% at the end of my for loop and the button freeze during the process, I can illustrate my point and introduce the use of SwingUtilities... But why it's working in my first exemple?
    I know that a call to an ActionListener in a Swing composant insure that the code specified is executed in EDT, but I still can't get it? Someone can help me to understand that ?
    thx in advance,
    yannig
    Edited by: yannig on 24 mars 2011 10:57

    Hi,
    [url http://download.oracle.com/javase/tutorial/uiswing/concurrency/worker.html]Worker Threads and SwingWorker
    When a Swing program needs to execute a long-running task, it usually uses one of the worker threads, also known as the background threads. Each task running on a worker thread is represented by an instance of javax.swing.SwingWorker.
    import java.awt.*;
    import java.awt.event.*;
    import java.beans.*;
    import javax.swing.*;
    public class UITesting2 {
      private SwingWorker<Void, Void> worker;
      public JComponent makeUI() {
        final JProgressBar jProgressBar = new JProgressBar(0, 100);
        jProgressBar.setValue(0);
        jProgressBar.setStringPainted(true);
        final JButton start = new JButton("Start") ;
        start.addActionListener( new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            start.setEnabled(false);
            worker = new SwingWorker<Void, Void>() {
              @Override
              public Void doInBackground() throws InterruptedException {
                int current = 0;
                int lengthOfTask = 1024;
                while (current<=lengthOfTask && !isCancelled()) {
                  Thread.sleep(5);
                  setProgress(100 * current / lengthOfTask);
                  current++;
                return null;
              @Override public void done() {
                start.setEnabled(true);
            worker.addPropertyChangeListener(
                new ProgressListener(jProgressBar));
            worker.execute();
        JPanel panel = new JPanel();
        panel.add(start);
        panel.add(jProgressBar);
        return panel;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          @Override public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.getContentPane().add(new UITesting2().makeUI());
        f.setSize(400, 70);
        f.setVisible(true);
    class ProgressListener implements PropertyChangeListener {
      private final JProgressBar progressBar;
      ProgressListener(JProgressBar progressBar) {
        this.progressBar = progressBar;
        this.progressBar.setValue(0);
      @Override public void propertyChange(PropertyChangeEvent evt) {
        String strPropertyName = evt.getPropertyName();
        if ("progress".equals(strPropertyName)) {
          progressBar.setIndeterminate(false);
          int progress = (Integer)evt.getNewValue();
          progressBar.setValue(progress);
    }

Maybe you are looking for

  • Two accounts on the same computer!

    I have an IPOD Nano and an IPOD Touch. My wife likes different music than I do.Is it possiable to have two I Tunes accounts on the same computer?

  • APPLE TV 2 - Can I connect to non-HDMI TV via HDMI-capable AV reciever?

    I have an older Sony Trinitron TV that is not HDMI-capable. I have all of my video components (DirecTV, Blu-Ray, Wii) connected to it via component cable from a DENON AVR-2307C1 receiver. I connected my new Apple TV 2 to the receiver via the HDMI cab

  • Labview-Oc​tave/GNUPl​ot Inegration

    Hello, forum! I'm working on a little project to take images I've acquired using some LabVIEW code and automatically import them into GNU Octave (similar to MATLAB) and turn them into a 3D image "stack" an added bonus would bethe ability to return th

  • Why no more clips and just one big .mov file?

    I had been working in iMovie and iDVD 4 for some time up until present when I upgraded to iLife 6. One of the things I like about ver. 4 was that the whole movie was saved as a file but there were also the individual clips saved as well. I could use

  • Is anyone else's Windows 7 PC crashing from the CC 2014 programs?

    I've had nothing but trouble with Creative Cloud. First had trouble downloading and installing apps. Lately, however, my computer screen goes black and restarts. I've tied it to Photoshop CC 2014, Illustrator CC 2014 and Acrobat XI Pro. I've cleaned