There are various compound assignment operators, however it is only necessary to know the 4 basic compound assignment operators for the exam, being as follows: += (Addition compound) -= (Subtraction compound) *= (Multiplication compound) /= (Division compound) Essentially, they’re just a lazy way for developers to cut down on a few key strokes when typing […]
Category: SCJP
Static members…
Statics are a rather strange beast, they belong to no instance of a class, they have no fixed abode, other than their class.. Consider the following example : Statics don’t belong to any instance, they belong to the class itself. So there is only ever one copy of a static member (method or variable). Statics […]
Local variables are variables that are declared locally, funny that eh? This one should be nice and easy, lets have a look at a quick example : Some really easy things to remember, local variables don’t ever get initialised automatically, so you have to do that yourself. The method above, doSomethingElse, the variable gets declared, […]
We’ve already touched upon various modifiers, for classes (both access and non-access), but there are also some more modifiers for members, as detailed here. We have the following modifiers for members : final – Can’t be overridden abstract – No implementation specified, subclass must implement synchronized – Only a single thread of execution can pass […]
Class Modifiers (non-access)
In addition to class access modifiers, classes can also be marked with non-access modifiers. These modifiers imply rules on a class, but are not necessarily linked to access rights. The following non-access modifiers are available: final – The class can’t be extended. abstract – The class has to be extended, and can’t be instantiated on […]
Class Access Modifiers
Class access modifiers define who can see the class, you use it on a daily basis, have a look at the following : There you go, you said “public class”, thats you saying that this class is public, and anything can access it. It is important to note, that even though a class may be […]
As of Java 5, methods are now able to accept from 0 to many arguments. Sounds confusing, but you could actually be using it already without knowing, how about looking at your main methods? As we can see above, var args are declared as TYPE… NAMEOFVARIABLE. Lets take a look at a basic example I’ve […]
Coupling and cohesion are two terms that often get mixed up, however they are actually really simple concepts, and the bonus is, they don’t just apply to Java. Coupling Coupling, in its purest terms, means “the degree to which one class knows about another class”. If one class uses another class, that is coupling. Coupling […]
The conditional operator, or ternary operator as it is otherwise known is a great way for assigning variables based on boolean tests. For example you may have seen the following : Pretty simple right? However that if-else statement is a bit messy considering all we’re doing is checking a condition and then using the output […]
One of the great features of any programming language is the ability to repeat blocks of code, sometimes indefinately, sometimes until a certain condition is met, or for a set number of iterations. Luckily, Java comes with several flavours of loops, let have a brief look at our options The “for” loop – The for […]