Archive for December, 2008

Java Variable Declaration

When declaring variables in Java, there are certain pointers you will want to remember.  It may be natural to declare same type variables on the same line.  This is not proper programming technique as it decreases readability.  So what are Java variables?  Variables are a type or instance of an Object in Java.  For the easiest examples we can use int, String, char, double, etc as examples.  So here is how we do it:
Declaring an integer in Java (int):

int i;

Which is the same as:

int i = 0;

Breaking this down, the “int” means that this variable is an integer (a number without decimal). “i” is the variable name.  When using this variable later, we will refer to it as “i”.  The default value is 0 for all integers which means you do not have to declare this (optional).  The “= 0″ is the initial value of “i”.  Again, if you want the default value, leaving off “=0″ is acceptable for Integers.  Generally this rule is not appropriate with double, String or char.

Declaring a double in Java (double):

double x = 0.0;

Note that if you do not declare an initial value, doubles act more like integers.  If that is the intended behavior, an integer should be used.

Declaring a String in Java (String):

String text = “”;

String text = new String(); //Produces the same result as above

This declares the initial string as a blank string. Please note that you can not use this variable until you have made it something other than a null object, so the ‘=”"‘ would be the absolute minimum for a Java String value.

Notice the similarity between the second in this line

String and ObjectName (later in the post).  String is an Object in Java, a collection of chars.

Declaring a char in Java (char):

char letter = ‘a’;

If you are having issues declaring characters in Java, please note the single tics around the character in the reference.  Characters in Java do not use double quotes,  so watch out for this.

Declaring other Objects in Java (Objects):

ObjectName obj = new ObjectName();

I will go into this in a later post as well, but this is a basic object instance.  The new ObjectName() is calling the default cunstructor, i.e. public ObjectName() {…}.

For today, we have gone over variable declaration in minor form.  I see this error often while teaching introduction courses and feel that this may help some of those with issues surrounding the basics of declaring basic variables in Java.

Technorati Tags:

Tips When Flying

Flying can be a very convenient way to travel long distances over short periods of time.  For instance, if you want to go from Seattle to St. Louis, there are a ton of options.  I have a lot of family in Richmond VA and amazingly there is a direct flight from Virginia to St. Louis respectively (RIC) to (STL) and back.  Recently, there was a family member that (while attempting to pinch pennies) grabbed a flight that was indirect to save 20 dollars (per round trip) for two flights.  So basically, $20 per trip * 2 trips, which is $40.  What was the catch?  They had one stop for 220 and non-stop for 240.  They of course chose the one-stop option which left them stranded in Detroit (ice storm, delay, etc.).  They ended up having to fly to Raleigh and catching transportation on the ground from there (90+ miles).  It was an entire day to do this.  To make a long story short, they could have driven much faster from here to there (and cheaper) to avoid this mayhem.  What are some other things they could have done?  Gone direct!  Pay the extra $40 dollars and go direct!  So here are my tips.

  1. When at all possible, purchase a direct flight.
  2. Second option is to purchase a continuing flight (where the flight stops, but the traveler doesn’t need to get off of the plane).
  3. If option 1 and 2 isn’t available, try to separate your lay-overs enough to minimize missing a connection.  30 minutes is NOT enough, so make it at least 1.5 hours.  Most of the time, this makes for some downtime; but it is a lot less convenient than sitting in an airport overnight or ALL DAY because you were stuck in transit.
  4. If you do get stuck and it is the airlines fault, do NOT let them tell you there is nothing they can do.  Be polite, but demanding and you will get some benefit for the inconvenience.
  5. Finally, devise a back up plan before you leave to figure out what you may do IF you actually miss a connection.  Don’t leave your options only to the airline that has messed up your schedule; see what other airlines may be able to connect you (American can cross-reference South-West, and vice-versa).  If you do this research ahead of time, it may make for a better chance at making your destination in a more timely manner.

These tips are basic, and while there is not always a direct flight there may be options to minimize your frustration.  The one thing to remember is that being a mad, angry jerk is never the answer to your frustrations.  Polite and demanding is a better way to get what you want.

To All, a Merry Christmas

I wanted to take a minute and mention to anyone that reads my Blog a wonderfully Merry Christmas.  Soon, Santa will be coming by and filling many kids trees with Christmas presents (if he hasn’t already) around the globe.  While things may get tense tomorrow (maybe you didn’t get what you want, or he got more than she did, or whatever), it is important to remember the significance of what tomorrow really is.  It is a time to celebrate with your families (so close your browser now), celebrate life as we know it here on Earth, afforded to us by one man many years ago in the Lord, Jesus.  This is his birthday, and lets show him how much we love him by getting together with someone else and saying a prayer in his name thanking him for all that we have to celebrate (in his name) today, and God bless.

I need to get in the sack now so Santa can come by.  It is 1:38 my time and I am thankful that he is running late.

Err to Readability or Speed

Here is my question of the week.  For those of you that don’t know me, I program in CSharp professionally and I teach Java at the University level.  Recently I have been torn between two facts:

  1. Code for maintainability, in which even the average Joe could probably go in and figure out what is going on.
  2. Code for speed, where it is often confused because I want it to go really fast; who cares about Overpaid Joe?

I am a big fan of both.  I love fast, reliable, well written, maintainable code.  So is there a fall off in speed or performance when I program?  Given the fact that I am programming in Java and C#, then I guess there is.  After all, if I wanted the fastest, wouldn’t I use C or C++?  If I really sit down to think about it I think I want to be able to code stuff fast, with a scalable fall back on speed (libraries are good).  I want code that is maintainable and easy to read, since I even forget what I was doing 3 or 4 days later (err. Poor Documentation?).  I want Object Oriented for the much needed data abstraction and awesome organization.

I hope ASP.NET MVC deadens the CF crowd.  I really don’t think it belongs in the Enterprise world.  CF is a bear to deal with, and all of the XML type syntax…

© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top