Pre/Post increment query

I have a query regarding Pre/Post increment.
The following code:
int x = 0;
int y = 0;
x += y++;
System.out.println("x = " + x);
System.out.println("y = " + y);
Produces the following output:
x = 0
y = 1
(Value of y is assigned to x, y is then post incremented).
This makes sense to me. However the following code,
the value of x does not get incremented. Can someone
explain this to me?
The following code:
int x = 0;
x += x++;
System.out.println("x = " + x);
Produces the following output:
x = 0
(Value of x is assigned to x, then x does not get post incremented??).

I code with the mind set of "If the code is not self explanatory or obvious, then
it's too confusing and should be avoided".
I am studying for the Java Programmer Certification exam, so this query was more
to try and understand why the output did not match what I had expected.
So
x += x++;
is the same as (where x' refers to the original value of x)
x = (x) + (x++);
which is then executed in the following order:
x = x++; //(x = x + 1) post incrementation
x = x' + x'; //(x = 0 + 0) evalutation of the assignment
Thanks for all the responses!!

Similar Messages

  • Possibility to register Pre-/Post-Procedures for an SQL Template Handler

    I would appreciate to see the possibility to register pre-/post-procedures for an SQL template handler in ORDS 3.0.
    Why:
    We use Oracle VPD/Row-Level-Security to secure data access. Hence a trigger sets a couple of attributes in the database session context at login time which are then used in static RLS predicates to limit which records the user can see/modify.
    With ORDS 3.0 all sessions are opened under the same technical user (e.g. APEX_REST_PUBLIC_USER), hence all users have the same/no attributes in the session context and could see/modify all data.
    To avoid this situation, I need to set the attributes (e.g. the authenticated user) in the database session context before the actual query/plsql handler is executed.
    Also, resetting the session context after the handler is executed would be good.
    This scenario is in line with scenarios 'One Big Application User' and 'Web-based applications' in http://docs.oracle.com/cd/B28359_01/network.111/b28531/vpd.htm#DBSEG98291.
    Different solution approach:
    Kris suggested to write a PL/SQL handler where the pre-procedure is called before the business logic procedure/query. This is ok for me as long as I modify data and only need to return no or little data.
    As soon as I need to return a lot of data (e.g. select c1, c19, c30 from t1), this approach will force me to write a lot of code in the PL/SQL handler in order to marshal the c1, c19 and c30 to JSON and put it in the HTTP response.
    But this is the beauty of ORDS - I can simply define a template, write a GET SQL Handler 'select c1, c19, c30 from t1'  and have the data available as REST service, without writing any code to write JSON marshaled data in the HTTP response.

    I tried to log the request at Oracle REST Data Services (ORDS) but I could only start a new discussion: Possibility to register Pre-/Post-Procedures for an SQL Template Handler
    As I mentioned there, the PL/SQL handler approach works for me as long as I have no or only little data to send back to the client (e.g. put/post/delete succeeded or an error message why the call failed).
    If I need to return a lot of data from the PL/SQL handler I would need to, as far as I understand, to marshal the data to JSON and write it to the response body in the PL/SQL handler.
    I don't want to do the marshaling, because ORDS does it better.
    However, this works for me:
    I write a pipelined stored procedure that takes as input the attributes I need to set in the session context. I then can reference it in the SQL handler:
    select * from table(my_pipelined_function(:USER, ....)
    Now the JSON/HTTP response is created by ORDS again.
    I still needed to code a couple of lines, but it is way better than duplicating the functionality already existing in ORDS.
    With the hooks it would be perfect because I would not have to write any code (apart from the procedure to set the session context attributes), just configure the REST services in ORDS.

  • Post increment problem. please help to solve it

    public class test {
    public static void main(String args[])
         int i=10;
         i=i++;
         System.out.println(i); // value of i is 10 why
    }

    Mostafa.Hashem wrote:
    Absofuckinglutely NOT !
    1) Save current value of x. That is, 1. This is the value of the expression "x++".
    2) Increment x. x is now 2. We have now completed x++
    3) Assign value from step 1 into y.i wonder how small point like this takes all that time.
    Mr Jverd,
    the difference between prefix increment and the postfix increment is :
    IN PREFIX INCREMENT THE ASSIGNMENT OF EXPRESSION DONE FIRST THEN THE INCREMENT.
    IN POSTFIX INCREMENT THE INCREMENT DONE BEFORE THE ASSIGNMENT.Wrong.
    ++x and x++ are both expressions. They have a value and a side effect.
    In pre-increment (++x) the increment is done before the expression is evaluated. The value of the expression is the new value of x.
    In post-increment (x++) the increment is done after the expression is evaluated. The value of the epxression is the original value of x.
    In both cases
    y = ++x;
    y = x++;
    The right-hand side is evaulated completely before the assignment to y is done. In fact, in ALL java assignment statements, the RHS is evaluated completely before assigning anything to the LHS.
    y = ++x;
    is equivalent to
    x +=1;
    y = x;
    y = x++;
    is equivalent to
    tmp = x;
    x += 1;
    y = tmp;

  • Annoying screen on pre-POST

    Hi all, i used the search function and Google but I don't found a query that explains my question.
    Some years ago I bought a new video card for my computer, a Point Of View Graphics equipped with an NVIDIA GeForce 9600GT GPU. As I installed it my computer shows for a second or two a pre-POST black screen with the card specifications (brand, model, RAM, etc.), and I've always found this very annoying, but I didn't care cause 2/3 seconds in a global boot time of 45 seconds were not so important. Now I bought a new computer but i kept the video card, i have an SSD and the overall boot time is about 15s, so 2s become significant. Nothing of tragic, but man lives to walk up to perfection so... How can I remove it? Thank you!

    GE wrote:
    https://wiki.archlinux.org/index.php/NV … on_startup
    Is it this or something else?
    I don't know but I don't think so, cause it's on pre-post, when the computer has not started nor the BIOS. I'm going to make a video.

  • Error during setup of VSLS2011 "setup.exe: [2] ISetupComponent::Pre/Post/Install() failed in ISetupManager.."

    Hi
    I have VS 9 installed and was wanting to install LightSwitch so downloaded the ISO(VSLS2011_ENU.iso) and burnt to disk ran
    setup.exe and received the this message.
    "Setup could not install the following component:
    Microsoft ApplicationError Reporting"
    The log shows..
    [02/09/15,13:52:02] Microsoft Application Error Reporting: [2] CMsiComponent::Install() expects the setup file for Microsoft Application Error Reporting, but the file failed verification.
    [02/09/15,13:52:03] setup.exe: [2] ISetupComponent::Pre/Post/Install() failed in ISetupManager::InternalInstallManager() with HRESULT -2147467259.
    [02/09/15,13:52:04] SimpleUI: [2] DepCheck indicates Microsoft Application Error Reporting is not installed.
    [02/09/15,13:52:05] SimpleUI: [2] DepCheck indicates VC 9.0 Runtime (x86) was not attempted to be installed.....
    .NetFramework 3.5
    C:\Users\xxxxxx>Winmgmt /verifyrepository
    WMI repository is consistent.
    PC is win 7 pro 64bit 

    Hi ghw123,
    Welcome to Lightswitch forum.
    According to the error message above, this issue is related to verification. For this issue, you need make sure that you download VSLS2011_ENU.iso from Microsoft official site, see:
    http://download.microsoft.com/download/8/0/0/80047AD9-1D3E-46EB-8CF8-DFDA59E7799D/VSLS2011_ENU.iso 
    In addition, if you want to learn LightSwitch, I'd like to suggest you to download VS2012 or VS2013, many new features are added to them. see:
    http://www.visualstudio.com/en-us/downloads
    You need select the Lightswitch option when you install VS2012/VS2013.
    Best regards,
    Angie
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Pre/post processing

    Hello group!
    Configuration:
    Oracle 8.1.7
    XDK 9.0.0.0.0(beta)
    We use XSQL Servlet scripts (great framework!). We tried to provide single entry point into our webapp. We want to replace XSQLServlet class, and gain control of our servlet environment (transactions, thread synchronization, logs...).
    Problem is, if we replace XSQLServlet class with our own class (which extends HttpServlet), we can't use XSQLPageProcesor directly because it is declared private for XSQLServlet package.
    So, we try to use XSQLRequest class and construct an instance with XSQLServletPageRequest as parameter and then call XSQLRequest.process().
    It works ,but ...
    When we attach object with setRequestObject (), requestProcessed is never called.
    Why? We mist something?
    If we use XSQLRequest (URL url), must we handle sessions, request parameters, cookies ...?
    Where is the best place to put pre/post processing of request?
    Thanks in advance
    Tomi
    null

    We found just XSQLPageRequest.setRequestObject(), that we already try to use (first post in thread).
    We associate *.xsql with our HttpServlet because we want to transparently add controller object(s), and we want to turn this feature off in servlet engine config whenever we want. If we forward it (getServletContext().getRequestDispatcher().forward()), with same name and extension ...
    Some code:
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    XSQLServletPageRequest req = new XSQLServletPageRequest(request, response, myContext);
    //TransactionController implements the XSQLRequestObjectListener
    req.setRequestObject("transaction",new TransactionController(req));
    XSQLRequest xsqlrequest = new XSQLRequest(request.getRequestURI(), req);
    try
    xsqlrequest.process(response.getOutputStream() ,new PrintWriter(System.err));
    catch(Exception ex)
    ex.printStackTrace();
    return;
    }When we call XSQLRequest.process, servlet response just fine (except we lost default encoding windows-1250?).
    TransactionController is properly attached, but requestProcessed is never called.
    We found why. Maybe?
    XSQLRequest.process call createNestedRequest from XSQLServletPageRequest, and then setIncludingRequest.
    This seems like little overhead :)
    We just want to keep our XSQL Scripts clean from including controllers via custom actions in every page.
    Can we do that?
    Anybody tried something similar?
    Thanks for your time
    Tomi
    null

  • Is there any event callback for "pre/post-register/unregister" object?

    Dear all,
    We noticed that there are rich set of event callback provided by TopLink, including "pre/post-Refresh/Build/Clone/Merge". However, we cannot found any callback method for "pre/post-register/unregister" events. They will be very useful, if we to manage the internal status of register/unregister to indicate whether it is still under the control of TopLink.
    Thanks and regards,
    William

    William,
    Those specific events do not exist. The postClone event is called after an object is registered. This is frequently used to copy non-persistent values from the cached original into the working copy.
    There is also the ability to customize the clone/copy policy used by TopLink in creating the working copies in the UnitOfWork.
    http://download-west.oracle.com/otn_hosted_doc/toplink/1013/DP4/_html/descfg028.htm#sthref3950
    Doug

  • Pre-post / parked document in outgoing payment posting

    Hi Experts,
    could any of You, please confirm, if possible to create pre-posted / parked document for outgoing payment?
    We use F-53 / FBZ2 for this action, but sometimes takes a long time to select all items related to a bank payment note. The user want to have  only one final document, no partial bookings.
    Is there any possibility to create parked / dummy version here, to pause the administrational process and continue later, without loosing the data?
    Answers will be appreciated

    Hello,
    Please try recurring entries using transaction code F.14.
    I think there is no account assignment model or sample document where we can create for outgoing payments.
    Thanks
    Sharan

  • Post budget document from approved pre-posted budget document workflow

    Hi,
    We are using budget version "0" for AVC Check and "1" for provision budget used for sending further approvals.
    I am uploading provisional budget i.e Pre-posted budget with version "1"  and sending  two levels for approvals by using SAP Standard workflow.
    If pre-posted budget document approved by 2 levels, what is impact on budget posted document?
                       a) Will Pre-posted approved document be convert into Actual budget document with Version "0" (or)
                       b) Will Pre-posted document remain same by updating status with "approved", there by User again needs to post actual budget document with Version "0" by using "FMBB"
    Please help me
    Regards
    Sam

    CA Sam,
    The Pre-posted document will remain the same i.e.approved version 1. In order to create version 0 you can copy from version to version.
    Thanks
    Shyam

  • Post Increment Operator Question

    I had written a small program to test the working of Post increment operator.
    public static void main(String[] args)
         int a = 4;
         a = a++;
         System.out.println ( a );
    I expected the output to be '5', but the output given is '4'.
    Can anyone tell me to how this works in Java ?

    There is a big difference between a++ and ++a.
    a++ means increment a AFTER you have performed the line.
    ++a mean increment a BEFORE you perform the line.
    class Test
    public static void main(String[] args)
    int a = 4;
    a = ++a; //returns a = 5
    // a = a++; //returns a = 4
    //a++; //returns a = 5
    //++a; //returns a = 5
    System.out.println ( a );
    }

  • Bug: CCDoc fails with method group in Contract.ForAll/Exists in pre/post conditions

    When Contract.ForAll or Contract.Exists is used in a pre/post condition, and the predicate given is a method group instead of a lambda, CCDoc fails with the following error:
    CCDoc failed with uncaught exception: Object reference not set to an instance of an object.
    Stack trace:    at CCDoc.CCDocCSharpSourceEmitter.TraverseChildren(IMethodCall methodCall)
       at Microsoft.Cci.CodeTraverser.Traverse(IMethodCall methodCall)
       at CCDoc.XContract.WriteCSharpFromAST(IExpression expression)
       at CCDoc.XPrecondition.WriteTo(XmlWriter writer)
       at CCDoc.XmlTraverser.WriteEndElement(XmlReader reader, XmlWriter writer)
       at CCDoc.XmlTraverserBase.WriteNodeSingle(XmlReader reader, XmlWriter writer)
       at CCDoc.XmlTraverserBase.Transform(XmlReader reader, XmlWriter writer)
       at CCDoc.CCDoc.WriteContracts(IDictionary`2 contracts, Options options, DocTracker docTracker)
       at CCDoc.CCDoc.RealMain(String[] args)
       at CCDoc.CCDoc.Main(String[] args)
    Stack trace can vary, but its always the same method at the top.
    Example code that produces this error: 
    public static class Program
    public static void Main(string[] args)
    Contract.Requires(Contract.ForAll(args, ValidateArg));
    public static bool ValidateArg(string arg)
    return arg != null;

    Hi Lev,
    To your question to clear the track
    You can delete your track as described in the below link, and then recreate the track and reimport.
    Link: [Deleting Track|http://help.sap.com/saphelp_nw70/helpdata/EN/33/71fe94e1834af8b5bd3c0e1de5ab41/frameset.htm]
    Do not forget to delete DTR workspace.
    Do reward points if you find the link useful.
    Cheers,
    Sandeep

  • Posted this query several times but no reply. Please help me out

    Hi all,
    How to know whether a servlet had completely sent its response to the request.
    The problem what i am facing is, I send response to a client's request as a file.
    The byte by byte transfer happens, now if the client interrupts or cancels the operation, the response is not completed.
    At this stage how to know the response status. I am handling all exception, even then I am unable to trap the status.
    Please help me out.
    I have posted this query several times but no convincing reply till now. Hence please help me out.
    If somebody wants to see the code. I'll send it through mail.
    regards
    venkat

    Hi,
    thanks for the reply,
    Please check the code what I have written. The servlet if I execute in Javawebserver2.0 I could trap the exception. If the same servlet is running in weblogic 6.0 I am unable to get the exception.
    Please note that I have maintained counter and all necessary exception handling even then unable to trap the exception.
    //code//
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.security.*;
    public class TestServ extends HttpServlet
    Exception exception;
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException, UnavailableException
         int bytesRead=0;
         int count=0;
         byte[] buff=new byte[1];
    OutputStream out=res.getOutputStream ();
    res.setContentType( "application/pdf"); // MIME type for pdf doc
    String fileURL ="http://localhost:7001/soap.pdf";
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    boolean download=false;
         int fsize=0;
         res.setHeader("Content-disposition", "attachment; filename="+"soap.pdf" );
    try
                   URL url=new URL(fileURL);
         bis = new BufferedInputStream(url.openStream());
         fsize=bis.available();
         bos = new BufferedOutputStream(out);
    while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
              try
                        bos.write(bytesRead);
                        count +=bytesRead;
                        bos.flush();
                   }//end of try for while loop
                   catch(StreamCorruptedException ex)
                        System.out.println("Exception ="+ex);
                        setError(ex);
                        break;
                   catch(SocketException e)
                        setError(e);
                        break;
                   catch(Exception e)
                        System.out.println("Exception in while of TestServlet is " +e.getMessage());
                        if(e != null)
                             System.out.println("File not downloaded properly"+e);
                             setError(e);
                             break;
                        }//if ends
                   }//end of catch for while loop
    }//while ends
              Exception eError=getError();
              if(eError!=null)
                   System.out.println("\n\n\n\nFile Not DownLoaded properly\n\n\n\n");
              else if(bytesRead == -1)
              System.out.println("\n\n\n\ndownload \nsuccessful\n\n\n\n");
              else
              System.out.println("\n\n\n\ndownload not successful\n\n\n\n");
    catch(MalformedURLException e)
    System.out.println ( "Exception inside TestServlet is " +e.getMessage());
    catch(IOException e)
    System.out.println ( "IOException inside TestServlet is " +e.getMessage());
         finally
              try
         if (bis != null)
         bis.close();
         if (bos != null)
         {bos.close();}
              catch(Exception e)
                   System.out.println("here ="+e);
    }//doPost ends
    public void setError(Exception e)
         exception=e;
         System.out.println("\n\n\nException occurred is "+e+"\n\n\n");
    public Exception getError()
              return exception;
    }//class ends
    //ends
    regards,
    venakt

  • Pre/ Post and Post pan colours

    Hi,
    This ain't exactly a show stopper, but..
    In the mixer you can send the feeds as pre, post fader, or post pan.
    These 3 options are supposed to change the colour of the send box.
    Pre is green, post is blue, and post pan is supposed to be orange- but it's not. It is also blue.
    As I said, not exactly worth getting too freaked about!

    Well, there goes my 5 minutes of fame!
    Thanks!

  • Post increment question

    I was looking at this puzzle question:
    public class Assignment {
    public static void main(String[] a) throws Exception {
    int tricky = 0;
    for (int i = 0; i < 3; i++)
    tricky += tricky++;
    System.out.println(tricky);
    tricky is 0. How come the post increment in this case does nothing?

    I was looking at this puzzle question:
    public class Assignment {
    public static void main(String[] a) throws Exception
    int tricky = 0;
    for (int i = 0; i < 3; i++)
    tricky += tricky++;
    System.out.println(tricky);
    tricky is 0. How come the post increment in this case
    does nothing?
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=753569

  • Re: Pre & Post activities for homogeneous system copy

    Dear All,
    can any body help with pre & post activities for homogeneous system copy
    Thanks in advance
    Best regards,
    khan

    Hi,
    Use Oracle Database specific method to perform homogeneous system copy.
    Along with this reference official [system copy guide|https://websmp209.sap-ag.de/~sapidb/011000358700000416402008E.PDF], You can also refer this [useful doc|http://www.basisconsultant.com/component/remository/Sytem-Copy-Guides/Homogeneous-System-Copy-using-OnlineandOffline-Backup/] for the same to have all required pre-post activities information with more details.
    Regards,
    Bhavik G. Shroff

Maybe you are looking for

  • How to setup a forms function in R12 to launch an URL?

    Hi All, In 11i we could create a forms function of the type "SSWA plsql function" to launch a html page from the menu. How is that supposed to work in R12? So my question is, how to setup a forms function to launch an URL like www.oracle.com in R12?

  • How to create a tcode for a program in FMEQ transaction

    Hi ABAP Experts, I need to assign a program from FMEQ transaction to a custom z-transaction code. Can anybody tell me how to do this. I already tried  go to system-status-> "copy program name from here and past it in SE93). This would not work becaus

  • Mathscript Array

    Hello, I wanna use the counter in my While Loop to acces the values of my vector/array inside the Mathscript. However, I get this message error: "Error -90026 occurred at Error in function V at line 1:  The indexes for a matrix indexing operation mus

  • Using remote with music.

    When I use my remote to select the music, and click to start it I would like to use visualization full screen.How do I get it? I know when I have itunes open I can go to the view and click visualization there. Thank you Arlenen Stromnes

  • How to convert windows media file to QT?

    Quality issues aside, I have been given a windows media file to put on DVD. What program can convert it to QT so I can bring it in to FCP? Regards to all.