Introduction




Name of Experiment: Calculate Available and Free Memory of NOKIA ASHA 501

Exp No: 8

Background: Student should have a basic knowledge of Java Programming.

Summary: After going through this experiment, student should be able to calculate available and free memory of NOKIA Asha 501 device.

Learning Objective: Here, Student should learn the procedure to calculate available and free memory of NOKIA Asha 501 device. After, doing this experiment user himself will be able to make an app to calculate available and free memory of NOKIA Asha 501 device.

Target

Target Platform:This experiment is tested on Nokia Asha Device 501.

Procedure

SourceCode

Source Code:

package memory;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Memory extends MIDlet implements CommandListener {
Form PhoneMemory;
long freememory,totalmemory;
Command memory1;
String f1,f2;
public Memory() {
PhoneMemory=new Form("PHONE MEMORY");
memory1=new Command("Show Memory",Command.OK,0);
PhoneMemory.addCommand(memory1);
PhoneMemory.setCommandListener(this);
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(PhoneMemory);
}
public void commandAction(Command arg0, Displayable arg1) {
if(arg0==memory1)
{ freememory=Runtime.getRuntime().freeMemory();
totalmemory=Runtime.getRuntime().totalMemory();
f1=Long.toString(freememory);
f1=new String("Free Memory:"+f1);
f2=Long.toString(totalmemory);
f2=new String("Total Memory:"+f2);
PhoneMemory.append(""+f1);
PhoneMemory.append(""+f2);
PhoneMemory.append("By:Nicy Kaur Taneja");
PhoneMemory.append("Vandana Kumari");
}}}

Snapshots



This is how the output appears on the emulator of NOKIA Asha SDK 1.0 on successful compilation of source code.

Observation

Observation: Students have successfully displayed the Total and the Free Memory of NOKIA Asha 501 device.

Video Link

Download