This MIDlet will catch all System.out, System.err, and it can be useful debugging tool.
What you need to do is to download the
Please have visit to
http://www.mobile-j.de/snipsnap/space/J2ME/System.out+redirect+on+S60+3rd+Edition
Forms.getMinContentHeight()getPrefContentHeight(int width)hideNotify()keyPressed(int keyCode)paint(Graphics g, int w, int h)repaint()traverseOut()Interface Vs Inheritance
Interface: Like contract, which you must have to follow.
Inheritance: Like hierarchy of functionality.
Now where to use is important, And it totally depend upon situation
Which is appropriate to use depends on circumstances.
From my view:
Interface: If you want same behavior across unrelated classes.
Inheritance: Use when classes have same functionality.
Example:
Let’s say we have a class Singer that represents a human singer. Now, singer can also be a bird or a musical instrument like Piano etc too. If we make a Singer a class then we have to take care of the issue that inheriting Piano from Singer might not work as both classes don’t lie in the same category. Singer is a human (living being) whereas Piano is a non-living thing. So, instead of inheritance we can make an interface say Singable and we can implement it on Piano, Human, Bird etc.
OR
Bear extends Animal
Bird extends Animal
TeddyBear extends Bear implements Pet
Canary extends Bird
TweetyBird extends Canary implements Pet
A Pet is a set of defined behaviours, doesn't provide that behaviour as it will differ widely between your TeddyBear and your TweetyBird (TeddyBear might be cuddly but doesn't sing).
---------------------------------------------------------------
inner class is a class defined inside some other class (but you knew that). Inner classes are able to access the private members of their outer class instance.
A static inner class does not have this ability to access the privates of his outer class. This makes a static inner class very much like a regular class, and in many cases, using one of those mainly adds confusion over using a regular class without giving any real benefits.
Anonymous inner classes are often used because they save you having to explicitly define a class type. It's a shorthand, designed to save time while writing the code. Again, use with caution, cause they can make the code hard to understand.
This is important to understand that when to use static method and when to use instance method:
Thumb rule for Static and Non Static is:
Use Static Method when your method is independent of state of the instance object.
Use Non Static when your method is depending upon state of the instance object.
Let’s understand this by example that is good for all of us:
public class MrHappyObject {
private String _mood = _HAPPY;
private final static String _HAPPY = "happy";
private final static String _ANNOYED = "annoyed";
private final static String _ANGRY = "angry";
private static int _instantiations;
public static void main( String [] args ) {
MrHappyObject obj1 = new MrHappyObject();
MrHappyObject obj2 = new MrHappyObject();
obj1.printMood();
obj2.printMood();
obj1.receiveHug();
obj2.receivePinch();
obj1.printMood();
obj2.printMood();
}
public void printMood() {
System.out.println( "I am " + _mood );
}
public void receivePinch() {
if( _mood.equals( _HAPPY ) ) {
_mood = _ANNOYED;
} else {
_mood = _ANGRY;
}
}
public void receiveHug() {
if( _mood.equals( _ANGRY ) ) {
_mood = _ANNOYED;
} else {
_mood = _HAPPY;
}
}
public MrHappyObject() {
_instantiations++;
}
public static int instances() {
return _instantiations;
}
}
First we will look when to use non static method.
In above example we have 2 object obj1, obj2.
Both are born happy.
Now we call receiveHug() by obj1, and receivePinch() by obj2.Both receiveHug() and receivePinch() are non static method and they depends upon state of the object.
So the final output is:
I am happy
I am happy
I am happy
I am annoyed
That is what we want as Hugging the MrHappyObject`s Object make him happy and
Pinching it make it annoyed. We got the desired result because receiveHug(), and receivePinch() are depend upon state of object and they are non static Method.
Now Comple and run same class by making receiveHug(), and receivePinch() method Static .
public class MrHappyObject {
private final static String _HAPPY = "happy";
private static String _mood = _HAPPY;
private final static String _ANNOYED = "annoyed";
private final static String _ANGRY = "angry";
private static int _instantiations;
public static void main( String [] args ) {
MrHappyObject obj1 = new MrHappyObject();
MrHappyObject obj2 = new MrHappyObject();
obj1.printMood();
obj2.printMood();
obj1.receiveHug();
obj2.receivePinch();
obj1.printMood();
obj2.printMood();
}
public void printMood() {
System.out.println( "I am " + _mood );
}
public static void receivePinch() {
if( _mood.equals( _HAPPY ) ) {
_mood = _ANNOYED;
} else {
_mood = _ANGRY;
}
}
public static void receiveHug() {
if( _mood.equals( _ANGRY ) ) {
_mood = _ANNOYED;
} else {
_mood = _HAPPY;
}
}
public MrHappyObject() {
_instantiations++;
}
public static int instances() {
return _instantiations;
}
}
And the output is
I am happy
I am happy
I am annoyed
I am annoyed
This is not our desired result.
Now this makes clear when to use Static method and when to use non static method.
For creating OTA server you need HTTP server (Web server i.e tomcat50-jwsdp).
Now create new folder under web apps like C:\tomcat50-jwsdp\webapps\counter
Counter contains 2 folder ==>WEB-INF (it contains web.xml), images (or any other name ,it contains JAD n JAR)
Put MIME Type of JAD and JAR.
jad
text/vnd.sun.j2me.app-descriptor
jar
application/java-archive
And access this jad file from your mobile browser it will automatically invoke AMS.
Or can see it from your PC browser
http://localhost:8080/counter/images/
As images folder contains JAD and JAR file. Change locathost to your actual address.