My connection has been fixed so today I was able to resume the TheNewBoston tutorials. Today I learned some new interesting things while working on a second app from the tutorial.
The app consists of a text input box, that when typing certain commands it will do things. For example you can type in WTF and it will print it out below the input box, but with random colors and text sizes, I got introduced to the Random class in Java to implement this. I also learned about password input type, which can hide what you are writing in the input box like a password. I did that by putting a toggle where ON = hide the input text.
[slideshow]
I learned that a final variable cannot be changed. Also that you cannot compare two strings with “==”, you have to use the “.contentEquals()” method or a variant thereof. when you use == for strings, you are checking if the memory location of both strings are the same instead of checking to see if they contain the same word.
The tutorial introduced me to a switch statement which i had never heard of before. Now I know it’s a conditional statement and know how to use one. It is replaceable by the traditional” if/else” statement, but the latter is more of a choice, semantically speaking. If this is true, then you do something, if not, then you do something else. While a switch is more of a case e.g.this switch refers to this type of case. At least that’s how I see it, and I’m just a newbie.
I also got introduced to implementing interfaces. I had always seen examples where you extend a class, which means that in your current class you can use methods from another class. When you implement an interface though, you have to use all the methods. An interface is a reference type, like a class is, but can only contain constants, method signatures, and nested types. They don’t have method bodies and cannot be instantiated like a class can, they can only be implemented by classes. The interface I used is View.OnClickListener which is a public static interface.
Leave a Reply