Skip to main content

Posts

Showing posts from October, 2009

Programmatically Read JAD file in Blackberry

in here following code worked but you have to deploy the application using JAD file (download through the web)  not the using alx file. public static String getJADProperty(String Name){ CodeModuleGroup[] allGroups = CodeModuleGroupManager.loadAll(); CodeModuleGroup myGroup = null; String moduleName= "" ; moduleName = ApplicationDescriptor.currentApplicationDescriptor().getModuleName(); for ( int i = 0; i < allGroups.length; i++) { if (allGroups[i].containsModule(moduleName)) { myGroup = allGroups[i]; break ; } }   // Get the property String prop = myGroup.getProperty(Name); return prop; } You can get the custom property by calling // You can get the MyTag:something String value = getJADProperty( "MyTag" )

Asynchronous Threading in Blackberry

Assume that you are having a class called Class A it needs to call Class Z as a thread. Therefore you can  implement class Z from Runnable interface and implement your code in run(). Ex:- public class ClassZ implements Runnable {   public static final int METHOD1 =1; public static final int METHOD2= 2;   int code; public ClassZ( int code) { this .code=code; }   private void method1() { //Code for Method1 }   private void method2() { //Code for Method2 }   public void run() { switch (code) { case ClassZ.METHOD1 : method1(); break ; case ClassZ.METHOD2: method2(); break ; } }   public void runThread() { thread = new Thread( this ); thread.start(); } } If you start the Thread using ClassZ it runs ClassZ’s run method. Therefore  if you have several method...

Best Practices in programming

I though to write a continuous article describing best practices in programming. Here I’m not going to talking about  coding conventions but talking about enhanced cording techniques you can use. Using IO, Network connections InputStream streamRead =null; try { // Use InputStream to do your work } catch (Exception ex) { // Exception Handling } finally { try { // Try to close the stream, This may also give erros // resulting opened stream streamRead.close(); } catch (IOException e) { } // Set Stream to null to prevent // unwanted openings streamRead=null; } Not to use methods in loop’s conditions // This is not optimized for ( int i = 0; i < elements.capacity(); ++i) { // Code Here }   // This is optimized, // elements.capacity() only call in one time int capacity = elements.capacity(); for ( int i = 0; i < capacity; ++i) { // Code Here } Use String Buffer wherever possible. // This will create two st...