New Year 2013

Happy New Year Everyone!  Happy Year of the Snake!

Goodness, it's been a very long time since I've written in this blog! I've finished my first semester of acupuncture school and have a whole week off with no school, no clinic, and no work, so I have time to restart writing in MotherNatureSays.

Keeping with the new year tradition, I've come up with my 2013 resolutions. Last year I didn't make any resolutions at all; a first for me. I must have been in a funk last year, or something... This year, since I'm in school full-time, I'll have to become more organized in order to accomplish everything I want.

#1. Foremost, this year I want to become a more tolerant person. Getting back into academia was something I really wanted, but it was more difficult than I anticipated to go into a completely alien cultural environment. I'm going to a Taoist acupuncture school. They just do things differently; traditional Chinese medicine requires an entirely different mindset from Western scientific methods. Asking questions isn't exactly encouraged. The Master is always right (even when she isn't). I had major difficulty wrapping my head around the acupuncture points. AND it IS harder for me now that I'm older, to memorize and retain the information, especially when it didn't seem to make any sense to me to begin with.

Anyway, I'd get really wound up, frustrated, agitated, irritated, torqued, how many ways can you say "bent out of shape"? I even considered quitting and going to another school. BUT, I've made friends (and that's not an easy thing for me to do), I really like some of my instructors, and I love my clinical supervisor even though she is a really tough cookie to please.

SO, my number one goal this year is to relax over perfection. I don't have to know everything right now. It's okay if I don't learn as quickly as some of my younger classmates. It's okay to let go. To paraphrase a wise friend, 'C still equals diploma'.

#2. I'm going to practice anticipating my boss's needs. I work part-time as an IT person at my school. I've gotten into spats with my employer because I thought she wanted me to read her mind. At least that was my perception. She DOES want me to figure things out for myself and I've "figured it out" in ways that she didn't appreciate. I was asked, if she had to tell me what to do, what did she need me for? Since I love my job and I don't want another panic attack at work, I will utilize my #1 goal. I've also decided that a more productive frame of mind was to view this interaction with my employer as "anticipating her needs". Putting this into practice last work day resulted in a happy boss and a pleasant day of employment for me. It just required a different way of looking at things.

#3. Blog more regularly. That means that my posts may be much shorter. They might contain weird things about what I'm learning at school, or my ideas for another home business venture, or stuff about my tribulations with juice fasting, or my frustrations with teenage Butterfly, or any number of other non-related subjects. This ties in with the parallel goal of "write everyday". I may not blog every day, but I do want to write everyday.

#4. Juice very day. I was given a Hurom juicer for Christmas! I am sooooo very happy to get it. I had been blending my veggies/fruit, then putting the stuff through a fine-mesh strainer, then putting the resulting juice through a micro-fiber cloth to strain it again. The whole process took so much time that it wasn't feasible to do it on the mornings I needed to leave the house less than an hour after waking up. Now juicing only takes a few minutes and the result makes a marvelous breakfast.

#5. Create a more organized home. I've discovered the FlyLady. Her motto is: 
"Clutter cannot be organized. It can only be eliminated! Get rid of clutter and you will find the time that you need to bless yourself and your family." ~FlyLady  
My home is never really messy but I've definitely developed spots that need decluttering. I'm working on the 15_minutes_at_a_time theory, i.e. you can do anything for 15 minutes. Which leads to my next goal -->

#6. Exercise for 15 minutes per day. If I can master this, then perhaps I can work up to more.

That is my list of goals for this year. Now, if I could just make some academic goals for Butterfly...

Happy New Year to all of you! I wish you prosperity, joy, good health, and love! May this year be better than the last!


Learning Java: Day 13

Working With Swing Components

Component is the more correct term for what I've been referring to as widgets. Those are the things you put in a GUI, or the things that the user sees and interacts with. Almost every thing you can stick in a GUI extends from javax.swing.JComponent.

Chapter 13 of Head First Java covers the layout managers for JPanel and JFrame, creating scrollbars on textboxes, making lists, and finally, creating the BeatBox midi player.

Fact 1: Different layout managers have different policies and you have to memorize what they are if you want your buttons/textboxes/lists/etc to be placed where you actually want them to be.

Fact 2: BorderLayout is the default layout manager for a frame; FlowLayout is the default for a panel.

Fact 3: When you add a component to another component, the added component is controlled by the layout manager of the background component.

Three layout managers: border, flow, and box.
BorderLayout: the BorderLayout manager divides a background component into five regions (NORTH, SOUTH, EAST, WEST, CENTER). You can only add one component per region to a background controlled by a BorderLayoutManager. This is the default layout manager for a frame.

FlowLayout: the FlowLayout manager lays out components from left to right, top to bottom, in the order they were added, wrapping to a new line when needed. This is the default layout manager for a panel.

BoxLayout: the BoxLayout manager places components from top to bottom, one per line.

Most of my time spent in this chapter was typing the code for the BeatBox and then debugging it prior to compiling. Debugging might be the most useful skill I'll learn as I work my way through the book.

School is starting on September 8th.  I still have 5 more chapters and 2 appendices to work through before school begins.  I've gotta work faster!

Learning Java: Day 12

Do It Yourself Graphical User Interfaces

Chapter 12 of Head First Java  goes over the ins and outs of creating GUIs - Graphical User Interfaces. We learn to deal with Event Handling and Inner Classes while moving from command line inputs and outputs to creating our first graphical anything.

This chapter has taken me four days to get through; in part because it's a long chapter, partly because I've been busy with the house and family, but mostly because it's been difficult for me to understand.  Not to mention my self-induced buggy code. On the other hand, I'm getting MUCH better at debugging my code.

To make a very long story short:

Import the javax.swing package when you want to put a window on the computer screen.
JFrame is what makes a window to put your widget (button, text field, image, over a dozen different types) on.

An Event is what happens when the user does something with the screen widget (i.e. clicks a button.)

Each widget needs a Listener to tell the class that an event occurred.

Import java.awt.* when you want to use the java Graphics components for drawing, filling, setting colors, and manipulating those aspects of 2D drawing.

If you want more than one widget in a window, use Inner classes.

We created three versions of the midi player:
  1. The player gave a sound-only output of ascending piano notes.
  2. The player gave an output of ascending piano notes while printing "la" in the command window for each note that was played.
  3. A new window was created with a randomly placed rectangular box with randomly selected fill-color for each randomly selected piano note (64 times)
Yay! I'm finally creating graphics and sound!  It's still a little foggy but it's a start!




Learning Java: Day 11

Exception Handling
Anytime you work with computers, stuff happens. The server is down. The network is offline. The file is corrupted.  As a programmer you need to write code that can handle the bad times; problem-handling code for when you can't guarantee that the file will be in the right directory, the server will be up and running, or the Thread stays asleep. Chapter 11 of Head First Java covers this kind of problem anticipation.

We will be building a MIDI Music Player.  Over the next three chapters we'll learn to create a graphical user interface (GUI) and a multi-user BeatBox Drum Machine. Today we learn what is required to create a MIDI player and how to handle exceptions.

Risky Business
When your code calls a risky method -- a method that declares an exception -- it's the risky method that throws the exception back to you, the caller. You have to read the API docs to see if there is risky behavior in the code.  The method has to declare the exceptions it might throw. The API docs then tell you WHEN you might get that exception, such as resource restrictions because the object (in this case, the sequencer) might already be in use. It's up to you to write code to deal with the problem.

Checked Exception vs RuntimeException
RuntimeExceptions occur because you've got flaws in your code that need to be fixed before the code will compile.
Checked Exceptions happen while the program is running and are caused when a method throws an exception with the keyword throw,  followed by a new exception object:
     throw new noJuiceFastException();
Methods that might throw a checked exception must announce it with a throws Exception declaration. Methods can throw more than one exception.

Try/Catch
A try/catch block tells the compiler that you know an exceptional thing could happen in the method you're calling, and that you're prepared to handle it. The compiler doesn't care how you handle it; it cares only that you say you're taking care of it.

  • Exceptions are polymorphic
  • Write a different catch block for each exception that you need to handle uniquely.
  • Multiple catch blocks must be ordered from smallest to biggest.
Making Sounds
You need four things:
  1. Sequencer: The thing that plays the music
  2. Sequence: The music to be played...a song
  3. Track: The part of the Sequence that holds the actual information
  4. Midi Event: The actual music information (notes to play, how long, etc.)
Today we use command line arguments to experiment with sounds. Next chapter we create MIDI events using a very crude video that pulses to the beat of the MIDI music. 

Onward...

Speedy Pasta Skillet Recipe

Saturdays are busy days around our house. House-cleaning, laundry, bed-linen-changing, ironing; it's a day that calls for easy meals. This recipe is one I learned to make as a young teenager and have fed to my own family as the kids grew up.  It's always been a family favorite; it's tasty, cheap, quick to make, and can be modified to use whatever you have on hand.  It's a great main dish when you're too pooped to put much effort into cooking.

This recipe takes about 1/2 hour to make if you boil the noodles at the same time you cook the ground beef. It will feed about 5-6 people if you include a salad and another side dish.

Speedy Pasta Skillet
1 pound ground beef
1 cup onion, chopped
1 clove garlic, minced
1/2 cup green onion, chopped (optional)
1 cup eggplant, peeled and chopped (optional)
1 teaspoon oregano (optional)
1 teaspoon parsley flakes (optional)
Salt and pepper to taste
1 6-oz can tomato paste
1 cup grated cheese (optional)

1 pound rigatoni pasta, cooked to al dente

chopped tomatoes and cilantro for garnish (optional)
grated Parmesan cheese (optional)

Set a large pot of heavily salted water on the stove at high heat.  When the water comes to a boil add your pasta.  Turn the heat down to medium and allow the pasta to boil until it's still a little firm (al dente). Stir occasionally to keep the pasta from sticking to the bottom of the pan. Drain.

In the meantime, brown the ground beef, onions, green pepper, garlic and eggplant together in a large skillet. Drain any excess fat from the skillet. Season with the herbs and salt and pepper to taste. Add tomato paste to the meat and mix well.  Add the grated cheese and mix again.  Add the drained pasta to the meat and mix well.  If desired, garnish with chopped tomatoes, cilantro, and grated Parmesan cheese. 

Notes: All of the optional items are additions to the original recipe. You can use any kind of pasta: elbows, shells, wheels, tubes, whatever you have on hand.  Use any vegetable that your family likes. I've used peas instead of eggplant.  A relative uses frozen lima beans. Chopped kale, chard, or spinach would be lovely. Substitute Italian sausage for the ground beef. Use a pound of chopped mushrooms instead of ground beef for a vegetarian version. Use cheddar, mozzarella, Monterey Jack, Swiss, or something entirely different for the cheese or don't use any cheese at all. The variations are endless.

Learning Java: Day 10

Numbers and Statics
We are what we repeatedly do.  Excellence then, is not an act, but a habit.
- Aristotle
Today marks the halfway point in the book, Head First Java. Yesterday I was wondering why I was so determined to learn this programming language, especially since it is not even remotely similar to my upcoming Master's degree studies of acupuncture and Oriental medicine. Java is difficult for me to learn and frequently I've felt really, really dumb because it's taken so long to wrap my mind around some of the concepts. I've told people who've asked me why I'm bothering to learn programming, that I want to be able to create Android phone apps for use in my master's studies, so therefore I need to know Java (since the phone apps are created in Java). But I think the answer lies deeper than that. 

I want to learn Java because it's difficult for me.  I want to conquer this subject. I want to learn Java because it's just one of the many things I want to learn or do before I die. So let's get on with it...
______________________________________
STATIC
The keyword static lets a method run without any instance of the class.  This is used when you don't need to have an instance of the class (like when using the Math methods). 

You call a static method using the class name

Example:     Math.min(66,99);
You call a non-static method using a reference variable name
Example:     Werewolf Jacob = new Werewolf();
          Jacob.howl();

Static variable: value is the same for All instances of the class.
Static variables are shared.
All instances of the same class share a single copy of the static variables.
Instance variables: 1 per instance
static variables: 1 per class

FINAL means it can never change
A final variable means you can't change its value.
A final method means you can't override the method.
A final class means you can't extend the class (i.e. you can't make a subclass).

MATH
Converting a String to a primitive value ('parseInt', 'parseDouble', or 'parseBoolean'): 
     String s = "2";
     int x = Integer.parseInt(s);

Converting a primitive number into a string (easiest way is to concatenate the number to an existing string)
     double d = 42.5;
     String doubleString = " " + d;

     double d = 42.5;
     String doubleString = Double.toString(d);

FORMAT
%,d means "insert commas and format the number as a decimal integer."
%.2f means "format the number as a floating point with a precision of two decimal places."
%,.2f means "insert commas and format the number as a floating point with a precision of two decimal places."
Formatting Dates (Use java.util.Date when you want the current date and time):
%tc gives the complete date and time: String.format ("%tc", new Date()); 
          Fri Aug 17 23:58:29 HST 2012
%tr gives just the time: String.format ("%tr", new Date());
          11:58:29 PM
%tA %tB %td gives the Day of the week, month and day
     Date today = new Date();
     String.format ("%tA, %tB, %td", today,today,today)(there's an easier way but I can't get it to format correctly on this screen)
                    Friday, August 17

Use java.util.Calendar for date manipulation.
There are a LOT of methods in the Calendar API and a lot of Calendar Fields.
And we finally end with practice and exercises.  This was a very LONG chapter. My brain is fried...


Learning Java: Day 9

Constructors and the Garbage Collection
Have you ever run a software program that slowed down after you'd been working for a while, and it got so bad that you had to close the application and restart it in order to continue working?  That's what happens when the programmer doesn't pay close attention to getting rid of objects when those objects are done doing "its thing".  Those abandoned objects continue taking up RAM, so much so that eventually you run out of memory space and have to close the program in order to free the memory space up again.  Java automatically takes out the trash for you.

Chapter 8 of Heads Up Java covers how objects are created, where they live while they're alive, and how to keep or abandon them efficiently.

There are two areas of memory that are important in Java; the Stack and the Heap. 

The Heap is also known as "The Garbage Collectible Heap".  The Heap is where ALL, ALL, ALL objects live. The instance variables that belong to the object live inside their objects on the heap, too. 

The Stack is where method invocations (like go() and doStuff() and main()) along with local variables live. A local variable is alive until its method completes. A local variable is in scope only within the method in which the variable was declared.  You can only use that local variable while its method is actually running.  As soon as the method is completed, the variable is popped off the Stack and goes into garbage collection.

How Objects Are Created
  1. Declare a reference variable:                     Dog myPuppy = new Dog();
  2. Create an object                                      Dog myPuppy = new Dog();
  3. Link the object and the reference            Dog myPuppy = new Dog();

Constructors
A constructor looks and feels a lot like a method, but it's not a method.  It's got the code that runs when you say new. It's the code that runs when you instantiate an object. The thing that separates a method from a constructor is the return type. Methods must have a return type, but constructors cannot have a return type.

Overloaded constructors means you have more than one constructor in your class.  To compile, each constructor must have a different argument list.

How Long Does an Object Live?
An object's life depends exclusively on the life of the references referring to it.  If the reference is considered alive, the object is still alive on the Heap.  If the reference dies, the object will die and will be picked up by garbage collection.

3 ways to get rid of an object's reference:
  1. The reference goes out of scope, permanently 
    •  // the reference dies at the end of the method
  2. The reference is assigned another object       
    •  // the first object is abandoned when the reference moves
  3. The reference is explicitly set to null       
    •  // the first object is abandoned when the reference is 'deprogrammed'.
This chapter end with exercises, a puzzle and a five-minute mystery.