It's not a secret anymore!*
The moose likes Product and Other Certifications and the fly likes MIDlet lifecycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "MIDlet lifecycle" Watch "MIDlet lifecycle" New topic
Author

MIDlet lifecycle

Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Q)What will happen when the following code is executed?

import javax.microedition.midlet.*;

public class MyMIDlet extends MIDlet {

private String name;

public MyMIDlet(String name) {

this.name = name;
}

public void startApp() {

System.out.println("The device name is: " + name);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional)
throws MIDletStateChangeException {

this.notifyDestroyed();
}
}

Choices:

a) The program will be installed but will throw a RuntimeException when invoked.

b) The program will throw a javax.microedition.MIDletException when invoked.

Which choice is correct one? OR Which exception will be thrown when a MIDlet with non-default constructor is called?
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Actually none of them is correct. java.lang.IllegalAccessException is thrown when the MIDlet is invoked. It's not a RuntimeException type nor a javax.microedition.MIDletException(which does not even exist).

The explanation is that you have to have a no-argument constructor in the class. If you don't want to put one, there should be no other constructor at all. Otherwise, it will throw that IllegalAccessException error, which from the AMS invocation on the class constructor.

Hope it helps...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Thanks Ko Ko
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8801
    
    5
Hi Girish,

Are you using the wireless toolkit from Sun? It's a great way to test your J2ME code questions, and probably the single best way to study for the exam is to write lots of little programs to test stuff out!

Plus, it's free!

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Hi Bert,

Yes, I am using J2ME wireless toolkit from sun.

Thanks for suggestion..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MIDlet lifecycle
 
Similar Threads
J2ME program
Nokia Emulator shuts itself down
New to J2ME and authorization failed message
Some more Mock questions #1 For me
destroyApp(true) || notifyDestroyed()