Unfortunately, some people have a very rudimentary way of understanding basic things. I’ve been asked on several occasions to explain simple programming concepts that seem to escape them.

Now, anyone with even a slight grasp of programming knowledge will likely raise one of their eyebrows and put even Mr. Spock to shame, because this is the kind of stuff we learned by ourselves when we were nine years old. However, I’m not an elitist (mostly) and things like this remind me of how much I felt sorry for the poor fools in high school who couldn’t even spell their own name because they were too busy SMSing each other about their lack of genitalia while bathing in copious amounts of turpentine.

.

First of all, understanding how object-orientation works is of paramount importance. Visualising code in your head without writing it down and staring at it for hours wondering what it’s supposed to do is a handy skill to have. This is explicit with Java only (which is a crap language, but is popular because people are obese and lazy), but is easily transferable to other OOP languages.

So, say I wanted to create a simple program that outputted the text “You are fat.” in an OOP-like fashion, it would be something like this:

.

YouAreFat.java

public class YouAreFat {
String message;

.

This stores a piece of data (’message‘) as a unique part of the class YouAreFat. (Technically, it’s a reference, but people just say that to try and make you look stupid.)

.

public Message(String conMessage) {
this.message = conMessage;
}

.

This is the actual constructor for the message. By doing this, the message can be modified to be anything the programmer wants it to be, and have multiple, different instances of it. Pretty useless, you might think? Right now, yes. But this allows high scalability and flexibility because you can add a lot more variables and data if you needed to without giving you a headache later on.

(The reason I prefix ‘con‘ to ‘conMessage‘ is to indicate that it’s a construction variable. This is just for aesthetics.)

This is the ‘test’ code; this is what calls the shots, so to speak. Formally, this part of the code should be separate and in its own file — the reason behind this is to make the code easier to change and look less obfuscated (cluttered to you illiterates). However, I usually ignore this unless the program is huge, because it’s a stupid rule. So, why not just write System.out.println(”You are fat.”);? Because then it would not be very object oriented, and you can’t build on it and manipulate it. This is how you learn how it’s supposed to work — by starting off with something simple and easy to understand.

Message Message01 = new Message(”You are fat.”); instantiates the constructor. Basically, this is saying “I want to make a Message object, called Message01, and give it a string of text that reads ‘You are fat.’”. The line after that, System.out.println(Message01.message);, gets the data of the message and outputs it as text.

Think of it like an MP3 player, or iPod. Each music track is like a constructor:

This is basically the same concept. This is important. You must understand this concept, and so many people don’t.

Let’s say you want to expand upon your iPod (or JavaPod, actually). You want it to distinguish between band and song, maybe so you can order them alphabetically in the future, or see how many songs from each band you have or something. Easy!

And this creates and displays the track. Notice there are now two inputs in Song.

However, let’s just say we accidentally named a track wrong, and we want to change it. All we would have to do is create a method for changing an object’s data, and then run it in the test program (or main).

We add:

.

public void setTitle(String mutTitle) {
this.title = mutTitle;
}

.

This is a void because it’s not going to return any data, it’s just going to change (mutate) the data of an object. The reason I prefixed ‘mut‘ to ‘mutTitle‘ is to indicate the input is a mutation; aesthetics again.

We then add this to the main:

.

Track01.setTitle("Destroy All Humans");

.

Now Track01’s title will now display as something different when written to the screen!

Here is a slightly modified version of what the above code should look like at last:

The for loop and track representation through an array is just a cleaner way of outputting an index of items that would otherwise clutter up the code. It’s the same as writing System.out.println(”Title: ” + Track01.title + “\nBy: ” + Track01.band); three times, only changing the number in each one. Don’t worry about understanding this if you failed grade 1 math.

Learning the rest is SO easy once you know this horribly basic and simple part. Hammer it into your head, preferably with something heavy and made from iron.