Guerrilla Java – Pancakes

 

Guerrilla Java

Since I don’t have enough irons in the fire already, I’ve started writing a book on Java – specifically, how to get started with Java if you’re already a developer in another language, and do so FAST.

 

I have a friend who is a developer in PHP, and is wanting to learn Java to move to higher paying, and more enterprise projects. He’s been asking me various questions, and I realized that this might be a good opportunity for me to share what I know, and also distill this down into a format that I can share with more people who are in the same boat as him.

He doesn’t so much care about getting a Java certification, but more about actually being productive in Java as quickly as possible.

So, I’ve whipped up a LaunchRock page where you can signup to get a sample chapter for free, along with pre-order the book.

 

That all being said, I’m sure you’re wondering just what the <bleep> pancakes have to do with Java… ? They’re both breakfast items, right? Ha. Sorry.

 

So, the question of the morning was something like:

 

“What’s the difference between a class and an object”?

 

I was trying to explain it, and for some reason pancake mix popped into my head.

 

Classes, vs. Objects (and this applies to OOP in general, not just Java):

 

Classes are like a box of pancake mix. It has the ingredients, everything you need (pretty much) to create a pancake, but it’s not actually a pancake.

Objects are the pancakes themselves – they each have unique attributes: some are burnt (ask my son), some are big, some small… some shaped like a sickly Mickey Mouse. You can reference them each individually:

 

Pancake mickey = new Pancake();
Pancake burnt = new Pancake();

mickey.setRodentType("mouse");

System.out.println(mickey.getRodentType()); // output: mouse

 

or group them in a Collection defined with Generics:

 

Collection<Pancake> pancakes = new ArrayList<Pancake>();

magicalPancakeLoader.loadDataIntoCakes(pancakes); // pretend function to load data

for(Pancake p : pancakes) {
    System.out.println(p.getName()); // outputs name of specific instance of pancake
}

 

Etc.

 

So, you USE the pancake mix to make instances of pancakes in the same way you USE a class to make unique object instances. This is why it’s called “Instantiating” a class.

Hopefully that makes some sense to you… so if you have a Java question, shoot me an email – [email protected]hillfold.com or post a comment; maybe it’ll make it into the book, but I’ll try my best to answer it!

 

If you haven’t yet, get the free sample chapter here:

http://guerrilla-java.launchrock.com/

 

Leave a Reply

Your email address will not be published. Required fields are marked *