Android for Beginners: Booleans

One interesting thing that I have discovered recently is that in java (and in Android), when we declare a boolean as an instance variable in the class without instantiating it, java automatically instantiates it as false. Let’s take a practical example, one that I have encountered recently.

Inside an app, there a boolean instance variable was declared:

public class example {

    private Boolean test;

…do something …


Inside the class, we have an if statement which is driven by the boolean variable that has just been created, in other words, we have the following:

if (test) { …do something …}

But since we never instantiated the test variable, one would assume a nullpointerexception would be returned, since we never instantiated “test”. However, from my research, I found out that booleans are actually primitive types and therefore they cannot be null. Only reference types can be null. 

See the following website for description of the two different types:

  • primitive types are the basic types of data
    • byte, short, int, long, float, double, boolean, char
    • primitive variables store primitive values
  • reference types are any instantiable class as well as arrays
    • String, Scanner, Random, Die, int[], String[], etc.
    • reference variables store addresses

Furthermore, if you do not instantiate booleans, the boolean is automatically instantiated by android to “false”. See the boolean section on the android site and look under the section called constructor:

Therefore our if statement will be skipped as we will have if (test) which is the same as if (false).



Android for Beginners: Coursera

Coursera is one of those absolute gem that I have found indispensible for new android programmers. The courses there are given free of charge by various universities which contribute through making MOOC (Massive Online Open Courses) available to the world so anyone, anywhere, can learn. Coursera really does a wonderful job in making education freely assessible. 

Coursera courses come with video lectures that are dished out on a weekly basis. Watching these videos can take about 1 – 2 hours, depending on the level of proficiency / knowledge you have on the subject. After watching the videos, there are quick quizzes and assignments you can do to test your knowledge. These quizzes and coding assignments which are both graded automatically by the Coursera system. All you need to do is to upload your code onto the site, it grades it for you, and within a few minutes, the system comes back with your marks.

There is also a massive support community on Coursera forums consisting of both students who are doing the course, teaching assistant (TAs) and of course, the lecturer. You can post a question on the forum and within a day, you are almost certain to have your answer. Don’t be scared to ask a question there  – people there are available and willing to help you with your problem and most importantly, people understand where you are coming from as a beginner as they are also in the same boat as you.

I’m currently watching the videos for Programming Cloud Services for Android Handheld System ( Dr Jules White does an excellent job at explaining the basics of HTTP and the communications between the app and the cloud. It is definitely worth a look at.


Android for Beginners

If you browse the internet for android coding stuff, you will find a ton of documentation written in high-level gobblegobble that sometimes doesn’t make a lot of sense.

That’s probably because android docs and tutorials, for example, even on the authoritative site, are more targeted at seasoned coders and not really for our mild beginners. Sometimes, you just need someone to do some translation for you on some of the methods android offers so that a beginner, like yourself (and myself, to an extent), can understand.

In the last 8 months where I have been learning android myself, I have made a lot of headway in understanding the code. I have also completed a coursera course on Programming Mobile Applications on Android Handheld Systems which ended in April 2014 and passed that with flying colours.

In the next few posts, I want to share my discoveries with the rest of the world and with all you lovely readers 🙂 – on what I have discovered on my Android Adventures. These posts will be written at a basic level so that beginners can gain a basic understanding of the concepts inside the vast system of Android.

Stay tuned for my Beginners: How-To Guide to Android.