ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Getting Started in BlackBerry App Development

Updated on May 7, 2012

Writing BlackBerry Apps

To write BlackBerry apps you need to know Java Programming. Two flavors of IDE are available from RIM developer website:

  1. JDE
  2. Eclipse Java Plug-in

Although you can install Eclipse separately first and then install the plug-in it is much better to install using "Full Installer" RIM developer site provides. The full installer installs a compatible version of Eclipse along with all the required BlackBerry dependencies.

Please note that JDE that you install will be a 32-bit software expecting 32-bit Java. In case of Eclipse installation since RIM supplied installer does all the installation you do not have to worry about these issues.

Also please note that BlackBerry devices too have different versions of BlackBerry Operating System, so JDE that you download will be for a specific BB-OS. In Eclipse also this point is to be born in mind because when you reach the stage when testing is to be done you will need to select the device simulator for the device that you are targeting. Because of these complexity it is much better that a novice BlackBerry developer starts with installing Eclipse Java Plug-in. Later as and when a specific simulators are needed you can download them. This avoids having to download and install multiple JDE's.

I strongly urge you to sign up to BlackBerry Developer website because some of RIM supplied API packages require you to sign your app with RIM supplied "signature". In past RIM was charging $20 for acquire a "signature" but now it is free. Signing up to BlackBerry Developer website also opens doors to many RIM supplied developer resources as well as many forums where answers to difficult problems can be found.

Biggest problem with using Eclipse Plug-in is that the full installer takes hours to download. But in my opinion developing using Eclipse Plug-in is much better experience. So I would recommend that you start with first installing Eclipse Plug-In. Since it will take hours to download I suggest that you pause reading this article and return when you have installed the plug-in. From this point and in my other articles on the BB app-dev topic I am assuming that you have installed BB Eclipse Java Plug-in.

Happy downloading!

Happy Downloading

Things at BlackBerry developer site are not well organized. Sometimes it takes more than one try to find what you want. Absolutely first thing to do is to search on Google the keywords: "BlackBerry Developer Zone". Click on the link which looks like the official BlackBerry Developer site.

Click on "Platforms" on top navigational menu. When page loads click on BlackBerry Java panel. The full installer for Eclipse BlackBerry Java Plug-in should be in "Tool" section. Alternatively go straight to "Downloads" page and search from there.

If you are not able to find quickly the link for Eclipse Plug-in send me a message. I will try to reply in a month or two.

First Steps

Okay. So now we will start writing our first BB App. Even if you have decided to use JDE instead of Eclipse because of similarity of steps involved in setting of new project reading this will be instructive. First of all any Java development requires a "Workspace". If your learning computer is shared with many students then you should create a folder which will uniquely identify your workspace. You may be learning from multiple sources or books. You may decide to make one workspace folder for each source. So for example we have a hypothetical reader named "Maria Roberts" who is also reading author "Bob Barkin" who has written some web-pages on BB programming. Maria Roberts finds that on a PC she shares there is already a folder named "c:\m" created by another student "Meena Shah". So Maria decides to create a folder named "c:\mr". After Maria started learning from Bob Barkin's webpages she had created a folder named "c:\mr\b". So when she starts learning from articles written by Bakulesh Thakker she creates another folder named "c:\mr\bt". Advantage of having shorter names is that should the need arise to type it you will not have to type a lot. Disadvantage is that if everyone is using short names then a mistype can have grave consequence.

When you start Eclipse you will be asked for a workspace location. Once you select the appropriate workspace, Eclipse will open a "perspective". The "perspective" is an Eclipse concept. It means what all panes will show on screen. Fortunately, the BlackBerry Java Plug-in opens by default in what is known as "BlackBerry Application Development" perspective. But in a student environment you may be sharing your learning computer with another student who may have made another perspective as default. In this case you must talk to your instructor for change in default or temporarily open BBAppDev perspective. It is possible to install multiple copies of Eclipse IDE. For non-BB use your instructor or system admin might want to install another Eclipse IDE for non-BB use by other students.

When BB App perspective opens it looks very much like a Java perspective. There is a "package" explorer on left side. If you have just started there would not be any package saved to workspace yet. So let us start our first BB project. From menu select "File" >> "New" >> "BlackBerry Project". Many menu or sub-menu options have shortcut keys. For "File" >> "New" there is Alt+Shift+N. You should find out these and for more frequent menu actions you should start using them. For a novice it may give you false sense of mastery. But in job interviews your interviewer might be impressed and convinced that you have been a developer for some time. Truth is mastery of IDE is small part of learning.

What is in the name?

We first start a new BB project. For purpose of my articles on BB App Dev I am using C:\hp\bt as my workspace folder. By now you should know that workspace is nothing but a folder. In Java programming sometimes there are restrictions. For example, a Java class definition for (say) HWApp must be in a source file named: HWApp.java. Some of these programming system idiosyncracies can be figured out by using random names. So for example we will be building software for a Hello World App using names like HWApp, HWScreen etc. But you may build this Hello World App using random names to know which files are created by Eclipse and what is in these files. For example, I once used Hindi equivalent of children's nonsense rhyme: eeny meeny miny moe. (In Hindi it is: akkad bakkad bambe bol, assi nabbe puray sau. I don't remember remaining lines but these random words suffice for my task.). So, for example, instead of "bt" I used "akkad". That gave me a clue that the "bt" for Eclipse is nothing but a folder. I used "bakkad" for project name. Then I found inside the folder "akkad" two folders: ".metadata" and "bakkad". In this way I freely helped myself with random words instead of familiar names like "HelloWorld" etc just to discover where these names are going and which names are ending up becoming file names or class name and so on. Things are slighly different in standalone BB JDE. Once you have used both flavors of development IDE's you will start using one preferentially over other depending on how easy or pleasant your use experience had been. We will, however, continue with Eclipse below.

Create a New Project

First we create a new project. Use menu option "File" >> "New" or shortcut key Alt+Shift+N and select "BlackBerry Project" option from sub-menu. We will call the project as simply: "HelloWorld". In the dialogue that appears for "Project Name" enter "HelloWorld". Click "Finish" button on dialogue. Eclipse will create a template for you application with all the default names. So, for example, the package name is simply taken as "mypackage". If you had not clicked "Finish" but rather clicked on "next" button you would have been given option to change these names.

Package Name

There are no hard and fast rules for naming Java packages. One of the most frquently used RIM supplied class is: net.rim.device.api.ui.UiApplication, of which the last word "UiApplication" is the class name. Rest of the name shows the hierarchy of names. There is rather long three word prefix: "net.rim.device". Word "net" sounds like part of a internet address: www.rim.net. That begs question as to why Research In Motion is using "net" because as of now www.rim.com is owned by RIM company? Answer to that question is probably once in ancient past they did not own www.rim.com domain but they did own www.rim.net. This is just a guess. Like domain package names are to ensure that they are unique. Package name becomes important if you are going to develop library packages.

Class Name

For class name issue of what to select is simple. We want it to represent a blueprint of an object. A class is plan. An object is actual thing. Class name, therefore, a generic name. Whereas object is a realization of some class. As such its name will reflect the business purpose it serves. Having said this, often it is difficult to come of with different name for class and their objects because often a class is used for creating exactly one object. In this case only by using a convention we may be able to distinguish for human reader of program. One convention is to use for a class name words without intervening spaces with first letter of each word capitalized. Like this: HelloWorldApplication. Actual object created will start with lower case letter but in name of object also we can capitalize the start of other words. Like in example below:


 HelloWorldApplication mainWindow = new HelloWorldApplication();


Method called "main"

Almost all BB apps will have a class which extends UiApplication or some such similar class. At least one object of this class is always coded. This object has a method called "main". When an app is started it receives the control first. An app which cannot be started multiple times must detect if the app has been already launched once. This can happen if user started an app and then started working on other apps or minimized this app and forgot that he had started it. If an app is already running and expected behavior of app is that it's UI is made visible then that is what the code in "main" method should do. If app was not started then its expected task is to first setup the initial UI screen with appropriate messages and prompts reporting on first things that app does. For example, an app that assumes availability of WiFi connection might not find one. In this case app must report that on it and await user to dismiss the mess or close the app. A typical HelloWorld main method looks like following:

public static void main(String[] args)
{
  HelloWorldApplication mainWindow = new HelloWorldApplication();
  mainWindow.enterEventDispatcher();
}


Those familiar with programming in C will instantly recognize parameter passed to "main" method as second parameter of a function called "main". First parameter is incorporated in array size of args. Although the "main" method receives these parameter it is hardly ever used in BB App's.

Examine the folder "mypackage" and you will find two files: MyApp.java and MyScreen.java. As explained above if instead of clicking on "Finish" button if you had clicked on "Next" button you would have given different names. May be you would have given HelloWorldApplication and HelloWorldScreen. These respectively will generate HelloWorldApplication.java HelloWorldScreen.java files. Browse files: MyApp.java and MyScreen.java. They seem to be complete BB App software. This software is standard BB App template. Most templates are skeletal and sometimes even incomplete programs. When you fill out details these become complete. If you are curious you can run this application.

There are two things to bear in mind before you run a serious App. First is that you are required to "sign" your application with a RIM supplied signature if your App is using some restricted API's. Second is selection and configuration of simulator to use. The Eclipse as installed has a BB simulator for 9930 device.

We will discuss these and other topics in upcoming articles.

If you tried to run the skeletal app then unless you know all BB apps that come bundled with the device you would not know which is your app. For making you app easy to recognize and stand out from other apps you need to make an icon for it.

To fix our ideas we will build a simple app to illustrate various concepts. We describe briefly this.

A Simple Pedagogic App

The planned pedagogic app will show two fractions in form: a b/c + d e/f. User is required to calculate: a + b / c + d + e / f and enter it in form: q r/d. Here q is quotient, r is an integer less than d. Please note that fractions "a b/c" and "d e/f" are too in same format except they may not be normalized form. That is, if the answer is: "2 3/4" then "2 6/8" is not correct answer. But a + b/c could be presented as 2 6/8 just for extra hard mental exercise for players. We will write first version of this "game" in which user simply enters all components of answer and then clicks verify button. Later version will expect answer within some time limit. Also each digit entered must be correct because no correction even for typo error would be allowed. We can also include a simple score system for this game. Hopefully this game will be fun and instructive for learning Java and BB App programming.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    Click to Rate This Article