JAVA as C (or C++) Front End

L

Luc The Perverse

Hello!

Generally I do not like using Java because it is slower than C - and the
majority of my existing code is already written in C.

I am just looking for some general information on using Java/C or Java/C++
combinations.

I generally know nothing about Java programming.

Some questions I would like answered are (some directly Java related, other
Java/C related):

1. How do I get a single executable? Whenever I write and compile a java
program, I have to invoke it by calling Java.EXE. But I have used software
which is obviously written in Java which is invoked with an EXE file. Do I
have to use a seperate C or C++ program which calls Java.exe or is there
some option that hides this?
2. Cross platform installations. Is there some [free] tool which is going
to help me with this, or am I going to set up a
FreeBSD/Linux/Unix/Solaris/Crapintosh/Win 98 box for installation testing
and learn how to write all of them?
3. If I invoke a DLL call from Java, is the JVM going to "manage" the
function or do something else stupid that will significantly make the DLL
function run slower than native code?
4. (Related to previous question) If I write a Java front end, and C back
end, are there any pros and cons to which one invokes the other.
5. Does [free] Java have native functionality for easily playing and
recording multimedia. I intend on making a learn English now program for
spanish speakers, and I will need to allow them to record themselves talking
and playback. I have no desire to implement this under C.

I am going to write some really simple things first, like duplicate file
checker, maze drawing, interactive math quiz.

I have written Java applications before, and I realize that entire apps can
be written in Java alone. I am trying to study and learn C now.

An example would be nice too. I would like to see one where Java displays
a progress bar, and open a thread in a DLL which send messages to update the
progress bar as work gets done.

I am using DevC++ (which is also a C compiler) if that makes any difference.
 
A

Alun Harford

Luc The Perverse said:
Hello!

Generally I do not like using Java because it is slower than C - and the
majority of my existing code is already written in C.
I generally know nothing about Java programming.

Ya, we got that from the first line. :)
Some questions I would like answered are (some directly Java related, other
Java/C related):

1. How do I get a single executable? Whenever I write and compile a java
program, I have to invoke it by calling Java.EXE. But I have used software
which is obviously written in Java which is invoked with an EXE file. Do I
have to use a seperate C or C++ program which calls Java.exe or is there
some option that hides this?

Various tools exist to do this.
3. If I invoke a DLL call from Java, is the JVM going to "manage" the
function or do something else stupid that will significantly make the DLL
function run slower than native code?
Nope.

5. Does [free] Java have native functionality for easily playing and
recording multimedia. I intend on making a learn English now program for
spanish speakers, and I will need to allow them to record themselves talking
and playback. I have no desire to implement this under C.
javax.sound.*


I am going to write some really simple things first, like duplicate file
checker, maze drawing, interactive math quiz.

I have written Java applications before, and I realize that entire apps can
be written in Java alone. I am trying to study and learn C now.

I've coded in C for 8 years. It's horrible, and it's obsolete. (except for
writing an OS kernel).
Why on earth do you want to learn it?

Alun Harford
 
G

Guest

Generally I do not like using Java because it is slower than C - and the
majority of my existing code is already written in C.

I have written Java applications before, and I realize that entire apps
can be written in Java alone. I am trying to study and learn C now.

Which of the above statements is true?

Google jini to find how to have Java interact with other languages.

Java source code compiles into a platform-independent bytecode; you don't
have to recompile (pure) Java classes for each OS and CPU. Using JIT
(just-in-time) technology Java is almost as fast as c++. To compile a
Java application to a native executable you will need a 3rd party product.

HTH,
Laie Techie
 
C

Chris Uppal

Luc said:
1. How do I get a single executable? Whenever I write and compile a
java program, I have to invoke it by calling Java.EXE. But I have used
software which is obviously written in Java which is invoked with an EXE
file. Do I have to use a seperate C or C++ program which calls Java.exe
or is there some option that hides this?
4. [...] If I write a Java front end, and C
back end, are there any pros and cons to which one invokes the other.

One 'pro' for having the the C code invoke the java code is that you will then
"naturally" have an apparently standalone .exe (on Windows, similar on Unix-ish
OSes). You will still be dependent on there being a full installation of the
JRE available, however. The corresponding 'con' is that you will then have to
write versions of the invoking code for Windows and Unix-ish OSes.

There are other was of getting a single executable. Some are merely
pre-packaged equivalents to the above, others -- such as Excelsior JET -- are
genuine compilers.

-- chris
 
A

Andrew Thompson

Chris said:
There are other was of getting a single executable.

Since JWS can make dll's available to Java apps., I
recommend using Webstart for the deployment.

It adds 'auto-update' as a feature over many installer
alternatives, and it is very easy for the end user.

I have not tried it, but I cannot foresee any great
difficulties in having a JWS'd Java app., call a C/C++
app. using JNI.

Just a thought..
 
C

Chris Uppal

Andrew said:
It adds 'auto-update' as a feature over many installer
alternatives, and it is very easy for the end user.

One of my favorite features is that when an explotable security hole is
discovered in JWS (as -- I think -- has happened at least twice), and Sun
release a new version to fix it, it is possible for the malicious script to
tell JWS that it needs an earlier version to run, so JWS will obligingly
download the vulnerable version to run the malicious code...

Or at least that's how it was described on BUGTRAQ, I haven't attempted to
verify it myself, and I imagine that Sun have fixed that particular error by
now anyway. But it did make me laugh (rather a lot).

-- chris
 
R

Roedy Green

1. How do I get a single executable? Whenever I write and compile a java
program, I have to invoke it by calling Java.EXE. But I have used software
which is obviously written in Java which is invoked with an EXE file. Do I
have to use a seperate C or C++ program which calls Java.exe or is there
some option that hides this?

There are several ways. See
http://mindprod.com/jgloss/nativecompiler.html
 
R

Roedy Green

Generally I do not like using Java because it is slower than C.
I generally know nothing about Java programming.

Those two statements are contradictory. If you don't yet know how to
code in Java, the problem may be your lack of knowledge rather than a
defect in the language. Once you natively compile, you won't notice
much difference.
 
R

Roedy Green

2. Cross platform installations. Is there some [free] tool which is going
to help me with this, or am I going to set up a
FreeBSD/Linux/Unix/Solaris/Crapintosh/Win 98 box for installation testing
and learn how to write all of them?

No. That is the whole point of java. You distribute one class file for
all platforms.
 
R

Roedy Green

4. (Related to previous question) If I write a Java front end, and C back
end, are there any pros and cons to which one invokes the other.

Java calling C is easier. You can also communicate via sockets,
databases, files, ...
 
R

Roedy Green

An example would be nice too. I would like to see one where Java displays
a progress bar, and open a thread in a DLL which send messages to update the
progress bar as work gets done.

It would, but after you have spit in the face of Java users from a
position of extreme ignorance, your are lucky to get as much help as I
gave you.
 
H

HalcyonWild

Luc said:
Hello!


1. How do I get a single executable? Whenever I write and compile a java
program, I have to invoke it by calling Java.EXE. But I have used software
which is obviously written in Java which is invoked with an EXE file. Do I
have to use a seperate C or C++ program which calls Java.exe or is there
some option that hides this?

Code in Java, and call java.exe from a shell script, if you are ok with
it.
3. If I invoke a DLL call from Java, is the JVM going to "manage" the
function or do something else stupid that will significantly make the DLL
function run slower than native code?
4. (Related to previous question) If I write a Java front end, and C back
end, are there any pros and cons to which one invokes the other.
5. Does [free] Java have native functionality for easily playing and
recording multimedia. I intend on making a learn English now program for
spanish speakers, and I will need to allow them to record themselves talking
and playback. I have no desire to implement this under C.

JNI might help, though it really isnt simple. Prefer to pass simple
datatypes rather than complex classes between java and c/c++.

Java isnt as slow as you think, if you program intelligently. Will a
few microseconds make much of a difference, on a P4 machine with loads
of RAM. Normally you "notice" the difference on server applications,
where there might be multiple users submitting requests, and multiple
Database calls, network traffic, etc.

And when looking for advise, dont show any superiority. Try showing
down linux on a linux newsgroup, and you will be in the line of deadly
fire.
 
A

Andrew Thompson

Chris Uppal wrote:

(snip)
[ cannot say I'd ever heard of the security problem
re JWS ]
..But it did make me laugh (rather a lot).

<wrily>
Sun does some funny things.
</wrily>
 
C

Chris Uppal

Andrew said:
(snip)
[ cannot say I'd ever heard of the security problem
re JWS ]

The one I was thinking of was (selecting a BUGTRACK archive almost at random):
http://marc.theaimsgroup.com/?l=bugtraq&m=111117420632213
and also see:
http://marc.theaimsgroup.com/?l=bugtraq&m=111160970209222


BTW, there's a newer one, fixed in JDK 1.5.0_2.

http://sunsolve.sun.com/search/document.do?assetkey=1-26-101748-1

No details the error are given -- which I take (uncharitably) to mean that it
is particularly ludicrous ;-)

-- chris
 
L

Luc The Perverse

I don't think its obsolete. I think it is an excellent learning
language. It is too easy to be spoiled by OOP, and then never really
learn how functions/data/objects interact. I also like that you can
do inline assembly language if you want to streamline a routine.
 
L

Luc The Perverse

I'm sorry, I'm not really seeing the contradiction. I have made
simple programs in Java before but all the large programs I have
written have all been in C++. I'm trying to take a step back from OOP
so that I can remember what I'm doing, instead of defining class
functions like I have learned to do like a robot. That's what I'm
using C for. At the same time I would like to make something
worthwhile. I have identified that C is a stupid language to try to
inplement a GUI in - that is where Java comes in.
 
L

Luc The Perverse

If I write a Java program, I will expect it to be run by the JVM - that
does not bother me.

But to appeal to users who have never even heard of a command line, I
am going to need some form of system integration. In the case of
windows for instance, I will likely need a start
menu/desktop/quicklaunch icon - some programs call for right click
functionality of files.
 
L

Luc The Perverse

If and when I do begin to sell software that I am writing, I realize I
will need a way to update the user software, in the form of patches
etc. If I choose not to make my software public domain (which is
unlikely) I will also need to look into some liscensing. A cross
platform product which could do this on most versions of
windows/linux/macintosh with all the normal nifty features, like auto
run set up already would be exceptionally useful. I will look into
this further probably on another day
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top