Burak Dede – Read Once Do Everytime

Archive for the ‘java’ tag

Using Eclipse For Blackberry Development

leave a comment

In order to use Eclipse for Blackberry development you have to install Eclipse Blackberry plugin which you can find by signing up for Blackberry development program from Blacberry offical site.You can also use the JDE IDE but i find user interface of the ide awful so using eclipse is a good decision.

  • Download eclipse blackberry plugin full ( about 280 mb)
  • Install plugin with the existing directory of eclipse
  • Your eclipse version must be 3.4.1 or older cause blackberry plugin does not support newest version of the eclipse so you have to dive into older version of eclipse.
  • Than after installing plugin you can easily create blackberry project from file menu.

Written by burakdede

June 15th, 2010 at 10:47 pm

Posted in mobile development

Tagged with , , , , ,

Mysql Turkish Character Problem

2 comments

I come across this problem while dealing with mysql insert data , so i search a little and found solution , it is obvious that it is a character encoding problem but which one to choose is problem.First you can change the mysql connection url something like this ” jdbc:mysql://localhost:3306/yourconnectionname?characterEncoding=latin5″ , than you have to change the database table and coloumns encoding by altering collacation property with latin5 , actually utf-8 encoding will do the job too but i havent tried it…

Written by burakdede

June 15th, 2010 at 11:35 am

Posted in database

Tagged with , , , , ,

Introduction To J2ME Platform

10 comments

J2ME isn’t a specific piece of software or specification. All it means is Java for small devices. Small devices range in size from pagers, mobile phones, and personal digital assistants (PDAs) all the way up to things like set-top boxes.

J2ME is divided into configurations, profiles, and optional APIs, which provide specific information about APIs and different families of devices. A configuration is designed for a specific kind of device based on memory constraints and processor power. It specifies a Java Virtual Machine (JVM) that can be easily ported to devices supporting the configuration. It also specifies a strict subset of the Java 2 Platform, Standard Edition (J2SE) APIs that will be used on the platform, as well as additional APIs that may be necessary. Device manufacturers are responsible for porting a specific configuration to their devices.

Profiles are more specific than configurations. A profile is based on a configuration and provides additional APIs, such as user interface, persistent storage, and whatever else is necessary to develop running applications for the device.

Optional APIs define specific additional functionality that may be included in a particular configuration (or profile). The whole caboodle—configuration, profile, and optional APIs— that is implemented on a device is called a stack. For example, a possible future device stack might be CLDC/MIDP + Mobile Media API. See the section “Platform Standardization” later in this chapter for information on JSR 185, which defines a standard J2ME stack.

J2ME configuration divided into 2 categories according to device specifications.First one is Connected Device Configuration called CDC which sits on top of the J2ME.These devices have to meet the requirements specified by JSR community process.CDC devices target especially high end PDA’s , navigation systems , settop boxes.Therse devices has ,at a minimum, 512KB of read-only memory (ROM), 256KB of random access memory (RAM), and some kind of network connection.And also CDC devices gives full JVM support.

Other type of configuration is Connected Limited Device Configuration which is called CLDC.This configuration category include devices like mobile phones,pagers,PDA’s…As you see these devices smaller than the devices listed on CDC.CDC devices have limited memory , limited processor power ,limited screen size,limited battery life because of these developing applications for these devices is a important process.The CLDC is designed for devices with 160KB to 512KB of total memory, including a minimum of 160KB of ROM and 32KB of RAM available for the Java platform.For note connected means here network connection that is not very fast and intermitted.These devices support specific implementation of JVM which is KVM.K means here as far as i know “it is a JVM whose size is measured in kilobytes rather than megabytes”.

Other important part of J2ME is profiles.I am not going to dive into other profiles just MIDP which is the important and known one  in J2ME development.MIDP stands for Mobile Information Device Profile and have also JSR process and specifications.Here is the MIDP 2.0 specifications.

  • A minimum of 256KB of ROM for the MIDP implementation (this is in addition to the requirements of the CLDC)
  • A minimum of 128KB of RAM for the Java runtime heap
  • A minimum of 8KB of nonvolatile writable memory for persistent data
  • A screen of at least 96×54 pixels • Some capacity for input, either by keypad, keyboard, or touch screen
  • Two-way network connection, possibly intermittent

Most of the latest devices support MIDP 2.0 specification but older ones user MIDP 1.0.

Structure of MIDP Application

MIDP application has a API which comes from both CLDC and also MIDP 2.0 .CLCD api comes from core api defined in Java SE and MIDP api comes with java micro edition packages.Here is a list of avaliable packages.

For CLDC

  • java.lang
  • java.lang.ref
  • java.io
  • java.util
  • javax.microedition.io

For MIDP

  • javax.microedition.lcdui
  • javax.microedition.lcdui.game
  • javax.microedition.media
  • javax.microedition.media.control
  • javax.microedition.midlet
  • javax.microedition.pki
  • javax.microedition.rms

Also device vendors supply their own API’s specific to their device.These are different API’s from MIDP and as i said specific to that device not platform independent and make developers to reach device specific features.MIDP applications sits on top of the device specific OS , and use only api provided by MIDP and CLDC.Device specific java application use API provided by device vendor.(Device Specific API’s).

Advantages of MIDP

Portability

The advantage of using Java over using other tools for small device application development is portability. You could write device applications with C or C++, but the result would be specific to a single platform. An application written using the MIDP APIs will be directly portable to any MIDP device.

Security

A second compelling reason for using Java for small device development is security. Java is well known for its ability to safely run downloaded code like applets. This is a perfect fit—it’s easy to imagine nifty applications dynamically downloading to your mobile phone.

Written by burakdede

June 14th, 2010 at 12:18 am

Posted in java,mobile development

Tagged with , , , , , ,

Creating Your First MIDlet Project : Hello World

2 comments

I assume you have proper development enviroment , which i explained for MacosX here .Here is the steps you have to follow to create new MIDlet project under Eclipse Pulsar.

  1. File -> New -> MIDlet Project
  2. Enter Project Name , and also add Configuration which i explained here for MpowerPlayer by showing path of the MPowerPlayer.
  3. After that create a new Java ME MIDlet class again from File menu with File -> New -> Java ME MIDlet
  4. Use the following Hello World code for MIDlet.
  5. Use the following source code for MIDlet.  HelloWorld.java
  6. Right click project -> Mobile Tools For Java -> Create Package
  7. Right click project -> Run As -> Emulated Java ME MIDlet and then you are done…

Written by burakdede

June 13th, 2010 at 4:38 pm

Developing J2ME Application on MacOSX

leave a comment

The reason for such a headline is that developing J2ME applications on MacosX kind of problematic.First of all there is no offical Java Wireless Toolkit for MacOS.Sun havent released one yet.You have to use 3rd party applications such as MPowerSDK.I am going to list steps to prepare your development enviroment with Eclipse IDE.

  1. Download latest JDK from Sun site if you havent downloaded yet.
  2. If you are familiar with Eclipse IDE , they develop a package named “Pulsar” for mobile development ready tools bundled you can download it. For other IDE support look this topic.This package comes with Mobile Tools for Java plugin.
  3. Download MPlayitSDK from their site , cause Java Wireless Toolkit is only available for Linux and Windows enviroment not for Mac yet.
  4. If you want obfuscation support download ProGuard.Configure it under Preferences -> Java ME -> Packaging -> Obfuscation .

Written by burakdede

June 13th, 2010 at 2:12 pm

Change the Default Port On Grails Application

leave a comment

Grails applications by default run on 8080 port.But sometimes  other applications may use the same port ,to solve this problem you need to do some simple console work while starting your application.Let say you want to run your application on port 9090 insted of default one.

grails -Dserver = 9090 run-app

Making changes on default port is simple like that , but if you wanna make this change permanent you can create BuildConfig.groovy file under directory “/grails-app/conf”

"grails-app/conf/BuildConfig.groovy"

Written by burakdede

February 16th, 2010 at 4:17 pm

Posted in grails

Tagged with , , , ,

(Auto)Boxing and Unboxing with Java Generics

29 comments

As you may know auto boxing and unboxing is a new feature of the Java 6.(which is not new for languages like C#, we can say it is new feature for the Java).Java has two main data types one is primitive type and other is reference types.Primitive types are the types generally built in language (like int , short,byte,long,float,double,bool,char…) and allocated on the stack side of the memory.But reference types are the types lets say shortly any type that subtype of the class Object in java (like class,array,String…) and they allocated on the heap side of the memory.

What about boxing and unboxing , boxing is conversion of the one primitive type to its corresponding reference type (int to Integer in this situation) while unboxing is conversion of the reference type to corresponding primitive type.You can think of actually “boxing” the varaible and putting it to heap side , and unboxing as reverse procedure to the stack side.

These boxing and unboxing operations are automatically done by java while using generics.Generics  can think of as a compile time check for class or interface or any other types that used with generics for their parameters.From definition its hard to understand so lets show a example of generics use.

1
2
3
List<Integer> ints = new ArrayList<Integer>();
ints.add(1);
int n = ints.get(0);

Here as you can see we are creating a list from arraylist(which is a class the implements list interface so assigment is OK) with specified parameters String in angle brackets.With the help of generics it is guaranteed that all the parameters that added to arraylist is String , if you try to add something other that String it is a compile time error.Before java generics its programmer job to guess what is the variable type coming from list and make suitable cast to that object.It is a extra work for programmer.With generics its is now compiler responsibility to check parameters and give compile time error.

You can say it is not different from c++ templates , but actually it does.There is a different implementation of the generics in bot c++ and java side.In C++ if you use generics and create and objects lets say List<String> and List<Integer> and List<List<String>> , C++ made 3 copy of your code for each generic in use.If you use 100 different type of generics there will be 100 different code , this can lead to code bloat.But in java no matter how many differnt generics you use there is only one code for all.C++ model generics called expansion,it can be lead to code bloat but in performance side it is more efficient that Java model.Also if you are using generics with C++ you have to be careful about usage of angle brackets.

Lets look at another code to see how auto boxing and unboxing work with Java.

1
2
3
4
5
public static int sum (List<Integer> ints) {
  int s = 0;
  for (int n : ints) { s += n; }
  return s;
}

In this code sample we again using a list from arraylist as  parameter to sum function with specified Integer generic.(you can say what is the difference between “Integer” and “int” , and why we not using “int” for generics like this “List<int> ints”) Cause type parameters always bound to reference type not primitive types.And also you can ask why we are using “int” insted of “Integer” as return type like “return Integer”? .Because result types may be either primitive or reference types, and it is more efficient to use the former than the latter.Also you can say why for variable(or you can say foreach another new feature of java 6) not “Integer” insted of  “int”.This is actually hold performace issue behind.If you use “Integer” instead of “int” compiler unbox the value of “Integer” every time and perform operation than box the value back for later iteration.This is a big performance loss.

Here how generics doing auto boxing and unboxing.

1
2
3
List<Integer> ints = new ArrayList<Integer>();
ints.add(new Integer(1));
int n = ints.get(0).intValue();

This is the different version of the first code sample at top.This is how it looks when we are using generics in our code.As you can see if we try to add int value to List that expects Integer , it automatically box the value and then add it to the list.On the other hand if we try to get the value out of list , it again automatically unbox the value and assign it .(here we using integer so if we try to box int value it is done with new Integer(x) , and if we try to unbox it you have to call intValue method of the Integer).

For more information about generics you can look at Sun documentation for generics and also for Collections framework of Java.

Written by burakdede

November 17th, 2009 at 4:03 pm

Posted in java

Tagged with , , , , ,

Introduction to Google’s Android Platform

12 comments

As the title says Android is a platform that include operation system,middleware and also application programming interface(api) which is create by Google.It is a solution for developers to create rich mobile applications easily with the power and easiness of Java programming language .Why it is a solution cause mobile systems like symbian and java midlets didnt gave so much flexibility that Android platform gave to developers.

By using Symbian platform you can write applications that access the hardware of the device but it require so much complex c/c++ code.This is kind of tiresome for developers using symbian platform.After symbian platform Java MIDlets have evolved and MIDlets fix the difficult hardware access in mobile platforms by abstracting the underlying hardware platform and giving developers ability to create applications that run on wide variety of platforms that support java run time.Cost of this platform independence is restricted access to hardware.Cause native and third party application doesnt have the same priority.Third party application recieve restricted access to hardware platform.This cant be good for the third party application especially developers who create application for that platform.And

What makes Google Android Different?

Developers can use Java to create applications for the Android platform.This is a big advantage cause Java accepted by developers all over the world and has great support  and most important it is open source like Android platform itself.But what known wrong here that you can not use Java classes directly and write application for the Android platform you have to make your classes and strcutre of your application specific to Android platform.

Antoher difference is that all applications at Android platform whether its a native application or third party they have the same priority.This gives huge flexibility to third party applications , as other platforms do opposite.They gave restricted access to third party application and also restricted resource.

Android platform built on linux kernel and it is a open source platform.You can even write low level code for platform.Also Android is a member of Open Mobile Alliance and Linux Phone Standarts Forum(LiPS).There is  wrong belief that  Android platform is fully open source, well it is not true right now but it is expected to be fully open source.

At this stage, not all of the Android stack has been released as open source, although this is expected to happen by the time phones are released to market. It’s also worth noting that the applications you develop for Android do not have to be open source.

And also your application doesnt have to be open source , you can make money from it, it is a developers choice to make it open source or not.There is a  market that has the same functionality like Apple’s app strore named Android market.You can look at android applications from Android Market.

As a general belief it is not a competitor to Apples İphone.Cause iphone is fully hardware and software platform but Android only offers a general software stack that can run on every hardware platform that meet Android requirements.Unlike Apple’s iphone there is not one Android Mobile Phone.You can check latest Android supported mobile phones here.

Android also has a rich api and great documentation.Also you can download latest SDK from here.What makes Android so attractive is that its open philosophy,you can create or even change applications like you imagine them.

Written by burakdede

October 24th, 2009 at 7:30 pm