Learning Java: Day 4

How Objects Behave
We are now in Chapter 4 of "Head First Java" and today we learn about object behavior and how state affects behavior and behavior affects state.  No, this is not a book on parenting or sociology, nor a discussion of Washington politics. This is about getting java objects to do what you want them to do. (Now if I could just get the resident teenager to consistently do what I tell her...)

Remember, state is what the class or object "knows" (aka "instance variable"), and behavior is what it "does" (aka "method"). 

First, though, I have to tell you that my genius programmer daughter-in-law explained how to get my program output to show up in the command window (command windows are such a hold-over from DOS days...) I've gone back to the beginning of the book to see if I just missed the instructions on how to get the java file compiled and then run.  Well, kind of.

The computer that I'm using has Windows7 installed on it.  For some unknown reason that is probably user error (that means I don't know what the heck I'm doing), I keep getting error messages when I try to compile my code using the "javac" command even though I'm SURE the path is set correctly.  In desperation, I finally associated the file extension "java" with the "javac.exe" program (control panel / Programs / Default Programs / Associate a file type or protocol with a program / select the .java extension / click the "Change Program" button / click the "Browse" button /; locate the "javac.exe" file (on my machine it is in Program Files\Java\jdk1.7.0_05\bin) / click the "Open" button. Voila, the .java extension is associated with the javac.exe program.

Now when I click on the filename.java file it automatically creates a class file.  THAT'S the file I needed to use to see my program results!  NOT the java file!  DUH!!!!  And I needed to use this format: "java (name of class file without .class extension)" which the book did NOT say, possibly because I was supposed to already know that. Whatever. The result is that I can now see my program output!  Yea! Hurray!  My DIL is brilliant!

"Jen says you're well encapsulated..."
Chapter 4 talks about encapsulation; that means hiding the stuff the class KNOWS (aka instance variables) by making it private so the data can't be changed accidentally (or maliciously) and making the stuff the class DOES (aka methods) public so that objects can access them. Encapsulation is used to help cut down on dumb mistakes like changing your number of items to less than zero, or completely losing the "phone number" (aka reference) to an object or other types of things that can crash a program and ruin your day. 

Remember the Make a Teddy Bear machine that we talked about in Chapter 2? The behaviors were getModel, setModel, getSize, setSize, getClothing, and setClothing.  You'd make the get and set methods public so other objects can access them but keep the state, that is the bearModel, bearSize, and bearClothing information private so some joker doesn't turn your Ballerina Bear into a Secret Service Prostitute without your say so. 

This chapter also discussed the importance of "creating" objects.  You can talk about (write code) objects and their behaviors all day but if you forget to new them (create an instance of an object; basically make an object), you're not going to have anything useful.
You're returning a what?
There's also discussion about how methods must declare a return type even if it doesn't return anything (you know how it is, you have to file a tax return even if you don't get anything back) and when something is returned it must return something compatible with the original type (kind of like expecting a Big Mac when at McDonald's and not a Chalupa.)

The rest of the chapter had the usual exercises and puzzles.  
I'm finding that I'm writing code that I don't completely understand and it is worrying me.  Will I understand more as I go along.  Will I understand everything in the book at the end?  Hoo boy...

Learning Java: Day 3

Variables
Today we are covering Chapter 3 of "Head First Java".

Remember variables from algebra? You know, x + 3 = 10, you solve for the unknown x, so x = 7? Programming uses variables, too.  Remember class and objects from yesterday's lesson? Variables can be objects. The java book defines a variable as a container that holds something. There are two kinds of variables in Java: primitives and references.

A primitive variable can be one of several types: a number (byte, short, int, long, float, double), or a "yes/no, true/false, on/off" answer (boolean), or an alphabetic letter (char). If you really are into this stuff, here's the mnemonic for remembering primitive types: Be Careful! Bears Shouldn't Ingest Large Furry Dogs. (Yep, I know, you're only reading this to be kind and have no interest in learning Java...) Primitive variables are different sizes according to the type.

The other type of variable is an object reference variable. This type of variable is just one size no matter if the object is a bacteria, a movie, a galaxy, or something entirely intangible because this variable only holds the reference to the object rather than the object itself. It's kind of like the phone number to contact the object when the object needs to do something.

You have to tell Java what type, what value and what name your variable has. Kind of like ordering in expensive coffeehouses, "I'd like a grande Salted Caramel Hot Chocolate" (can you tell I'm not a coffee drinker?) To put it in Java terms it would be a "Chocolate (type)  hotSaltedCaramel (name) = grande (value)".  Try that at Starbucks!

A school of fish is a Fish Array
Other things learned in this chapter are arrays (a litter of puppies is a Dog array, a dozen eggs in a carton is an Egg array, dresses in a closet is a Dress array, etc.), how an array is always an object (not plural, an array is a singular object even though it may contain multiple things), and using the dot operator to access the parts of an object.

We end this chapter with exercises and puzzles.

Wow, this took me 4 hours to get through. I can feel my neurons humming...


Learning Java: Day 2

Classes and Objects
Here we are in Chapter 2 of "Head First Java"

I'm having hold-over problems from yesterday. My VERY simple programs compile, but I don't know where the output is going. Translation: The code that I'm writing appears to work correctly but it's supposed to write out simple sentences and I don't know where those sentences are going.  

I've sent out an email distress call  to my programmer daughter-in-law for help. She will undoubtedly find this very funny but will be able to explain in simple words how to view my program output.

Today I learned the difference between a class and an object. A class is like a teddy bear machine and the object is the ballerina teddy bear or the soldier teddy bear (or whatever else kind of bear) that is made by the teddy bear machine.

Each class has things that it "knows" and things that it "does".  So in the example of the teddy bear machine, it would "know" the bearModel, the bearSize, and the bearClothing. The things it "does" might be getSize() (you push the size button), setSize(), getModel() (you push the model button), setModel(), getClothing() (you select the clothing buttons), setClothing(), and assembleBear(). The object, in this example, is the teddy bear that drops out of the machine.

So, a class is like a blueprint, an object is (or objects are) what's made from the blueprint. Or, as the book says, "a class is like a recipe; objects are like cookies."

The rest of the chapter consists of practice, exercises, and a puzzle.

I'm glad this chapter is short.  After a day of housecleaning, laundry, ironing, and baking cookies, there wasn't a whole lot of time to spend on the computer.

I'm pooped.  It's bed time.  Nighty night!

Learning Java: Day 1

This summer I've taken a wonderful break while I've allowed my body to heal.  It's been great for the body but not so good on my mind; I feel an intellectual void. I have one month until I start acupuncture school so it seems like a great time for a challenge: learn Java programming.

Before you say "ewww", let me explain that I love computers.  I have a bachelor of science in Information Technology. I've taken several C and C++ classes in the past and I have to say that I suck as a programmer. I keep thinking that if I just keep practicing I'll "get it" and be able to create usable programs.  Sounds logical, doesn't it?

So I purchased an O'Reilly Java tutorial called, "Head First Java".  The introduction is funny and appealing, the online reviews are very positive, and it has 18 chapters plus two appendices so I can finish the book before school starts if I do one chapter per day.

So there you have it; one Java-clueless older woman, one highly ranked tutorial, and one month to finish (gee, this sounds like "Julie and Julia".)  Here we go...

First you have to install the Software Development Kit (SDK) onto your computer.  You'd think that Oracle (the folks that "own" Java) would have an easily navigable website.  After all, they are computer folks.  But no, this is a place for folks that KNOW WHAT THEY ARE DOING. So after some fiddling around, I finally find the file and get the blasted thing downloaded. Then I had to download the Application Programming Interface (API) documentation so I can look stuff up.  (An API is a piece of code that lets software code from various things like servers/cellphones/fuzzy logic rice cookers/etc. talk to each other) Finding the API documentation was easy; finding the downloadable file took 20 minutes.

Next step was to set the PATH to the java software so the computer knows where to find the compiler.  I had to look up how to do that because it's been a good fifteen years since I've done this. It's going to be a little tougher to get my brain functioning properly than I had anticipated.

The first chapter was a remedial course of beginning programming in writing a class, looping, boolean tests (is it true or false such as: is it greater than, less than, or equal to something), branching, and compiling. Then we moved on to writing code and compiling it. Then exercises and puzzles.

I THINK this will be a good experience.  I hope to finish the book at the end of the month with some usable skills.

Wish me luck!

Classic Lentil Soup Recipe


Lentil Soup, salad, Sweet Potato Rolls with Lilikoi Jelly
A few days ago my son sent me a vegetarian recipe for lentil soup. He took it from a cookbook that I would love to own: How to Cook Everything Vegetarian by Mark Bittman. We frequently eat meatless meals so I was happy to try this recipe.  The resulting soup was good, but in my opinion, not good enough, so I tinkered with it (although after the tinkering it was no longer vegetarian). I finally ended up with a soup that had a deeper background flavor and more oomph. Try the original recipe and if you think it needs more something then try the changes I've listed at the bottom of the page.

Classic Lentil Soup

1 cup dried lentils, washed and picked over
1 bay leaf
Several sprigs fresh thyme or a few pinches dried
1 carrot, cut into 1/2-inch dice
1 celery stalk, cut into 1/2-inch dice
6 cups vegetable stock or water, or more as needed
Salt and freshly ground black pepper
2 tablespoons extra virgin olive oil
1 onion, chopped
1 teaspoon minced garlic

1) Put the lentils, bay leaf, thyme, carrot, celery, and stock in a deep skillet or medium saucepan.  Sprinkle with salt and pepper. Bring to a boil; turn the heat down to low and cook, stirring occasionally, until the lentils are tender, about 30 minutes.
2) Meanwhile, put the olive oil in a small skillet over medium heat.  Add the onion and cook, stirring, until it softens, about 5 minutes.  Add the garlic and stir, then cook for 1 minute more and turn off the heat.
3) When the lentils are tender, fish out the bay leaf and thyme sprigs and stir the onion mixture into the soup.  Add more stock if the soup is too thick, then taste, adjust the seasoning and serve.

Here's what I changed: 
I increased the dried thyme to 1 teaspoon
I used water and added 2 cubes of cilantro bouillon (since I didn't have vegetable stock on hand)
I added 1 teaspoon of Kaiulani Spices Hawaiian Cajun seasoning for zip
I added 1/4 teapoon of Kaiulani Spices Kona Coffee seasoning for background depth
I added 1/2 cup leftover Portuguese sausage, diced (cooked from breakfast)



Crockpot Lu Pulu Recipe

Lu Pulu, rice, and broccoli salad
Yesterday my Visiting Teachers came by.  As we sat and talked they mentioned how much they admired my garden, especially the taro patch by the front door.  We have perhaps ten different varieties of taro that have been acquired from all over the island.  Most have been planted in what used to be the "swamp" by the front door. The taro is thriving in the wet ground and our entry looks so much better with them planted there. 

Of course, we had to discuss what we do with taro.  I mentioned that I wanted to learn to make pork lau lau. So sad; I don't have salted butterfish on hand, so that was out. Tongan lu pulu was mentioned as another tasty and easy (I LOVE easy recipes) way to use taro leaves. AND you can make it in the crockpot! How wonderful is that?!

So this morning I set out early to gather taro leaves, in the rain no less (the uber frequent rain is the reason we had a swamp by our front door.) I cut thirty leaves out of my mostly young plants and set to work cleaning and slicing. I sliced up the leaves before adding them to the crockpot, but apparently that's not necessary. I layered all the ingredients and let the whole thing cook on low for 6 hours.  We came back from church to the fragrance of cooked luau leaves, corned beef, and onion.  It was lovely.

Taro patch after the scalping
Here's what I learned: although the lu pulu was tasty, it was rather bland for my family.  Next time, I will add soy sauce and maybe a little crushed hot pepper to each layer, even though that takes it out of the traditional realm.  I will also only use younger leaves rather than a mixture of old and new leaves.  The old ones were much tougher and didn't melt into the rest of the leaves the way they were supposed to.  Maybe it's a duh, but I didn't take the longer cooking time for the older leaves into account when I was harvesting. I'll also have to try the traditional method of using NZ corned beef instead of the rectangular canned stuff. This time around I only used two cans of coconut milk; I may increase that to three on the next go 'round.

This recipe is easy, especially when you use bagged taro leaves (also called luau leaves, or lau lau leaves) from the grocery store. I hope you'll try it.

Crockpot Lu Pulu 

Taro leaves (aka luau leaves or lau lau leaves) (I used 30 leaves), either sliced up or simply layered in the pan
2 large onions, chopped (use 2 if you love onions, 1 if you like less) (I used 4 really large bunching onion bulbs because I had them)
2 cans corned beef (NZ corned beef if you are a purist, American if that's all you have)
2 or 3 cans of coconut milk

1. Layer 1/3 of your leaves in the bottom of the crockpot.
2. Sprinkle 1/2 of the chopped onions on top of the leaves.
3. Layer chunks of the corned beef on top of the onions.
4. Pour one can of coconut milk over everything.
5. Repeat steps 1 through 4.
6. End with a layer of taro leaves.
7. Pour your third can of coconut milk, if you are using it, over everything.
8. Cook on low heat for 6 hours.

Serve over rice.

Happy eating!

Day 1 of New Eating Habits


Today's blog is pretty mundane. Tomorrow will give the beige wall some real competition.

I woke up feeling good.  I have energy. I lost another 2 pounds overnight. I get to eat normally. How much better could life be?

BREAKFAST
Family: They ate cereal
Me: 1/2 papaya, about 1/2 cup of Indian eggplant and tomatoes

Today is a pretty normal Saturday; cleaning the house, doing laundry, shopping for shorts for Butterfly (she gets to use her birthday gift cards).  It feels like there should be a celebration of some sort for my new life. Honestly, I just feel wonderful. I MUST be feeling good; I'm cleaning and organizing without reason.

LUNCH
Family: Sourdough hotdogs (I asked if they wanted me to make lunch for them - negatory)
Me: Salad of spinach, cherry tomatoes, broccoli, carrots, alfalfa sprouts, sliced pieces of a mozzarella stick, sesame dressing. Yum.

Shopped with Butterfly for camp shorts and t-shirts.  She was happy with the new stuff. She leaves on Monday and will be gone for 4 days.  Whoo hoo!  What shall I do for fun?

DINNER
Leftovers for all. I also had a bowl of salad greens for dessert.  I ate each exquisite bite in pure bliss.

Went for a 2-mile walk just for fun.

I am so very happy!