2015/01/28 – Updates

Whew, let’s see.  I’ve gotten about eight more chapters into Learn Java for Android Development.  I haven’t posted the end chapter quizzes because, frankly, they’re really obnoxiously long.  I’ll get around to that sooner or later.

Finished the game Infested Planet.  Great little indie game but damn, I guarantee you will be cussing at the screen on more than one level.

Another independent game worthy of your time is Gods Will Be Watching.

Also finished Sam and Max Season 1, Episode 1: Culture Shock, Episode 2: Situation: Comedy, Episode 3:  The Mole, The Mob, and the Meatball, and Episode 4:  Abe Lincoln Must Die!

My daughter’s reading Fahrenheit 451.  I’m a bit astonished to see her reading a book which was written prior to the age of cell phones.  It does fit into her future society fetish well though.

About it for now.

Posted in General | Leave a comment

Learn Java for Android Development, Chapter 3

  1. What is a class?
    1. A class is a user defined type complete with user defined methods and fields.
  2. How do you declare a class?
    1. <public|protected|private> class <className> { }
  3. True or false:  You can declare multiple public classes in a source file.
    1. False.
  4. What is an object?
    1. An instantiation of a class.
  5. How do you obtain an object?
    1. <className> <variableName> = new <className>();
  6. What is a constructor?
    1. A method that fires when a class is instantiated, allowing for the initialization of its members.
  7. True or false:  Java creates a default noargument constructor when a class declares no constructors.
    1. True.
  8. What is a parameter list and what is a parameter?
    1. A parameter is an argument to a method; a parameter list is an ordered sequence of these arguments.
  9. What is an argument list and what is an argument?
    1. An argument is a variable passed to a method as a parameter; an argument list is an ordered sequence of these variables.
  10. True or false: You invoke another constructor by specifying the name of the class followed by an argument list.
    1. False.  this(<argument list>)
  11. Define arity.
    1. Arity is the number of arguments passed to a constructor or method.
  12. What is a local variable?
    1. A local variable is one whose scope is limited to a method or subsection of a method.
  13. Define lifetime.
    1. Lifetime determines how long a variable exists.
  14. Define scope.
    1. Scope determines how accessible the variable is to code.
  15. What is encapsulation?
    1. Encapsulation is the act of creating a class, of specifying fields and methods.
  16. Define field.
    1. A field is a variable declared within the class body but outside of a method.
  17. What is the difference between an instance field and a class field?
    1. An instance field is scoped to an instance of an object while a class field is scoped to all objects of the same class.
  18. What is a blank final, and how does it differ from a true constant?
    1. A blank final is read only and can only be set in an instance constructor.  There is one blank final per instance of an object whereas a true constant has only a single instance.
  19. How do you prevent a field from being shadowed?
    1. Change the name of the shadowing variable or refer to the shadowed variable using this.
  20. Define method.
    1. A named chunk of code.
  21. What is the difference between an instance method and a class method?
    1. An instance method has access to instance fields and class fields; a class method only has access to class fields, but can access private fields via an object reference.
  22. Define recursion.
    1. A method invoking itself.
  23. How do you overload a method?
    1. Use the same name and a different parameter list.
  24. What is a class initializer and an instance initializer?
    1. A class initializer fires when any reference to the class is made.  An instance initializer is fired when the instance is created and separately from a constructor.
  25. Define garbage collector.
    1. A garbage collector determines which variables are no longer being referenced and frees their memory.
  26. What is an object graph?
    1. An object graph is a reference of all objects referenced by another object.
  27. True or false: String[] letters = new String[2] { “A”, “B” }; is correct syntax.
    1. False.
  28. What is a ragged array?
    1. A ragged array is an array where the last dimension has a different number of members for each member of the array.
  29. Merge Listings 3-6 and 3-7 into a complete Image application that demonstrates its constructors.
    public class Image
    {
         Image()
         {
              System.out.println("Image() called");
         }
     
         Image(String filename)
         {
              this(filename, null);
              System.out.println("Image(String filename) called");
         }
     
         Image(String filename, String imageType)
         {
              System.out.println("Image(String filename, String imageType) called");
              if (filename != null)
              {
                   System.out.println("reading " + filename);
                   if (imageType != null)
                        System.out.println("interpreting " + filename + " as storing a " + imageType + " image");
              }
         }
     
         public static void main(String[] args)
         {
              Image image = new Image();
              System.out.println();
              image = new Image("image.png");
         }
Posted in General | Leave a comment

Sorting a Generic List By A Property Name Stored In A Variable

I ran across this problem recently.  The normal code I see looks like this:

If sortExpression = "Property1" And sortDirection = "Ascending" Then
     sortResults = sortResults.OrderBy(Function(x) x.Property1).ToList()
ElseIf sortExpression = "Property1" And sortDirection = "Descending" Then
     sortResults = sortResults.OrderByDescending(Function(x) x.Property1).ToList()
ElseIf sortExpression = "Property2" And sortDirection = "Ascending" Then
     sortResults = sortResults.OrderBy(Function(x) x.Property2).ToList()
ElseIf sortExpression = "Property2" And sortDirection = "Descending" Then
     sortResults = sortResults.OrderByDescending(Function(x) x.Property2).ToList()
ElseIf sortExpression = "Property3" And sortDirection = "Ascending" Then
     sortResults = sortResults.OrderBy(Function(x) x.Property3).ToList()
ElseIf sortExpression = "Property3" And sortDirection = "Descending" Then
     sortResults = sortResults.OrderByDescending(Function(x) x.Property3).ToList()
End If

Assumptions for the above code: sortExpression is a String, sortDirection is a String, sortResults is a List or derivative thereof.

Ugh. That sort of code is infuriating. It’s exactly the sort of repetition that modern languages are supposed to free us from, right?

Well, with a bit of reflection, we can clean this up substantially.

Imports System.ComponentModel
 
...
 
Dim sortProperty as PropertyDescriptor = TypeDescriptor.GetProperties(GetType(T)).Find(sortExpression, True)
 
If sortDirection = "Ascending" Then
     sortResults = sortResults.OrderBy(Function(x) sortProperty.GetValue(x)).ToList()
Else
     sortResults = sortResults.OrderByDescending(Function(x) sortProperty.GetValue(x)).ToList()
End If

Yes, reflection is slower and there is a price paid. However, the cleaner code and type safety make it worthwhile; if sortExpression doesn’t exist as a property on T an exception is thrown whereas with the previous if..else ladder you would’ve simply exited out without any sorting being done.

Posted in Programming | Leave a comment

Learn Java for Android Development, Chapter 2

  1. What is Unicode?
    1. Unicode allows for the representation of characters beyond the English alphabet.  It allows for up to 65,535 different characters.
  2. What is a comment?
    1. A comment is ignored by the Java compiler.  It is intended to help others who are reading the source code to understand the intent and purpose of the code.
  3. Identify the three kinds of comments that Java supports.
    1. A single line comment.  (// Comment)
    2. A multi line comment.  (/* … */ Comment)
    3. A Javadoc comment.  (@author, etc. Comment)
  4. What is an identifier?
    1. An identifier is used to represent either a variable or method.  It is the name by which the variable or method is identified and used in source.
  5. True or false:  Java is a case-insensitive language.
    1. False.  Java is case-sensitive.
  6. What is a type?
    1. A type is a predefined object with specified fields and methods.
  7. Define primitive type.
    1. A primitive type is a type upon which all other types are built.  They are one of the built in types (float, double, int, char, byte, char) which the compiler recognizes natively, without additional code.
  8. Identify all of Java’s primitive types.
    1. bool, char, byte, short, int, long, float, double.
  9. Define user-defined type.
    1. A user defined type is just that; a type of object with variables and methods which is defined and constructed by the developer.
  10. Define array type.
    1. An array type represents a collection of objects.
  11. What is a variable?
    1. A variable is a section of memory allocated to hold a value and identified by an identifier.  The size of the memory allocated is dependent upon the type being held.
  12. What is an expression?
    1. An expression is an operation with one or more variables.
  13. Identify the two expression categories.
    1. Simple and compound.
  14. What is a literal?
    1. A literal is a constant value entered directly into source code.
  15. Is string literal “The quick brown fox \jumps\ over the lazy dog.” legal or illegal.  Why?
    1. Illegal.  \j and \  are not valid escape sequences.
  16. What is an operator?
    1. An operator specifies an operation that is to be performed.  Example:  * for multiplication, + for addition, – for negation or subtraction.
  17. Identify the difference between the prefix operator and a postfix operator.
    1. The prefix operator is applied to a variable prior to the variable’s value being used in its expression; the postfix operator is applied to a variable after the variable’s value has been used in an expression.
  18. What is the purpose of the cast operator?
    1. To convert one type to another.
  19. What is precedence?
    1. The order of operations in which operators are applied and expressions are calculated.
  20. True or false:  Most of Java’s operators are left-to-right associative?
    1. True.
  21. What is a statement?
    1. A statement is an execution of type method, an assignment of a value to a variable, or to make a decision/branch in code.
  22. What is the difference between the while and do-while statements?
    1. A while statement may not always execute; a do-while statement will always execute at least once.
  23. What is the difference between the break and continue statements?
    1. The break statement will exit the loop and continue execution after the loop; the continue statement continues the loop using the next value of the loop operand.
  24. Write an OutputGradeLetter application (the class is named OutputGradeLetter) whose main() method executes the grade letter code sequence presented earlier while discussing the if-else statement.  Use the DumpArgs application presented in Listing 2-1 as the basis for this application.  (You don’t need to include Javadoc comments, but you can if you want.)
    public class OutputGradeLetter {
        public static void main(String[] args) {
            char gradeLetters[] = { 'A', 'B', 'C', 'D', 'F' };
     
            for (int i = 0; i &lt; gradeLetters.length; i++)
             System.out.println(gradeLetters[i]);
        }
    }
  25. Create a Triangle application whose Triangle class’s main() method uses a pair of nested for statements along with System.out.print() to output a 10-row triangle of asterisks, where each row contains an odd number of asterisks (1, 3, 5, 7, and so on) as shown following:
              *
             ***
            *****
           *******
          *********
         ***********
        *************
       ***************
      *****************
     *******************
    public class Triangle {
        public static void main(String[] args) {
            for (int r = 1; r &lt; 10; r++)
            {
                for(int c = 0; c &lt; 10 - r; c++)
                    System.out.print(" ");
     
                for(int c = 0; c &lt; r; c++)
                    System.out.print("*");
     
                for(int c = 0; c &lt; r - 1; c++)
                    System.out.print("*");
     
                System.out.println();
            }
        }
    }
Posted in Programming | Leave a comment

Learn Java for Android Development, Chapter 1

  1. What is Java?
    1. Java is a language and platform.  The language is similar to C/C++/C# in syntax; the platform is the virtual machine.
  2. What is a virtual machine?
    1. A software application that translates from its own instruction set to the native, hosting instruction set.
  3. What is the purpose of the Java compiler?
    1. The Java compiler translates the Java language into byte code which is executable by the Java virtual machine.
  4. True or false:  A classfile’s instructions are commonly referred to as byte code.
    1. True.
  5. What does the virtual machine’s interpreter do when it learns that a sequence of byte code instructions is being executed repeatedly?
    1. It uses the JIT compiler (just-in-time) to compile the instructions into native code.
  6. How does the Java platform promote portability?
    1. By using byte code to provide an abstraction to the underlying platform; the platform’s run-time environment provides the specific implementation.
  7. How does the Java platform promote security?
    1. By sandboxing the applications running on top of the JVM.  (Java virtual machine.)
  8. True or false:  Java SE is the Java platform for developing servlets.
    1. False.  Jave EE is used to develop servlets.
  9. What is the JRE?
    1. The JRE provides the platform specific implementation of the JVM.
  10. What is the difference between the public and private JREs?
    1. The private JRE is included with the JDK and allows Java programs to execute independently of whether or not the public JRE is installed.
  11. What is the JDK?
    1. The JDK is the Java Development Kit.  It provides all the utilities, documentation and libraries necessary to develop for Java for a platform.
  12. Which JDK tool is used to compile Java source code?
    1. javac
  13. Which JDK tool is used to run Java applications?
    1. java
  14. What is Standard I/O?
    1. Used to represent input and output across all Java implementations used for keyboard and file input and output.
  15. How do you specify the main() method’s header?
    1. public static void main(String[] args)
  16. What is an IDE?  Identify the IDE that Google supports for developing Android apps.
    1. An IDE is an integrated development environment.  It removes the tediousness of compiling, debugging and executing applications as they are being developed.  Google (as of the time of the writing of this book) supported Eclipse with the ADT (Android Development Tools).  As of the end of 2014, Google was pushing Android Studio as it’s primary development focus.
Posted in Programming | Leave a comment

December 31st: Mottos for the New Year

“I love deadlines.  I like the whooshing sound they make as they fly by.”
— Douglas Adams

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.”
— Tom Cargill, Code Complete, Chapter 31: Personal Character

Heh.

Posted in General | Leave a comment

December 31, 2014: Last Day for Apress All Access for $149.

I signed up for Apress’ All Access because I buy way more than 3 computer books a year, and generally speaking, way more than 3 of what I buy are Apress books.  Might as well reward the publisher, right?  That’s the common saying at least:  if they made it available at a decent price, we’d buy it.

$149 is a very reasonable price for access to Apress’ entire library.  The ability to download ePubs for $4.99 is a side benefit that I will take advantage of.

Of course I still have to do something with my knowledge.

Posted in Programming | Leave a comment

December 22, 2014: Accepted A Job, Programming != Computer Science

I’ve accepted a job at Schnucks, where I was contracting.  Everyone cheer!

Also, programming != computer science.  But what if you could pick up the knowledge distributed in a computer science course for free?  You can!  This is here for me more than you; I admit that unashamedly.  Check out http://blog.agupieware.com/2014/05/online-learning-bachelors-level.html.

 

Posted in General | Leave a comment

December 8, 2014: Open to new job, other miscellaneous.

First, I’m looking for a new job.  If you’re interested my StackExchange profile can be found at http://careers.stackoverflow.com/bmschkerke.  I’m currently a contractor and frankly, I don’t like being a contractor.  Promises to be hired on have not been followed through with so it’s time to move on.

Second, I finally upgraded my home network to Gigabit.  I probably should have done this years earlier but I always balked at the price.  Now, with the Linksys SE2500 at $40.00 or so it was a no brainer.  Most of the machines I have already had Gigabit interface cards.

Third, I just picked up the Kindle HDX for $140.00.  Time to pass my iPad 3 on to my daughter, I think.  While I enjoy the Apple products I have much heavier investments in the Android ecosystem.  Might as well leverage them.

Finally, I got sucked into World of Warcraft, specifically the Draenor expansion.  It is comfortingly mind numbing, but I wish I had something else to challenge me other than this.

Posted in General | Leave a comment

November 12, 2014: Microsoft open sourcing .NET

Here’s the official Microsoft release.

This is great.  This provides an alternative path for developers to smash into Linux and Mac development while using their existing skill set.  This expands the Microsoft base and allows them to offer Premium services (becoming more service oriented like a Red Hat or Ubuntu) while providing their world class tools to developers.

.NET was never sold, so I can’t see a down side to this announcement.  Much kudos to Satya Nadella for this change.

Disclaimer:  This is the announcement.  We won’t see the actual result of this change for a while yet, but it is exciting to see.  And I do predict that we will see impact from this change.

Hanselman has a great summary of everything happening here.

Posted in General | Leave a comment