Tuesday, January 20, 2009

Shahabinary Alpha 0.002


Shahabinary English to Norwegian dictionary :

Shahabinary is a OS free, freeware PC application which is at least runable on Linux & Windows (TESTED). The code is not open source this time (like Shahabinary 0.001) but I will post the source code in near future. Due to some technical difficulties with GUI, the word recognition ability has been disabled but will be functional again in version 0.003. This version enjoys a better GUI and much more comfortable design with significant changes in the code which makes it smaller and easier to compile. The only thing you need to do for running is to unzip the folder and double click on Shahabinary v. 0.0002.jar.

Again I repeat the words and database are not trustable and this is just an exercise in my learning progress. This project the focus is mostly on the technical part and not the dictionary parts of the application.

Click here
to download the latest Shahabinary ...

Enjoy ...

Thursday, January 08, 2009

How to run an exe file from java

If you want something which you do not need to read much about it but it is old :

Runtime.getRuntime().exec( "myprog.exe" );

will spawn an external process (usually a program written in some language other than Java) that runs in parallel with the Java execution. In W95/W98/Me/NT/W2K/XP/W2K3, you must use an explicit *.exe or *.com extension on the parameter. In Vista it will still work even if you leave it off. Be careful to include it, or your code will mysteriously fail on the older operating systems.

It is also best to fully qualify executable names so that the system executable search path is irrelevant, and so you don’t pick up some stray program off the path with the same name.


ATTENTION : Starting with JDK 1.5, exec has been replaced by ProcessBuilder. start. You should likely not be using exec for new programs. However, studying exec is useful to understand old programs that use exec and to understand why ProcessBuilder is designed the way it is. They have many things in common, especially the way command interpreters and internal commands must be handled, and they both use the same Process class. So read about exec first, then enjoy the improved ProcessBuilder.

example :

/ using ProcessBuilder to spawn an process
ProcessBuilder pb = new ProcessBuilder( "dolunch.exe", "firstarg", "secondarg" );

Map env = pb.environment();

// insert set FRUIT=strawberry into environment just for our children
env.put( "FRUIT", "strawberry" );

// remove set LIVERCOURSE=YES from environment just for our children
env.remove( "LIVERCOURSE" );

// modify set WINE=pinot to WINE=pinot blanc
env.put( "WINE", env.get("WINE") + " blanc" );

// set up the working directory.
// Note the method is called "directory" not "setDirectory"
pb.directory( new File( "/lunchDir" ) );

// merge child's error and normal output streams.
// Note it is not called setRedirectErrorStream.
pb.redirectErrorStream( true );

Process p = pb.start();
// From here on it, it behaves just like exec, since you have the
// exact same Process object.
// ...

// You can reuse the ProcessBuilder objects.
// They retain their initialisation.
Process sister = pb.Start();


reqading txt files with UTF8 formats

Well this code helped me reading Persian language characters from a text files.

java.io.FileInputStream fis=new java.io.FileInputStream(
"File Path");
java.io.InputStreamReader isr=new java.io.InputStreamReader(
fis, "UTF8");
java.io.BufferedReader fin=
new java.io.BufferedReader(isr);
String line;
}//end of while

How do I right-align a JTextField?

short answer : add this code to the constructor ...

Tuesday, January 06, 2009

Finally Shahabinary Alpha 0.001 is ready :-)

Finally after a long delay because of my exams the Shahabinary dictionary alpha version 0.001 probably full of non discovered bugs with very little amount of words is ready to download for coders. This dictionary is coded in Java and is a open source free Norwegian to English dictionary. I hope this is my first step toward the next better versions of this dictionary specially from Norwegian to Persian and the other way.

Click HERE to download.

Wish me luck and enjoy...


How to make an iterator for a Hashmap in Java

Iterate through the values of Java HashMap example :

  1. /*
  2. Iterate through the values of Java HashMap example
  3. This Java Example shows how to iterate through the values contained in the
  4. HashMap object.
  5. */
  6. import java.util.Collection;
  7. import java.util.HashMap;
  8. import java.util.Iterator;
  9. public class IterateValuesOfHashMapExample {
  10. public static void main(String[] args) {
  11. //create HashMap object
  12. HashMap hMap = new HashMap();
  13. //add key value pairs to HashMap
  14. hMap.put("1","One");
  15. hMap.put("2","Two");
  16. hMap.put("3","Three");
  17. /*
  18. get Collection of values contained in HashMap using
  19. Collection values() method of HashMap class
  20. */
  21. Collection c = hMap.values();
  22. //obtain an Iterator for Collection
  23. Iterator itr = c.iterator();
  24. //iterate through HashMap values iterator
  25. while(itr.hasNext())
  26. System.out.println(itr.next());
  27. }
  28. }
  29. /*
  30. Output would be
  31. Three
  32. Two
  33. One
  34. */