Wrapper Class methods

Hello.
I'm testing wrapper class methods. I'm working right now with valueOf(). I'm trying to do a resume about the min and max values of all radix for wrapper class, something like this:
          p(" - Integer Table - ");
          p("Min: "+Integer.MIN_VALUE);
          p("Max: "+Integer.MAX_VALUE);
          p("Max Bin value: 1111111111111111111111111111111");
          p("->" + Integer.valueOf("1111111111111111111111111111111", 2));
          p("Max Oct value: 7777777777");
          p("->" + Integer.valueOf("777777777", 8));
          p("Max Hex value: 7777777777");
          p("->" + Integer.valueOf("FFFFFF", 16));Don't worry about p(). So .. when I'm using the method for octal and hexadecimal base they don't reach the max value of the integer. So I think that this is a mathematical issue that I don't know (I don't have math instruction =( so be nice with me) or probably something else. Let me know if my question is now well asked.
Regards.
vanhalt

Two's complement isn't all that straightforward, but it's not too hard once you really look at it. (Catch-22, I know.)
The basics (I assume you know the first part, but I just want to make sure it's clear):
A computer stores numbers in binary. So, for instance, an 8-bit number has spots for 8 binary digits, making the largest possible number 11111111 (255). So that gives us 0-255 (256 possible values), but no negatives.
To store negatives, you could take a bit away from your possible values, making it 1 bit for sign (say, 0 for positive and 1 for negative) and 7 bits for the number. In this scheme, you could get 127 positive values (00000001 to 01111111 [1 to 127]), 127 negative values (10000001 to 11111111 [-1 to -127]) and 2 ways to express zero (00000000 and 10000000, since 0 and -0 are the same number).
Well, for a number of reasons, this isn't practical. Most importantly, it makes doing binary math very difficult. For example
(5 - 2) --> (5 + -2) --> (00000101 + 10000010) = 10000111 --> -7. This is clearly the wrong answer.
So some smart computer scientists realized that by taking an inverse of the binary value and then adding 1, they could do math with negative numbers without much difficulty. So instead of -2 being 10000010, they'd take the positive value (00000010) and get the inverse (11111101), then add 1 (11111110). Now you can add them: (00000101 + 11111110) = 100000011 (which has a 9th bit because of carry-over in the addition). And hey, it's not going to fit anyway so let's drop the 9th bit. And now we have 00000011. Which, lo and behold, is 3.
And if your result comes back with a negative in the 8th bit, reverse the two's complement -- subtract 1, then inverse, and you have the absolute value.
It's a nice trick that takes advantage of some arithmetic and the fact that we know we'd have to drop digits at the end. [Here's a more thorough explanation of why it works.|http://www.cs.duke.edu/courses/cps104/spring07/twoscomp.html]

Similar Messages

  • Wrapper classes/ instance variables&methods

    can anyone provide me additional information on the wrapper classes.
    In addition, could someone please provide an explination of the- instance and class (variables+methods)

    Every primitive class has a wrapper class e.g.
    int - Integer
    float - Float
    long - Long
    char - Character
    etc. When a primitive is wrapped it becomes an object and immutable. Primitives are generally wrapped (either to make them immutable) or to be able to add them to the collections framework(sets, maps, lists which can only take objects, not primitives).
    An instance variable is a variable that each copy of the object you create contains, as is an instance method. Each instance you create (each copy of the object) contains its own copy of the variable and method.
    A class variable and method means that no matter how many objects you create, there will be one and only one copy of the variable and method.
    Hope this helps. Also see the java tutorial.

  • What is the proper way to code a "wrapper" class?

    Basically I want to replace an existing Action with a custom Action, but I want the custom Action to be able to invoke the existing Action.
    The following code works fine. I can create a custom Action using the existing action and the text on the button "paste-from-clipboard" is taken from the existing Action. So everything works great as long as the existing Action extends from AbstractAction.
    However the Action interface does not support the getKeys() method which I used to copy the key/value information from the existing action to the wrapped action. So if you try to create a button from some class that strictly implements the Action interface the key/value data in the wrapped Action will be empy and no text will appear on the button.
    So as the solution I thought I would need to override all the methods in the wrapped Action class to invoke the methods from the originalAction object. That is why all the commented code in the class is there. But then the protected methods cause a problem as the class won't compile.
    Do I just not worry about overriding those two methods? Is this a general rule when creating wrapper classes, you ignore the protected methods?
    import java.awt.*;
    import java.awt.event.*;
    import java.beans.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class WrappedAction extends AbstractAction
         private Action originalAction;
         public WrappedAction(JComponent component, KeyStroke keyStroke)
              Object key = getKeyForActionMap(component, keyStroke);
              if (key == null)
                   String message = "no input mapping for KeyStroke: " + keyStroke;
                   throw new IllegalArgumentException(message);
              originalAction = component.getActionMap().get(key);
              if (originalAction == null)
                   String message = "no Action for action key: " + key;
                   throw new IllegalArgumentException(message);
              //  Replace the existing Action with this class
              component.getActionMap().put(key, this);
              //  Copy key/value pairs to
              if (originalAction instanceof AbstractAction)
                   AbstractAction action = (AbstractAction)originalAction;
                   Object[] actionKeys = action.getKeys();
                   for (int i = 0; i < actionKeys.length; i++)
                        String actionKey = actionKeys.toString();
                        putValue(actionKey, action.getValue(actionKey));
         private Object getKeyForActionMap(JComponent component, KeyStroke keyStroke)
              for (int i = 0; i < 3; i++)
              InputMap inputMap = component.getInputMap(i);
              if (inputMap != null)
                        Object key = inputMap.get(keyStroke);
                        if (key != null)
                             return key;
              return null;
         public void invokeOriginalAction(ActionEvent e)
              originalAction.actionPerformed(e);
         public void actionPerformed(ActionEvent e)
              System.out.println("custom code here");
              invokeOriginalAction(e);
         public void addPropertyChangeListener(PropertyChangeListener listener)
              originalAction.addPropertyChangeListener(listener);
         protected Object clone()
              originalAction.clone();
         protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
              originalAction.firePropertyChange(propertyName, oldValue, newValue);
         public Object[] getKeys()
              return originalAction.getKeys();
         public PropertyChangeListener[] getPropertyChangeListeners()
              return originalAction.getPropertyChangeListeners();
         public Object getValue(String key)
              return originalAction.getValue(key);
         public boolean isEnabled()
              return originalAction.isEnabled();
         public void putValue(String key, Object newValue)
              originalAction.putValue(key, newValue);
         public void removePropertyChangeListener(PropertyChangeListener listener)
              originalAction.removePropertyChangeListener(listener);
         public void setEnabled(boolean newValue)
              originalAction.setEnabled(newValue);
         public static void main(String[] args)
              JTextArea textArea = new JTextArea(5, 30);
              JFrame frame = new JFrame("Wrapped Action");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add(new JScrollPane(textArea), BorderLayout.NORTH);
              frame.add(new JButton(new WrappedAction(textArea, KeyStroke.getKeyStroke("control V"))));
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );

    I can't get the PropertyChangeListener to fire with any source. Here is my test code. Note I am able to add the PropertyChangeListener to the "Paste Action", but I get no output when I add it to the WrappedAction. I must be missing something basic.
    import java.awt.*;
    import java.awt.event.*;
    import java.beans.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    public class WrappedAction3 implements Action, PropertyChangeListener
         private Action originalAction;
         private SwingPropertyChangeSupport changeSupport;
          *  Replace the default Action for the given KeyStroke with a custom Action
         public WrappedAction3(JComponent component, KeyStroke keyStroke)
              Object actionKey = getKeyForActionMap(component, keyStroke);
              if (actionKey == null)
                   String message = "no input mapping for KeyStroke: " + keyStroke;
                   throw new IllegalArgumentException(message);
              originalAction = component.getActionMap().get(actionKey);
              if (originalAction == null)
                   String message = "no Action for action key: " + actionKey;
                   throw new IllegalArgumentException(message);
              //  Replace the existing Action with this class
              component.getActionMap().put(actionKey, this);
              changeSupport = new SwingPropertyChangeSupport(this);
            originalAction.addPropertyChangeListener(this);
            addPropertyChangeListener(this);
          *  Search the 3 InputMaps to find the KeyStroke binding
         private Object getKeyForActionMap(JComponent component, KeyStroke keyStroke)
              for (int i = 0; i < 3; i++)
                  InputMap inputMap = component.getInputMap(i);
                  if (inputMap != null)
                        Object key = inputMap.get(keyStroke);
                        if (key != null)
                             return key;
              return null;
         public void invokeOriginalAction(ActionEvent e)
              originalAction.actionPerformed(e);
         public void actionPerformed(ActionEvent e)
              System.out.println("actionPerformed");
    //  Delegate the Action interface methods to the original Action
         public Object getValue(String key)
              return originalAction.getValue(key);
         public boolean isEnabled()
              return originalAction.isEnabled();
         public void putValue(String key, Object newValue)
              originalAction.putValue(key, newValue);
         public void setEnabled(boolean newValue)
              originalAction.setEnabled(newValue);
         public void xxxaddPropertyChangeListener(PropertyChangeListener listener)
              originalAction.addPropertyChangeListener(listener);
         public void xxxremovePropertyChangeListener(PropertyChangeListener listener)
              originalAction.removePropertyChangeListener(listener);
         public void addPropertyChangeListener(PropertyChangeListener listener)
            changeSupport.addPropertyChangeListener(listener);
        public void removePropertyChangeListener(PropertyChangeListener listener)
            changeSupport.removePropertyChangeListener(listener);
         public void propertyChange(PropertyChangeEvent evt)
             changeSupport.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
         public static void main(String[] args)
              JTable table = new JTable(15, 5);
              WrappedAction3 action = new WrappedAction3(table, KeyStroke.getKeyStroke("TAB"));
              action.addPropertyChangeListener( new PropertyChangeListener()
                   public void propertyChange(PropertyChangeEvent e)
                        System.out.println(e.getSource().getClass());
              action.putValue(Action.NAME, "name changed");
              Action paste = new DefaultEditorKit.PasteAction();
              paste.addPropertyChangeListener( new PropertyChangeListener()
                   public void propertyChange(PropertyChangeEvent e)
                        System.out.println(e.getSource().getClass());
              paste.putValue(Action.NAME, "name changed");
    }

  • Apache comons logging implemented it with a  wrapper  classes around

    hi friends,
    i have an interesting (unsually )problem regaurding apache commons logging, i am using three classes .
    one is the logger class where i instantiate the logging instance ie Log log = LogFactory .getLog("some name");
    then there is a class called LFactory where i use i hashMap to store the various different logger created or to access the different logger for the hashmap
    then the last i have i LoggerAccessor class which links the LFactory.
    as u all now that the logger will give the line number of the class where we use the log instance ( Log log)..... but as i am using a wrapper classes around the actually log instance.
    in any class where i require the logging to be done.. i used my LoggerAccessor. so instead of giving me the Actuall Classname,methodname,and line number of the class where i give logging statements. I get the name of my class where i have created the instance and specially the line number of the class where the instance is created....( means my first class).
    i want to get the name,method,linenumber of the class where i have added logging statements
    please find me the solution for it.....
    thanks

    Good Question Nutan !! But i don't have answer !! Hope someone else will answer this !

  • What exactly is a wrapper class?

    In so far as Integer, Byte, Double et al. are concerned I understand that those wrapper classes are a way to handle primitive types as objects. But I've come across references to wrapper classes in documentation and other technical articles and I don't think I really understand what they are really used for. Why do you need a wrapper class for an object?
    Could someone shed me some light on this issue?
    Thanks,
    John

    An instance of a wrapper class holds a pointer to and instance of some other class or interface and provides access to it, typically supplying methods equivalent to all the methods of the underlying type.
    The basic wrapper class a functional replacement for the underlying object.
    When you're passed an object from some code outside your control you often don't know what exact class it is, or have access to it's class definition.
    A wrapper object allows you to modify the functionality of such an object. You can extend the wrapper class, for example, adding extra methods. Or you can modify the methods, for example to provide logging of calls made.
    As a concrete example, I have a wrapper class LoggedConnection which wraps a java.sql.Connection object. It also implements java.sql.Connection. If you ask a LoggedConnection for a Statement or PreparedStatement it fetches the appropriate object and returns a wrapped version which logs the SQL and the execution times etc..
    My "get me a connection" routine can return either a raw Connection or a LoggedConnection according to whether a SQL log file is provided.
    The main program doesn't need to know if it's using a genuine Connection object or the wrapped version.
    Part of the definition would look like:
    public class LoggedConnection implements Connection {
      private Connection wrappee;
      public LoggedConnection(Connection con) {
        wrapee = con;
      public createStatement() throws SQLExeception {
        return new LoggedStatement(wrappee.createStatement())
    }(Of course this was tedious to write by hand because Connection has so many methods, all of which the wrapper must implement. Later I wrote a java program to generate Wrapper classes).

  • How to keep track of status using wrapper class?

    Hi,
    I got the following code on the server side:
    ..........//this method invocation may take a long time to do
    Object methodResult = method.invoke(object, args);
    if (methodResult != null) //method invocation return results
          //convert the methodResult Object into JDOM Element   
         ObjectWriter writer = new SimpleWriter();  
         Element element = writer.write(methodResult); 
         //return result to client--------------------------------------------------------  
         //Results tag to notify incoming result from method invocation on next incoming byte  
         out.println("Results"); 
         //convert the element into String  
        String strXML = Util.convertXMLtoString(element);  
        //send the String xml out to the client. The client will receive the string representation of the xml  
        out.println("strXML):        
    else //there are no results return from method invocation
        //save the result into xml file  
        Util.createFile(element, new File(filename));
    .......................The problem is how to I keep track of the status of the method invocation.
    As can be seen from the above code, Object methodResult = method.invoke(object, args);
    the method invocation will take a long time!
    How do I write a wrapper class to keep track of the status of the method invocation that can be check by the client? I am thinking of using a url to keep track of method invocation so that the client can continously poll the wrapper object to check if the method invocation has finished.
    Can anyone change my code and give advice?
    Thanks a lot!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    No,
    I am not using Java threads at all.
    I just need to keep track of the status of the method invocation and report to the client.
    Sometimes, the method invocation can take ages so it is not acceptable for the client to invoke a method and wait a long time without any response: but in fact the server is still in the process of executing the method.
    Please advice.

  • How do I create Wrapper class for Message Box?

    I want to create Wrapper class for Message Box class in my project. I am using Telerik Testing FrameWork. In that message box was not recognized in unit testing thats y i want to create wrapper class, for creating the
    instance for that mesage box.

    A wrapper class is simply a class that for example wraps another object or a subset of its methods. You could just create a class that exposes the same methods as the MessageBox and uses the MessageBox internally.
    If you define an interface and program against this in your application, you could replace your wrapper object with another object that implements the same interface when you are doing the unit tests. Something like this:
    public interface IMessageBoxWrapper
    System.Windows.Forms.DialogResult Show(string text, string caption);
    public class MessageBoxWrapper
    public System.Windows.Forms.DialogResult Show(string text, string caption)
    return System.Windows.Forms.MessageBox.Show(text, caption);
    public class MockMessageBoxWrapper
    public System.Windows.Forms.DialogResult Show(string text, string caption)
    return System.Windows.Forms.DialogResult.OK;
    private readonly IMessageBoxWrapper _mbw;
    public Form1(IMessageBoxWrapper mbw)
    InitializeComponent();
    _mbw = mbw;
    private void SomeMethod()
    _mbw.Show("...", "...");
    Hope that helps.
    Please remember to close your threads by marking all helpful posts as answer and please start a new thread if you have a new question.

  • What is meant by a wrapper class ?

    What is meant by a wrapper class ?

    java uses simple types such as int and char. these data type r not part of object hierarchy. they r passed by value to methods and cannot b directly passed by reference. there is no way for 2 methods to refer to the same instance of an int. at times u will need an object representation for one of these simple types.wrapper classes encapsulate or wrap the simple types within a class. thus, they r commonly referred to as type wrapper.
    java provides classes that correspond to each of the simple types

  • Expose a class method as web service

    hi ABAPers,
    is it possibile to expose a class method as web service? I would like to write a base class with common code, while derived classes implement specific application logic.
    I have both R/3 6.40 and Netweaver 7.0 kernels, so I'm interested in both.
    thank you.

    No, it is not yet possible.
    You can only create a web service for an RFC Function Module, Function Group or Business Object.
    You may create a RFC FM as a wrapper to your Class methods and create a web service on the RFC FM.
    Regards,
    Naimesh Patel

  • Opinions on javadoc and wrapper classes

    I have several wrapper classes (in this case, wrappers for InputStream) that override all of the methods, but only a few of the methods overridden have important changes. The rest of the methods behave as described in the original contract (in this case, the various InputStream.read() methods).
    I would like to hear some opinions regarding documenting these methods. Any javadoc I write for them would be nearly identical or even copy/pasted from the original javadoc. The javadoc comment for the whole class clearly says that the class follows the contract for the wrapped class, and as such the overrideen methods will work as such.
    Is it reasonable to ask that someone reading the javadoc for this class should refer back to the wrapped class' API documentation, or should I copy (or paraphrase) the description from the original API documentation?

    I like the idea of @see, but since I'm just javadoc'ing my classes, @see doesn't link, which in this case, eliminates some of the usefulness. Here's a concrete example:
    /* ************ Normal ************ */
    available
    public int available()
    throws java.io.IOException
    Overrides:
    available in class java.io.InputStream
    Throws:
    java.io.IOException
    /* ************ @see ************ */
    available
    public int available()
    throws java.io.IOException
    Overrides:
    available in class java.io.InputStream
    Throws:
    java.io.IOException
    See Also:
    InputStream.available()
    /* ************ JDK in sourcepath ************ */
    available
    public int available()
    throws java.io.IOException
    Description copied from class: java.io.InputStream
    Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.
    Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.
    A subclass' implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the InputStream.close() method.
    The available method for class InputStream always returns 0.
    This method should be overridden by subclasses.
    Overrides:
    available in class java.io.InputStream
    Returns:
    an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.
    Throws:
    IOException - if an I/O error occurs.
    /* ********************* end javadoc stuff *************** */
    Because of the Overrides bit, the @see tag isn't really adding anything new. The inherited comment is clearly labeled as such, which is a big plus to me (give credit where credit is due).

  • Java Wrapper Classes are immutable?

    Hi guys,
    The one artichle i have read it says wrapper classes are immutable and once you assign a value to a variable(wrapper class type) you wont be able to change that value ,also ;
    Integer myInt=new Integer(5);
    myInt=10;//i change it no problem showed up.also why it says wrapper classes are immutable?
    //how the java works at the background and change it for us what methods does it use to change the value?
    //why java made wrapper classes as immutable?Thanks.

    Garibanus wrote:
    Hi guys,
    The one artichle i have read it says wrapper classes are immutableAnd it was correct in saying that.
    and once you assign a value to a variable(wrapper class type) you wont be able to change that valueThat has nothing to do with imutability. If the article said that, it's wrong. If it said that assigning a reference variable to point to an object has anything to do with that object's imutability, it was wrong.
    Immutability has to do with the state of an object, not with references that point to it.

  • Failed to Generate Wrapper Class exception while connecting to access database.

    i tried to connect to access database in windows. i made a user dsn in windows
    control panel and added this to the connection pool. after which i created a JDBC
    datasource using this connection pool.(specifying the driver as sun.jdbc.odbc.JdbcOdbcDriver
    and url=jdbc:odbc:xyz
    where xyz is the user dsn name pointing to the relevant access database file.
    on testing this in the weblogic admin console it showed successful operation.
    when i tried to use this connection pool in weblogic 8.1 workshop and tried
    building a rowset control to check the connectivity it gave the following exception.
    file attached.
    any hints on how to get it working/ how to use access database with wl 8.1
    workshop.
    Exception in context_onAcquire
    java.sql.SQLException: Failed to Generate Wrapper Class.
    Nested Exception: java.lang.RuntimeException: Failed to Generate Wrapper Class
    at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:141)
    [DB-error.txt]

    ashok wrote:
    i tried to connect to access database in windows. i made a user dsn in windows
    control panel and added this to the connection pool. after which i created a JDBC
    datasource using this connection pool.(specifying the driver as sun.jdbc.odbc.JdbcOdbcDriver
    and url=jdbc:odbc:xyz
    where xyz is the user dsn name pointing to the relevant access database file.
    on testing this in the weblogic admin console it showed successful operation.
    when i tried to use this connection pool in weblogic 8.1 workshop and tried
    building a rowset control to check the connectivity it gave the following exception.
    file attached.
    any hints on how to get it working/ how to use access database with wl 8.1
    workshop.
    Exception in context_onAcquire
    java.sql.SQLException: Failed to Generate Wrapper Class.
    Nested Exception: java.lang.RuntimeException: Failed to Generate Wrapper Class
    at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:141)
    Hi Askok. This exception usually means that the weblogic server's environment
    doesn't have all it needs to make the jdbc connection you want. You should
    ensure that the OS environment variable PATH has all the libraries you need
    for making a jdbc-odbc connection, and that it's classpath also contains the
    driver you want.
    What DBMS are you connecting to? The reason I ask is because if there is a
    pure JDBC driver for it, that will be preferable, because the jdbc-odbc bridge
    from Sun is not threadsafe, so it can corrupt Weblogic.
    Joe
    >
    Exception in context_onAcquire
    java.sql.SQLException: Failed to Generate Wrapper Class.
    Nested Exception: java.lang.RuntimeException: Failed to Generate Wrapper Class
    at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:141)
    at weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:73)
    at weblogic.jdbc.jts.Driver.newConnection(Driver.java:674)
    at weblogic.jdbc.jts.Driver.createLocalConnection(Driver.java:196)
    at weblogic.jdbc.jts.Driver.connect(Driver.java:154)
    at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:298)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getConnection(DatabaseControlImpl.jcs:1360)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.context_onAcquire(DatabaseControlImpl.jcs:1252)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:353)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:420)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:393)
    at com.bea.wlw.runtime.core.container.Invocable.fireEvent(Invocable.java:603)
    at com.bea.wlw.runtime.core.context.WlwThreadContext.sendEvent(WlwThreadContext.java:989)
    at com.bea.wlw.runtime.core.context.WlwThreadContext.raiseEvent(WlwThreadContext.java:919)
    at com.bea.wlw.runtime.core.container.Container.raiseContextEvent(Container.java:553)
    at com.bea.wlw.runtime.jcs.container.JcsContainer.onAcquire(JcsContainer.java:513)
    at sun.reflect.GeneratedMethodAccessor325.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:353)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:420)
    at com.bea.wlw.runtime.core.container.Invocable.sendContextEvent(Invocable.java:524)
    at com.bea.wlw.runtime.jcs.container.JcsContainer.sendContextEvent(JcsContainer.java:464)
    at com.bea.wlw.runtime.core.context.WlwThreadContext.acquireResources(WlwThreadContext.java:676)
    at com.bea.wlw.runtime.jcs.container.JcsProxy.invoke(JcsProxy.java:307)
    at processes.Audit.insertAuditData(Audit.ctrl)
    at processes.ExceptionHandler.auditInsertAuditData(ExceptionHandler.jpd:78)

  • Wrapper class ?? what that ??

    please anybody could give me an example of utilisation of a "wapper class" ? (I don t know what is this)
    thanks....

    then the next (and the main) question is :
    I am displaying a frame which contains canvas. when I invoc the method g1.drawRenderedImage (from api Java Advancing Imaging), the console java prints the message :
    could not find mediaLid Accelerator Wrapper Classes. Continuing in pure java mode
    do you thing that the problem is that there isnt any Keystroke ?
    thanks....

  • Passing Wrapper Classes as arguments

    I have a main class with an Integer object within it as an instance variable. I create a new task that has the Integer object reference passed to it as an argument, the task then increases this objects value by 1. However the objects value never increases apart from within the constructor for the task class, it's as if it's treating the object as a local variable. Why?
    mport java.util.concurrent.*;
    public class Thousand {
         Integer sum = 0;
         public Thousand() {
              ExecutorService executor = Executors.newCachedThreadPool();
              for(int i = 0; i < 1; i++) {
                   executor.execute(new ThousandThread(sum));
              executor.shutdown();
              while(!executor.isTerminated()) {
              System.out.println(sum);
         public static void main(String[] args) {
              new Thousand();
         class ThousandThread implements Runnable {
              public  ThousandThread(Integer sum) {
                        sum = 5;
                        System.out.println(sum);
              public void run() {
                   System.out.println("in Thread : ");
    }

    AlyoshaKaz wrote:
    here's the exact queston
    (Synchronizing threads) Write a program that launches one thousand threads. Each thread adds 1 to a variable sum that initially is zero. You need to pass sum by reference to each thread.There is no pass by reference in Java
    In order to pass it by reference, define an Integer wrapper object to hold sum. This is not passing by reference. It is passing a reference by value.
    If the instructor means that you are to define a variable of type java.lang.Integer, this will not help, as Integer is immutable.
    If, on the other hand, you are meant to define your own Integer class (and it's not a good thing to use a class name that already exists in the core API), then you can do so, and make it mutable. In this case, passing a reference to this Integer class will allow your method to change the contents of an object and have the caller see that change. This ability to change an object's state and have it seen by the caller is why people mistakenly think that Java passes objects by reference. It absolutely does not.
    Bottom line: Your instructor is sloppy with terminology at best, and has serious misunderstanding about Java and about CS at worst. At the very least, I'd suggest getting clarification on whether he means for you to use java.lang.Integer, which might make the assignment impossible as worded, or if you are supposed to create your own Integer wrapper class.
    Edited by: jverd on Oct 27, 2009 3:38 PM

  • Why to use wrapper class?

    hello,
    can anybody please tell me why wrapper class are used in JAVA and what are exactly wrapper class?
    reply me soon....

    I want to give an example and then explain why it is for. Primitives will be good example for this situation.
    Example:
    Below are the primitive types and their wrapper classes...
    Primitive to Wrapper Class
    byte - Byte
    short - Short
    int - Integer
    long - Long
    char - Character
    float - Float
    double - Double
    boolean - Boolean
    USING OBJECT CREATION
    Think a situation when you create an integer object using this code:
    ---> Integer intVar = new Integer();
    you have the methods and constants:
    1 MAX_VALUE ,
    2 MIN_VALUE ,
    3 byteValue() ,
    4 compareTo(Integer anotherInteger) ,
    5 compareTo(Object o) ,
    6 decode(String nm) ,
    7 doubleValue() ,
    8 equals(Object obj) ,
    9 floatValue() ,
    10 getInteger(String nm) ,
    11 getInteger(String nm, int val) ,
    12 getInteger(String nm, Integer val) ,
    13 hashCode() ,
    14 intValue() ,
    15 longValue() ,
    16 parseInt(String s) ,
    17 parseInt(String s, int radix) ,
    18 shortValue() ,
    19 toBinaryString(int i) ,
    20 toHexString(int i) ,
    21 toOctalString(int i) ,
    22 toString(),
    23 toString(int i) ,
    24 toString(int i, int radix) ,
    25 valueOf(String s) ,
    26 valueOf(String s, int radix)
    now you have an object with 2 constants and 24 methods.
    USING WRAPPER CLASS
    and think using wrapper class of Integer..
    CODE ---> int intVar = Integer.parseInt((String)someStringData);
    In this case your Integer object have the methods and constants
    1 MAX_VALUE ,
    2 MIN_VALUE ,
    3 parseInt(String s) ,
    4 parseInt(String s, int radix) ,
    5 toBinaryString(int i) ,
    6 toHexString(int i) ,
    7 toOctalString(int i) ,
    8 toString(int i) ,
    9 toString(int i, int radix) ,
    10 valueOf(String s) ,
    11 valueOf(String s, int radix)
    as you in this situation you have 2 constants and 9 methods.
    AS YOU SEE THERE ARE 15 METHODS DIFFERENCE FROM THE OBJECT AND THE WRAPPER CLASS OF INTEGER OBJECT.
    NOW TALKING ABOUT PRIMITIVE TYPES ALL PROGRAMMERS USED THIS TYPES FOR THEIR CODES AND THEY ALWAYS NEED SOME THIS KIND OF CASTING. IN MY EXAMPLE I TAKE THE VALUE OF AN STRING VARIABLE. AND THERE ARE LOTS OF THINGS SIMILIAR TO THIS EXAMPLE.
    IDEA OF THIS WRAPPER CLASSES IS THAT USE AS YOU NEED NOTHING MORE. IN THE WRAPPER CLASS YOU DONT HAVE INTEGER OBJECT. YOU ONLY NEED THE PARSEINT METHOD OF INTEGER OBJECT INSTEAD OF CREATING THE INTEGER OBJECT YOU USE THE WRAPPER CLASS OF THIS TYPE...
    OBJECTS ARE STORED IN A MEMORY PLACE CALLED HEAP WHICH IS PLACED ON RAM AND GARBAGING OF THIS OBJECTS TAKES MORE TIME TO ALLOCATE FROM HEAP STORAGE.
    AND ANOTHER NOTE FOR THIS WRAPPER CLASSES if you want to store an int inside a container such as an ArrayList (which takes only Object references), you can wrap your int inside the standard library Integer class
    EX:
    import java.util.*;
    public class ImmutableInteger {
    public static void main(String[] args) {
    List v = new ArrayList();
    for(int i = 0; i < 10; i++)
    v.add(new Integer(i));
    // But how do you change the int inside the Integer?
    } ///:~
    GOOD LUCK...
    REALKINGTA....

Maybe you are looking for

  • Empty on the fields of activity description in CATS_DA

    Hello Experts, We use CAT2 to post some absence , and we can see the activity description related here. But when we try to use CATS_DA to to download report, some of rows are empty on the activity desciption fields. Who know why ? and how to solve ?

  • Caching the web service data in Flex 3.0

    Hi, I want to do the following task I am loading about 10000 records from MS SQL database into Flex data grid using web service on CreatinComplete event of an application in Flex 3.0.Now if I have done this and I press Browser refresh button, this ti

  • Load balancing with HttpClusterServlet

              Hi,           Could someone plz tell me how HttpClusterServlet achieves           load balancing?           Suppose there are 3 servers A,B,C (ordered list) in a cluster.           When the servlet the receives the request for the 1st time

  • What is going on for Ruby and RoR at OOW?

    http://db360.blogspot.com/2008/08/what-is-goign-on-for-php-and-ruby-on.html

  • .zip icon is blank white rather than the default Tiger .zip icon.

    Recently I removed StuffIt from my Mac and now when I have a .zip file sitting on my desktop it has a generic white icon rather than the default .zip icon (which I seem to remember was white with a zip through the middle). I was wondering if there is