howto: first mobile application in Netbeans

Today I’ll show how to create new mobile app project using Java Mobile and Netbeans (if you don’t have Netbeans installed, read my recent post). If you have installed IDE properly, you should see this screen:
To start new project click:Next, choose options responding to what kind of project you want to create. Select “Java ME” and “Mobile Application”Now, choose project name and path. Also you need to select options “Set as Main Project” (about it later), and “Create HelloMIDlet” which is responsible for creating default MIDlet (Java Mobile application for mobile phone). You can see, that project folder has been set automatically.
On the next screen don’t change options “Emulator Platform” and “Device”. It is important to change device configuration and profile. Change CLDC to 1.0 and MIDP to 2.0 (see image). It will let us to run app on much greater number of phones (this issue was covered in earlier posts).Don’t change anything on next screen and press “Finish”.

Congratulations! You have just created your first mobile app project, automaticaly thanks to option “Create HelloMIDlet” Hello midlet was created 🙂 and it’s ready to run and be copied on mobile phone.

IDE look after clicking “Finish”: Now, you can jump beetween code vieves by using thoose buttons.

  • Source lets you edit source code.
  • Screen lets you edit application view in easy-to-use interface. I don’t recommend this method. Of course it’s very easy in the beginning, but later, if you have to do some tiny modyfication, you’ll need to use it again – code created by this editor cannot be modified in “Source” tab. It’s easier in the beginning as I said, but after gaining some experience you’ll find everything easier to do in “Source” tab.
  • Flow is used to project, edit, view, or set relationships beetween application’s screens.
  • Analyzer – let’s leave this for later.

Becouse during creating project we have set option “Set as main project”, now we can only click button marked on screenshot (or use shortcut F9) to build and run our project.

Now we can “play” with our program in emulator window. Files ready to upload on your mobile are located in:

D:javaHellodist

in my case, and generally:

[project location] / [project name] /dist/ [filename].jad and .jar

filename is by default set to project name.

I would like to encourage you to experiment with this app and IDE’s options. Soon I’m going to post information on how to edit options in JAD file (this file is read by telephone to set information about program, like name, vendor, version).

Java Mobile – introduction

Firstly, quick introduction: JavaMe (also known as: j2me, jme, java me, Java Mobile Edition, …) is a special version of Java (in fact it is “frozen” Java 1.3, maybe with some features) dedicated to devices with low computing power, we distinguish two configurations: CDC (palmtops, more powerful phones, …), CLDC (Connected Limited Device Configuration) – baisicaly every other phone.

Configurations include basic classes, and they are extended by profiles (MIDP – Mobile Information Device Profile), all new phones should handle MIDP version 2.0 (newer 2.1). Profiles provide classes to:

  • handle screen (high and low level)
  • multimedia features
  • better connectivity (eg. HTTPS)
  • and many more

Next, phone can also provide additional APIs, called JSR. JSRs extend phone’s powers (for example by allowing you to use bluetooth), they are not included in CLDC nor MIDP. Every JSR has it’s own number, so they are easly identified (bluetooth is called JSR-82).

All programs I’m going to write require MIDP version 2.0. That doesn’t mean you wont be able to run them on older phones, but you may not be able to use things that are extended in version 2.0, for example you won’t hear background music playing, or you won’t be able to initiate call inside application.

When writing program for mobile phone, you should remember, that it’s manufacturer is responsible for delivering appropriate runtime environment (JVM). Sometimes it is not written according to specification delivered by Sun. I have noticed, that Nokia models have some problems with some elements of GUI. I have also tested Samsung’s and Sony Ericsson’s, and didn’t have any problems with them (I have no possibility to chceck it on other phones, so I don’t know how it is with for example Motorola).

You can find additional info on wikipedia (as usual):

At most on Friday I’ll post information how to start new project in Netbeans, and start writing programs:)