After recently sitting a course and exam for ITIL v3 Foundation, I thought it would be a good idea to reflect on some of the topics covered while they are fresh on my mind, and to also provide good future references.
I will try to cover the topics the exam requires you to know in order to pass, I’ll try to write an easy to understand guide, as when I was researching for specifics I was often overloaded with information and found it quite difficult to understand, hopefully I can target those that want a quick and brief introduction.
I will organise all my posts under a resources page, which should link out to the relevant articles, to keep it nice and tidy
The operators for incrementing and decrementing in Java has been irritating me for some time now, just when I think I understand whats going on, I try a mock exam for SCJP and I get caught out. So I’ve decided to sit down, do a bit of reading, and drill it out.
Take this example, what do you think the output will be?
int a = 1;
int b = 5;
System.out.print("a++ is : " + a++);
System.out.print("++b is : " + ++b);
The output will be :
Right heres the explanation. We have two things going on here, we have a Postfix(b++) operator and a Prefix(++b) operator.
What this means, in plain and simplest English is as follows
<em>a++ means, use the value of a in the executing statement, THEN increment it</em>
<em>++b means, BEFORE we use the value of b, increment it</em>
So there you have it, if the operator comes before the variable <em>(Prefix)</em>, it means do the incrementing/decrementing before you evaluate the expression in question, and if the operator comes after <em>(Postfix)</em>, then use the current value of the variable, and when thats done, increment it (maybe for use next time, such as in a loop?)
The same works for the decrementing operator, such as –a or a–