When to use short and byte

when do i should really use byte and short anyway?
let's say i'm writing a MIDlet and i really really want to save up some memory at run time, would it be helpful if i will use short and byte if i dont need large numbers? let's say i only need a maximum representation of 500?
i know int is commonly used, but is it worth the change?

I don't know about the Micro Editon VM, but the Java Standard Edition run-time VM has no special instructions for operating using byte primitives as opposed to, say, integer or short primitives, and byte primitives in the VM are stored as ints, I believe. So, chances are your optimizations of these primitives aren't going to save you that much in terms of speed or memory. However, again, my previous comments only apply to the Standard Edition VM [feel free to correct them if I am wrong, as I am not sure if these restrictions have changed since Java v1.3 or not].
Plus, if your value is going to be a maximum of 500, you need a short because the signed byte primitive will only be valid across the -128 to 127 range.
-Dok

Similar Messages

  • When to use inheritance and when not to?

    I've just been trying find out when to use inheritance and when not to use inheritance? I know that inheritance gives advantages such as code reuse and maintainability. But when are their times not to use inheritance that may effect the design of a project?
    Also when should one consider aggregation over inheritance(is-a relationship)?
    thanks,
    plandis

    Hi
    Answering this question usually requires a few books, so, I'm sorry, it's not really as simple as choosing between using a screwdriver vs. a hammer.
    But, very short, inheritance should ideally only be used when there exist a strict 'is-a' relationship. However, sometimes it may be clever to inherit when you have a 'is-almost-a' relationship... And sometimes this is a stupid move. This depends on the context/circumstances.
    Aggregation is normally considered a 'has-a' relationship, thereby differing clearly from inheritance. The old 'car' model says "a car is-a vehicle and has-some (at least) wheels."
    The wheels are aggregated to the car class, that itself is inherited from vehicle.
    However, this is just a good rule-of-thumb and there may be circumstantial reasons for not following these guidelines.

  • WHEN TO USE SYS_REFCURSOR AND WHEN NOT TO USE REFCURSOR

    SYS_REFCURSOR is a Weakly Defined Cursor
    DECLARE emp_refcur SYS_REFCURSOR;
    when this is so simple
    why this
    DECLARE TYPE emp_cur_type IS REF CURSOR RETURN emp%ROWTYPE; my_rec emp_cur_type; ?
    Can anyone explain in what situations we should prefer among these ..when both can give same result set .

    > WHEN TO USE SYS_REFCURSOR AND WHEN NOT TO USE REFCURSOR
    When the requirements define that one is better suited than the other.
    There are no hard and fast rules about when to use a specific tool. There are however basic concepts of what the purpose of the tool is, and what typical problems the tool can address.
    Ref cursors in PL/SQL.. usually not the best of ideas. Ref cursors are designed for client-server processing.
    1) The client makes a request for data/information.
    2) PL applies the back-end server logic and construct a SQL statement for the client.
    3) PL passes the SQL to the SQL engine where it is parsed and a SQL cursor created.
    4) PL passes a reference handle to SQL cursor back to the client
    5) The client can now fetch the rows output from the cursor.
    Advantages.
    - The client does not need to know SQL, db structures, business logic, etc
    - The PL code can be improved, modified, new business logic added, without even touching a single byte of client code
    So what are the advantages where the "client" in the above is another PL/SQL program? None really.
    A "real" client (an external one like Java, C#, Delphi, etc) can receive the ref cursor handle and dynamically at run-time determine the projection (output) of the cursor.
    PL code cannot (unless using the latest 11g features). In PL code, a ref cursor is actually implemented as a DBMS_SQL cursor. A DBMS_SQL cursor is to PL code what ref cursor is to Java/C#/etc.
    So whether you define a strongly typed or weakly typed ref cursor in PL/SQL code... typical response is "so what?" as ref cursors are not really intended for PL code. Not that there are exceptions - they do come in handy at times.. but as exceptions to the rule.
    So my response is "so what?" - it is more important to *correctly" chose what type of client cursor data type you want to use to interact with the back-end SQL cursor. Once that decision has been made (based on technical sound logic), then one can look at  (minor) issues such as weak vs. strong ref cursors.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Masterdata - when to use it and when not to use it

    Hi!
    I have had some discussion with my colleagues about the use of masterdata on Oracle databases. Some of them tells me that I should use it if the data don't change often (ofcourse.....). This should ALWAYS be done they say. But I don't agree on this..
    Is it really necessary to make a lot of masterdata (and also views that has to be used) if the data is only to be loaded once a day, and the number of records is max 1000?
    I can't see the effect on this...
    Can someone give me a guideline for when to use masterdata, and when I don't need to use masterdata (if there are any article on this, please give it to me).
    Best Regards
    Helge

    Hi
    Answering this question usually requires a few books, so, I'm sorry, it's not really as simple as choosing between using a screwdriver vs. a hammer.
    But, very short, inheritance should ideally only be used when there exist a strict 'is-a' relationship. However, sometimes it may be clever to inherit when you have a 'is-almost-a' relationship... And sometimes this is a stupid move. This depends on the context/circumstances.
    Aggregation is normally considered a 'has-a' relationship, thereby differing clearly from inheritance. The old 'car' model says "a car is-a vehicle and has-some (at least) wheels."
    The wheels are aggregated to the car class, that itself is inherited from vehicle.
    However, this is just a good rule-of-thumb and there may be circumstantial reasons for not following these guidelines.

  • When I use Mail and want to paste an emailadress with a right mouse click in the adres field this doesn't work, ofcourse cmd V  works. How can I solve this

    when I use Mail and want to paste an emailadress with a right mouse click in the adres field this doesn't work, ofcourse cmd V  works. How can I solve this

    YAY!  That did it.
    Thank you so much.
    And a Very Happy and Prosperous New Year to you!
    bonnie

  • When to use SELECT and END SELECT in the query.

    hi all,
    When to use SELECT and END SELECT in the query.
    regads,
    Venkata Suresh Penke.

    Hi Suresh..
    When do we need to use SELECT .. ENDSELECT
    Usually we will never use SELECT .. ENDSELECT as it gives very poor performance.
    But whenever we read a single Record we will use it as an alternative for SELECT SINGLE in some scenarios.
    Eg: When the Full primary key is not specified in the WHERE clause.
    SELECT * FROM MARC INTO WA_MARC UP TO 1 ROWS WHERE MATNR = P_MATNR.
    ENDSELECT.
    And other scenario is when we perform AGGREGATE OPERATIONS.when the Result is only one row.
    SELECT SUM( LABST ) FROM MARD INTO V_LABST UP TO 1 ROWS
    WHERE MATNR = P_MATNR.
    ENDSELECT.
    Note: In The Above scenario we cannot use SELECT SINGLE..
    <b>REWARD IF HELPFUL.</b>

  • Please give me advices when to use black and white sliders in LR4.

    Please give me advices when to use black and white sliders in LR4.

    I use blacks and white sliders on every photo (this does not necessarily imply non-zero values). I consider them as important as any other slider. Not optional, not for fine tuning - include consideration each iteration.
    Although that is contrary to what Adobe and many "experts" recommend, I tried doing it their way too but I could not get the results I wanted in most cases.
    The "concept" and original intent is for fine tuning, but the implementation is not. I often set whites to +20, +30, +40. This has a radical effect on overall exposure which is the most important thing to get right in PV2012. And it generally requires compensatory adjustment of highlights, shadows, and sometimes contrast...
    Likewise, optimal shadow toning can include radical blacks adjustment  - sorry Adobe/experts/defenders, but for me - it's true. And, blacks slider, like whites, affects entire histogram, a lot.
    Summary:
    ========
    If you want to keep things as simple as possible, then use sparingly and use last (gag), but if you want your photos to look how you want them to look - as good as possible, then use liberally, and pay the price...
    More info here: http://forums.adobe.com/message/4259091#4259091
    Rob

  • When to use jsp,and when to use servlet?

    I think that jsp and servlet can realize the same functions, because when run a jsp, it is transferred to a servlet program, so when to use jsp and when to use servlet?
    I am now developing the input interface for a website, I just use jsp and javabean to connect to weblogic and database, and I didn't use servlet, Is there any unseemliness?
    Thank you!

    IMHO I use servlets to control the flow between my jsp's based on a number of factors in a webapp. For instance, user authorization. If a user has the authorization to conduct various administrative functions on an application (like change user rights, reset passwords etc) they will have access to specific buttons or links on some screens that others will not. I use servlets to establish what access rights a user has and direct them to the appropriate pages. I also use servlets to test data validity on form input screens. I know that I can also do this with JavaScript but that can be disabled by the client and in order to prevent that I also double check the form input from a servlet. All my jsp's do is display the results of a business process (which is held in a JavaBean or EJB) and the servlets act as the controllers for the application, connecting to multiple databases, verifying application state, flow control etc. I try to keep the jsp as simple as possible as some of them are maintained by html developers who lack the necessary experience to write java code. I hope this helps.

  • When i use Firefox and do a Google search, find what i need and click on the link I keep getting automatically redirected to another search site

    When i use Firefox and do a Google search, find what i need and click on the link I keep getting automatically redirected to another search site called http://www.scour.com
    Can someone tell me if this is a problem with Google or Mozilla? or both? or neither?

    This type of behaviour can be caused by malware. Try running several malware scanners. It is best to run several as each will pick up things that the others miss. Some scanners you can try are:
    * [http://www.malwarebytes.org/mbam.php Malwarebytes]
    * [http://www.superantispyware.com/ SUPERAntiSpyware]
    * [http://www.lavasoft.com/products/ad_aware_free.php Ad-Aware]
    * [http://www.microsoft.com/windows/products/winfamily/defender/default.mspx Windows Defender]
    * [http://www.safer-networking.org/en/home/index.html Spybot S&D]
    This link may help - http://deletemalware.blogspot.com/2010/02/remove-google-redirect-virus.html
    If the above malware scanners do not find any malware or can not clear it, you should consider posting in one of these forums for specialized malware removal help:
    * http://forums.spybot.info/
    * http://www.spywarewarrior.com/index.php
    * http://forum.aumha.org/
    * http://www.bleepingcomputer.com/forums/
    * http://www.spywareinfoforum.com/

  • Since i uploaded ios 5 my ipad crashes when i use apps and safari.

    Hi,
    since i uploaded my ipad to ios 5 it crashes when i use apps and safari.
    i tried to restat it and also i reset it to the factory settings but nothing has changed.
    is there any software problems ??

    seems if I disable all security it works. Not a very good situation, tells me it's a port that is open that shouldn't be. I imagine it is fine on a mac, but on a pc it is an issue since most corporations use pc's.

  • I HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N"SE

    HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N". I HAVE CONNECTED A NEW KEYBOARD BUT THE PROBLEM STILL EXIST. WHAT ELSE CAN I DO?

    You might look at "Keyboard Shortcuts" in the Keyboard and Mouse preference pane and see if somehow the lower case n has been inadvertently assigned to something.
    Probably the best solution would be to click the "Restore Defaults" button.

  • My iphone 4s keeps freezing up. I have restored it as a new phone. Done numerous resets. But it still keeps freezing up when im using apps and trying to text. Its really annoying.

    My iphone 4s keeps freezing up. I have restored it as a new phone. Done numerous resets. But it still keeps freezing up when im using apps and trying to text. Its really annoying.

    Oh OisinC7,
         I'm aslo experiencing similar problem. Tell me your country and what apps make your phone freeze?

  • When to use interface and when Abstract Class?

    In a recent interview I was asked "When to use interface and when Abstract Class?" Explain with an example.
    Also in what situations a class should be made final(real time example)

    Interface is a pure contract with no implementation. Typically used to define a communication contract between two different sub-systems. Example EJB home interface. This also allows the design to change as long as the contract is met.
    Abstract class is when there exists a lot of common functionality already known and can be coded. However, a few unknowns exists (typically about data) for which abstract methods need to be defined and implemented by the sub class.
    Example: Consider a workflow engine. A great example for abstract class. The workflow process has lot of common code that is independent of the workflow type (vendor flow, contract flow, payment flow etc). However, certain decisions on the route to take will depend on value of data being submitted. So the base class will define a abstract Data getData() method and proceed assuming data will come. The implementing subclass will provide the actual logic for getting the data.
    Also see the "Template" design pattern.
    Note: To some extent the common code design drives the behavior of the abstract methods. So if the design changes then so "might" the behavior expected from the abstract methods.

  • Use always int or short and byte if int is not needed?

    If I have a variable for percentage and if I don't want to use double or float, what type should the variable be? byte? short? int? long?
    Is there a rule? What is a good style?

    The problem is with casting and that it seems that
    Java programmers just use int and double no matter if
    they really need such great values and precision.
    Am I right?You're probably right. I have standardized on int/double, but always use getter/setter methods. In this way I can change the internal representation of variables, for example to save memory space, without affecting the rest of the program. For variables declared in methods I think it's worth using int/double even if you could use "smaller" types. The memory allocated for those variables are reclaimed when the method ends and you don't have to bother much with implicit conversions.

  • Comparing between short and byte operations

    Hi, all!
    I want to optimize performance of my applet. I have realization of block cipher that work using bytes. But for optimization purpose I rewrite encryption algorithm for short values. In simulator it works 3,5 faster, but when I test it in real card it works 4,5 slower. I use JCOP J2A080 java card.
    Has anyone such a problem?
    P.S. before optimization I tested different operations in card such : add, shift, xor, and, read/write and for short it works faster.
    Code before optimization
        public static void add(byte[] x, short xLen, byte[] y, short yOffset,
                   short yLen) {
              short carry = 0, i = 0;
              while (i < yLen) {
                   carry += (short) ((x[i] & 0xFF) + (y[i + yOffset] & 0xFF));
                   x[i++] = (byte) (carry & 0xFF);
                   carry = (short) ((carry >>> 8) & 0xFF);
              while (i < xLen) {
                   carry += (short) (x[i] & 0xFF);
                   x[i++] = (byte) (carry & 0xFF);
                   carry = (short) ((carry >>> 8) & 0xFF);
         private void mainStep(byte[] n1, byte[] key, short keyOffset)
              add(n1, (short) 4, key, keyOffset, (short) 4);
              Util.arrayFillNonAtomic(om, (short) 0, (short) 4, (byte) 0);
              om[0] = sbox[0 + (n1[0] & 0xF)];
              om[0] |= (byte)(bArr[1 + ((n1[0] >>> 4) & 0xF)]<<4);
              om[1]  = (byte)(bArr[2 + (n1[1] & 0xF)]);
              om[1] |= (byte)(bArr[3 + ((n1[1] >>> 4) & 0xF)]<<4);
              om[2]  = (byte)(bArr[4 + (n1[2] & 0xF)]);
              om[2] |= (byte)(bArr[5 + ((n1[2] >>> 4) & 0xF)]<<4);
              om[3]  = (byte)(bArr[6 + (n1[3] & 0xF)]);
              om[3] |= (byte)(bArr[7 + ((n1[3] >>> 4) & 0xF)]<<4);
              n1[3] = (byte) ((om[2] << 3) | ((om[1] & 0xFF) >>> 5));
              n1[2] = (byte) ((om[1] << 3) | ((om[0] & 0xFF) >>> 5));
              n1[1] = (byte) ((om[0] << 3) | ((om[3] & 0xFF) >>> 5));
              n1[0] = (byte) ((om[3] << 3) | ((om[2] & 0xFF) >>> 5));
         }Code after optimization:
         private void mainStep(byte [] bKey, short j)
              short om1 = Util.getShort(bKey, j);
              short om0 = (short)(n_0 + om1);
              //change from add function
              if((((om1 < 0)&& (om0 >= 0)) && (n_0 >= 0))
                        ||
                   (((om1 < 0) || (om0 >= 0)) && (n_0 < 0)))
                   n_1 += 0x1;
              n_0 = om0;
              n_1 += Util.getShort(bKey, (short) (j+2));
              //and add function
              om0 = (short)(bArr[n_0 & 0xFF]&0xFF);
              om0 |= (short)((bArr[1+ ((n_0 >>> 8) & 0xFF)])<< 8);
              om1 = (short)((bArr[2+ (n_1 & 0xFF)] & 0xFF));
              om1 |= (short)((sbox[3+ ((n_1 >>> 8) & 0xFF)])<< 8);
              n_0 = (short)(( om0 << 11 ) | ((om1 >>> 5) & 0x7FF)) ;
              n_1 = (short)(( om1 << 11 ) | ((om0 >>> 5) & 0x7FF)) ;
         }

    From my point of view, simulator is suitable for the logical functionality testing of your application. In order to benchmark your application, you should use an emulator whose configuration is close to your real card.
    I used to participated into a smart card benchmark project. The real performance depends on many factors, even the driver for the card reader can affect the application performance. I've never used a simulator to test an application performance so I haven't got any problem like yours. Just some ideas to share with you.
    Best regards,
    JDL

Maybe you are looking for

  • ST-PI plug- in

    Hi SAP, We are planning to do ST-PI plug in upgrade in ECC for theTechnical preparation of GFLUV Session, do u think that do  we have to do any preparations on the BW side. Also I dont think BW extractions will be affected, any advices. Kindly please

  • I need to just reinstall Bridge?

    I recently removed some trial software off my computer, but for some reason or another it took Bridge with it. It was the version of Bridge that came with Illustrator and Photoshop CS2. Can I just use the CD and reinstall Bridge? or is there somethin

  • Adjustment Layer gone nuts

    For some reason I am having savage problems with adjustment layers in premiere. I have a sequence with a few video layers, one of them has a track matte applied, one of them is has an alpha, and a AL on top. At the start of the sequence, an effect ap

  • JES 2005Q4 installation problems

    When I start the installation it is not copying any files to any folder. On the screen only this message showing: OrionUninstallersun-ps7_0-entsys %1 OrionUninstallersun-ps7_0-entsys %41 OrionUninstallersun-ps7_0-entsys %71 and after the installation

  • Image Sizes in iDVD Themes

    I know this has been asked before but there doesn't seem to have been a definitive answer. What size and resolution do images need to be in order to fit into the standard drop zones in iDVD vers 7. I realise they can be repositioned by holding down c