PICkit2 - Tutorials, Experiments
PICkit 2 - Small size USB programmer
from Microchip.
How to use it as a demo device for
USB programming in C language
Java SE SWING JSR-296 Example
How to run background task in
JSR-296 SWING application
with 'busy animation' in the status bar.
Useful addition to Netbeans template.
Computer vision
Vision is the main sense of our robots.
See some Java algorithms we use
Tips-n-Tricks
Some advices about hardware and software tricks
PIC Programming
(firmware)
Assembler program for PIC16F628A
Communication program for sending
commands from cell phone to motors.
Driver for motor controller.
RoboHobbyPlugin
Open Source project on
SourceForge, Java brain
for the robot
In German
Short description of www.RoboHobby.com
in German
In French
Short description of www.RoboHobby.com
in French
In Spanish
Short description of www.RoboHobby.com
in Spanish
In Italian
Short description of www.RoboHobby.com
in Italian
In Russian
Short description of www.RoboHobby.com
in Russian
www.RoboHobby.com
How to compile Java application to native code,
for example to Windows EXE file
For some type of Java applications it is important to compile Java right to EXE
(or Linux binary) executable file.
It is important for example for shareware programs,
where you should try to cover your source code.
As you may know, it is easy to de-compile Java classes back to Java source code
and see technological details of your program.
Also JRE size is one more problem.
This short article will describe the ways how to convert Java binary, how to make EXE file
and highlight problems, which you can find ob this way.
In general it is not too easy to do such a compilation.
Originally SUN idea was something like "Compile once, run everywhere".
SUN's Java compiler creates files "*.class" - files in special pi-code,
which are ready to be run in JVM (Java Virtual Machine).
JVM in fact is a special computer program, something like
"special player for Java programs".
Even now it is impossible to run Java programs on a computer, where JVM is not installed.
SUN JDK is not able to compile Java source to native code.
User should have JRE (Java Runtime Environment) installed on his/her
PC to be able to run Java application.
But JRE is not too small in size. Current version is about 18-20Mb.
Is it possible to convert Java to EXE and run this EXE file without any JRE installed?
To make such a compilation you can use commercial Java compilers.
But the price is an issue.
Usually they are too expensive - from several hundreds to tens of thousands of US dollars.
We will not discuss this way of compilation in this article,
rather we will be concentrated in free alternatives.
GCC/GCJ for Java to native code conversion
One of the most popular free compiler GCC is able to compile Java.
And it can do compilation right to native code.
To be able to create EXE file from Java under Windows we should use
Windows version of this free compiler MingW/GCC.
Many thanks to Mohan Embar. His GCC/GCJ bundles for MS Windows you can find on the URL:
http://www.thisiscool.com/gcc_mingw.htm
Recently I downloaded last bundle and installed it on my PC.
What is good in this kind of Java-to-native code solution?
1) It is free. GCC, which is originally came from Unix/Linux World was moved to
Windows World and it still free there.
2) You can mix Java and C/C++ in a special gcc way. You can use not only JNI,
the standard way how to combine C/C++ and Java, but also use gcc-specific way CNI.
3) You can use a lot of Unix/Linux C/C++ code in your applications, mixing them with Java code.
4) GCC/GCJ works with SWT Java GUI Library from IBM.
SWT is pretty good user interface library and you can pre-compile it to your Java program,
using GCC/GCJ compiler.
What is bad with the GCC/GCJ solution?
1) It comes not from the SUN and a s a result is it always behind current version of the
SUN's Java.
When you start to work with GCC/GCJ, very soon you will see the difference -
not all the things are implemented or even if they implemented,
they work different way.
For example you can easy find, that there is no JDBC there.
Also SWING doesn't work there.
Even if it is declared that SWING is supported, in fact it doesn't work.
At least I couldn't make it works
(It is only my personal experience - SWING doesn't work there).
2) Size of the resulting files. When I started to use GCC/GCJ for Windows,
I found the even first "Hello World" was compiled to 2Mb file.
I had an idea to use GCC/GCJ for shareware programming and the size is very important factor.
The less your file, the more people will download the program.
When several years ago I did experiments with this compiler I was surprised.
2Mb was surprising value, because, for example,
MS VC++ compile for "Hello World" produced the EXE file of 300K in size.
And now I downloaded some newer versions from the Mohan's Embar web page.
Now you can see the results of very simple experiment.
I've just compiled "Hello World" example in several versions of GCC/GCJ.
The result was even more surprising.
See the tests results for several versions of GCC/GCJ:
GCC/GCJ 3.4 "Hello World" EXE file size is 2.898 Mb
GCC/GCJ 4.0 "Hello World" EXE file size is 8.884 Mb
GCC/GCJ 4.3 "Hello World" EXE file size is 38.7 Mb
Yes, we should keep in mind, that in some versions of bundles are configured to
pre-compile some libs right to the EXE, some not.
But even if we remember about this factor, we still see the tendency...
May be in the modern World, where people use xDSL connection it is not so important
which size of the file you are loading?
May be...
But if one resulting EXE file is about 40Mb, may be better to download and install
'normal' Java from SUN?
Modern SUN's JRE is just 18-20Mb.
Plus your own application. If it not too complicated, it may be not more then 1-2Mb...