I’ve recently started developing applications for the Blackberry. Consequently, I’ve had to jump to Java-ME and learn that and its associated tools. The syntax is easy, but I keep having issues with various gotchas and the environment.
For instance, something that surprised me and wasted a lot of time is absence of real properties on a class object (something I assumed all OOP languages had). There are many gotchas. I’ve been to various places where they compare Java syntax vs C#, but there don’t seem to be any sites that tell of things to look out for when moving to Java.
The environment is a whole other issue all together. The Blackberry IDE is simply horrible. The look reminds me Borland C++ for Windows 3.1 – it’s that outdated. Some of the other issues included spotty intellisense, weak debugging, etc… Blackberry does have a beta of the Eclipse plugin, but without debugging support, it’s just an editor with fancy refactoring tools.
So, any advice on how to blend in to Java-ME?
This guy here had to make the inverse transition. So he listed the top 10 differences of Java and C#. I’ll take his topics and show how it is made in Java:
Gotcha #10 – Give me my standard output!
To print to the standard output in Java:
Gotcha #9 – Namespaces == Freedom
In Java you don’t have the freedom of namespaces. The folder structure of your class must match the package name. For example, a class in the package org.test must be in the folder org/test
Gotcha #8 – What happened to super?
In Java to refer to the superclass you use the reserved word
superinstead ofbaseGotcha #7 – Chaining constructors to a base constructor
You don’t have this in Java. You have to call the constructor by yourself
Gotcha #6 – Dagnabit, how do I subclass an existing class?
To subclass a class in Java do this:
That means class
Ais a subclass of classB. In C# would beclass A : BGotcha #5 – Why don’t constants remain constant?
To define a constant in Java use the keyword
finalinstead ofconstGotcha #4 – Where is
ArrayList,VectororHashtable?The most used data structures in java are
HashSet,ArrayListandHashMap. They implementSet,ListandMap. Of course, there is a bunch more. Read more about collections hereGotcha #3 – Of Accessors and Mutators (Getters and Setters)
You don’t have the properties facility in Java. You have to declare the gets and sets methods for yourself. Of course, most IDEs can do that automatically.
Gotcha #2 – Can’t I override!?
You don’t have to declare a method
virtualin Java. All methods – except those declaredfinal– can be overridden in Java.And the #1 gotcha…
In Java the primitive types
int,float,double,charandlongare notObjects like in C#. All of them have a respective object representation, likeInteger,Float,Double, etc.That’s it. Don’t forget to see the original link, there’s a more detailed discussion.