问题描述
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:
System.out.println("Hello");
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 super
instead of base
Gotcha #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:
public class A extends B {
}
That means class A
is a subclass of class B
. In C# would be class A : B
Gotcha #5 - Why don’t constants remain constant?
To define a constant in Java use the keyword final
instead of const
Gotcha #4 - Where is ArrayList
, Vector
or Hashtable
?
The most used data structures in java are HashSet
, ArrayList
and HashMap
. They implement Set
, List
and Map
. Of course, there is a bunch more. Read more about collections here
Gotcha #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 virtual
in Java. All methods - except those declared final
- can be overridden in Java.
And the #1 gotcha…
In Java the primitive types int
, float
, double
, char
and long
are not Object
s like in C#. All of them have a respective object representation, like Integer
, Float
, Double
, etc.
That's it. Don't forget to see the original link, there's a more detailed discussion.
这篇关于为 C# 人真正了解 Java-ME 的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!