Archive for month April, 2009

how to check if given number is prime?

Tuesday, April 28th, 2009

This problem in general is very complicated, but when we don’t need to be 100% sure (but probability is near 1) about our results there is a very easy way to do this.

We’ll use method isProblablePrime from class BigInteger.

This method as a argument gets probability level, it’s calculated as 1 – 1/(2^x), where x is argument, so for x = 20, we can be nearly fully sure about result, the probability is 0,99999904632568359375. For smaller numbers this method gives even more sure results.

How to use it:
long x = some_value;
BigInteger bi = BigInteger.valueOf(x);
boolean isPrime = bi.isProbablePrime();

Firstly we set x to some value, then a new BigInteger is created based on x value, next we use method to check if it’s prime.

more information about BigInteger you’ll find here: http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html

howto install JRE – illustrated guide

Saturday, April 18th, 2009

I have decided to describe installation process of Java Runtime Environment one more time, now I’m adding screenshots so it will be much easier to understand:

  1. Go to http://www.java.com/en/download/
  2. Click blue button, a new page appears:
  3. After loading page, a download process should start automatically, if not click blue button again.
  4. Now, the JRE installator will be downloaded, wait until it’s completed, then run it.
  5. You will see this window:
  6. Again, wait some time, the installer will download another installer, that will install JRE, it will be started automatically:
  7. Click “Accept” and in next stage your JRE will be installed:
  8. After finished installation a new window opens saying that it has successfully installed your JRE, click “Finish”.
  9. You have installed JRE properly :)

adding icon to your MIDlet

Thursday, April 16th, 2009

Hello, this topic is also not very complicated, so the post will be quite short.
We have to remember about some rules before we add icon to a MIDlet:

  • Only PNG’s are allowed
  • icon’s size is not standarized
  • some phones will expand smaller icons, some won’t
  • the icons that are to big might be shrinked or cut to smaller, we can’t decide
  • I recommend using size 32×32, it is smaller than most phones can hold, so at least we can be sure, that it won’t be cut
  • icon files, if we want to reffer to it as: “/icon.png” should be placed in src directory in project’s path I think it’s the best way to do this (this file will be automatically added to newly created JAR file)
  1. After starting Netbeans we go as before to project’s properties, here we open “Application Descriptor” again, then we select second tab:
  2. Now, after choosing “Edit…” we can select file:
  3. Next, we have to add appropriate attribute to our JAD and manifest. Let’s click “Add…”, automatically first to add will be icon attribute:
  4. At last you can run this MIDlet in the emulator (or upload to your mobile). You should see icon you have selected for your app.

converting JARs into JADs using Jadmaker

Sunday, April 5th, 2009

This thing is not very complicated. Of course now we know how those files are created and we can do this automatically, but there is a better way.

  1. To convert file JAR into JAD download program called JADMaker it doesn’t require installation (the best is to unrar it into directory)
  2. Now we run program, and drag JAR file onto the window
  3. In the folder where there was JAR file now we have approperiate JAD
  • You can directly drag & drop JARs onto the JADMaker icon
  • Program allows you to convert multiple files at once, just mark what you need and drag&drop them.
  • Option “Enable Explorer Contex-Menu extension” allows you to convert files from right click context menu: