Need to recompile a Java Applet as an Executable

S

Sanny

I have a Java Applet which is quite slow.

There are a few functions that are called by the Java Applet. I want
those functions to be run as fast as possible.

One Option is to use Native Support.

Does an Applet support native language?

Can I create a C++ / C function and ask the applet to call that C
function that is run on Users Computer? And get back the output and
display on the Applet?

I just want a few functions to use fast C/ C++ access?

How to distribute my applet with C/ C++ dll/ That Applet accesses?

I will have 2 versions of Applet. One the slow version the other the
fast version.

I want that users who are not satisfied with the slow version. They
will need to use the Signed Applet. Once they allow the Signed applet
to access the Computer. The applet will load the C/ C++ dll / ActiveX
on the Computer / Webpage.

I want communication between Activex and the Applet for quick
computation.

Will the Activex/ DLL be 10-20 times faster than an Applet?

So for power users who are looking for better performance I allow them
to use the C/ C++ version.

Will this model work?

Will I have to create different ddl/ ActiveX for different platforms?

Say for Mac os/ Linux/ Windows etc? Do I need to create a different
ActiveX?

I just have a few functions in C/ C++ and the Applets sends the
parameters and returns the output.

Which C/C++ free package should I use to create this function. I just
want a few functions to be executed quickly by native language and
return the output to the applet. So I want a free editor where I can
compile the C/ C++ functions.

Second Question Will an Activex/ DLL on a webpage be as fast as any
executable? I am looking for the fastest options.

Please suggest me a good example or diagram of how to proceed. Will I
need Corba/ XML feature for Applet & Activex communication? Will this
setup work on all web browsers?

Does flash works faster than Java? Can I use those functions in Flash.
Wil a function run on Flash as fast as a Native Language?

Bye
Sanny

Good opportunities for Java/ C/ C++ Experts:

http://www.getclub.com/Experts.php

Tell your Expertise and projects.
 
N

Nick Keighley

I have a Java Applet which is quite slow.

There are a few functions that are called by the Java Applet. I want
those functions to be run as fast as possible.

One Option is to use Native Support.

Does an Applet support native language?

Can I create a C++ / C function and ask the applet to call that C
function that is run on Users Computer? And get back the output and
display on the Applet?

this isn't on topic on comp.lang.c how C or C++ "links" with java is
outside the scope of the C or C++ language.

<snip>
 
F

Flash Gordon

Sanny wrote:

Say for Mac os/ Linux/ Windows etc? Do I need to create a different
ActiveX?

This is about the nearest thing to a C question, and even this is not a
C question...

Of course any compiled C code would have to be compiled for the specific
target it is running on...

Does flash works faster than Java? Can I use those functions in Flash.
Wil a function run on Flash as fast as a Native Language?

You probably need to ask in a web authoring group/forum, since your
problems are all heavily to do with a web site. However, I would
recommend from my experience that you would be better off looking at a
higher level, ensuring that only what is needed is being downloaded etc.
I've seen sites where as much as 90% of what was downloaded was not
actually needed by the client! How to do this is all about web
authoring, and not Java (which is NOT Javascript) or C.
 
S

Sanny

Sanny said:
You should probably fix your Java code then.  It's rare for Java
performance to be so critical that you need to go outside of Java.  And
you almost certainly won't get the 10x or 20x speedup you seem to be
hoping for.

There is nothing wrong with the java code. I know some expressions in
C are working 10-20 times faster. Secondly "C" allows the use of
pointers and Assembly language programming.

Also I can configure Compilation in "C" such that it do not do error
checking at runtime speeding it up further.

My program does a lot of array sorting and array search and
comparisions. That is quite faster in C. Also lot of String Operation
is done.

In Java String Operations are 100 times slower than in "C". As copying
a string takes lots of time in Java.
You can easily make things slower, if you do that wrong.  And it won't
necessarily be faster in any case.  IMHO JNI is more appropriate for
when you need some specific functionality that's simply not available in
Java, or you need to reuse some code that would be impractical to port
to Java.

No doubt there are some specific, very specialized applications in which
writing some custom native code and calling it via JNI is helpful.  But
statistically speaking, it's not likely your program is in that category.


One more reasion to use "C" is to have my code encrypted. Java Code is
available to all so others can easily hack the java code. While
cracking an Activex is I suppose impossible.
Unfortunately, I don't know much about applets.  But due to security
concerns, I would expect applets to have much more restricted access to
JNI than regular Java applications.

I have full understanding of these. Only problem is how Browser
accepts the Activex and Applet.

Will a firefox browser run an ActiveX on Non Windows OS?

But, I suspect you don't really need to use JNI.
[...]
Will I have to create different ddl/ ActiveX for different platforms?
Say for Mac os/ Linux/ Windows etc? Do I need to create a different
ActiveX?

ActiveX is Windows-only.  Each platform has its own library format and
supported CPUs.  If you want a platform-specific solution, just write
the whole thing as native code.

OK, I can ask the users to purchase Windows operating System if they
want faster version. Thats not a big problem. I suppose 80-90% will
already have a windows version.

If you want cross-platform support, write the whole thing in Java,
figure out why your program is so slow, and fix it using only Java.

Its not Slow exactly. But I want it to be more fast. As C/ C++
routines are much faster as I can use Assembly language programming.

Bye
Sanny

Good opportunities for Java/ C/ C++ Experts:

http://www.getclub.com/Experts.php

Tell your Expertise and projects.
 
J

Joshua Cranmer

There is nothing wrong with the java code. I know some expressions in
C are working 10-20 times faster. Secondly "C" allows the use of
pointers and Assembly language programming.

That's not always a good thing. said:
One more reasion to use "C" is to have my code encrypted. Java Code is
available to all so others can easily hack the java code. While
cracking an Activex is I suppose impossible.

*Laughs heartily*
Two words: IDA Pro.
Native code is not immune to being cracked. Indeed, with modern tools
(both Java obfuscators and native disassemblers), it is generally as
easy as Java to crack in many cases. C has the unfortunate problem of
being a wonderful language to target for decompilers.
I have full understanding of these. Only problem is how Browser
accepts the Activex and Applet.

Will a firefox browser run an ActiveX on Non Windows OS?

No. Firefox doesn't support ActiveX period. Well, at one time there was
a framework to embed Gecko in ActiveX, but that stopped working several
years ago IIRC.

Even IE is shying away from ActiveX IIRC.
Its not Slow exactly. But I want it to be more fast. As C/ C++
routines are much faster as I can use Assembly language programming.

It sounds like you're not even trying to optimize in Java, just claiming
that it will be faster since you can use assembly, that unmaintainable
little bugger.
 
B

BGB / cr88192

Antoninus Twink said:
Utter nonsense.

usual answer by the regulars would be something like "the C standard makes
no mention of JNI or JVMTI, or JNA, ..., and hence these features are
outside the scope of C" (much like is the position WRT: threads, POSIX,
OpenGL, ...).

granted, to accomplish much of anything useful in C, one generally has to go
outside the narrow bounds that are "the standard".


granted, this is not exactly the issue as with the original post.
anyways, assuming that the browser is not using a poor JVM implementation (a
plain interpreter or similar), Java vs C performance is not likely to be
significant enough to bother worrying about in this case, and one is instead
better off concerning themselves with writing efficient code (any language
will be slow if the programmer doesn't know what they are doing, and usually
the language/compiler is the first thing to be blamed for the poor
performance of badly written SW).

actually, it is worse with non-prgrammers, who are more naturally inclined
to either blame the computer or imagine that the task itself is just too
complicated, rather than consider that it may be instead that the app is
just poorly written...


as far as Java vs Flash:
actually, Flash is likely to be much slower than Java (or at least, for any
tasks where non-trivial code is needed, Flash may be a better choice when
much of the basic functionality is already built into the Flash backend,
such as for 2D/3D animations or video players...).

or such...
 
A

Antoninus Twink

anyways, assuming that the browser is not using a poor JVM
implementation (a plain interpreter or similar), Java vs C performance
is not likely to be significant enough to bother worrying about in
this case, and one is instead better off concerning themselves with
writing efficient code (any language will be slow if the programmer
doesn't know what they are doing, and usually the language/compiler is
the first thing to be blamed for the poor performance of badly written
SW).

To be honest, whatever stories people come up with about how good their
JIT compiler is at optimizing on the fly and such like, the truth is
that for many applications, rewriting the bottleneck in C will gain you
an order of magnitude.

I believe the principal two reasons for this are:

1) No overhead in basic data types. AIUI, Java will take many bytes to
store a simple int, just because of all the OO book-keeping that needs
to accompany every single object. Therefore, smaller slices of every
array can fit in cache ---> performance death.

2) Java hides what's going on under the hood from the programmer. This
abstraction is great for reducing coding time, but it means people
unwittingly do things that cause lots of temporary variables to be
created (which might themselves depend on constructing half a dozen base
classes), or they keep generating lots of junk on the heap instead of
making one allocation and recycling it themselves, so that GC becomes a
killer.

In Java (and C++ for that matter), the possible expansion factor of a
single source line into assembly instructions is essentially unlimited,
whereas with C you generally see what you're getting.
 
B

BGB / cr88192

Tim Streater said:
Does this include C# or whatever is was that Baldrick was claiming was
only 10% slower than C?

I'll be damned.

one can also force the C into being compiled as C++/CLI and see what
happens...


I did this recently for a test...

actually, for the simple tool I converted, about the only real noticable
differences was that the C++/CLI version took around maybe 100-250 ms longer
to get up-and-going (I suspect this being due to the initial JIT overhead or
similar).

admittedly, I was not using a performance-sensitive tool, rather this was
just a misc observation while looking into C++/CLI (as a possible way to
eventually interface C and C# codebases...).


note that personally, I am primarily a C developer...
 
L

Lew

Antoninus said:
To be honest, whatever stories people come up with about how good their
JIT compiler is at optimizing on the fly and such like, the truth is
that for many applications, rewriting the bottleneck in C will gain you
an order of magnitude.

And for many, many, many more, it won't. It can most definitely lose you an
order of magnitude, also.

Java performance in some cases is superior to equivalent C code.

In others, it isn't.

On average, most CPU-bound stuff seems to be about 50-90% as fast as C code,
but the difference is much smaller if memory allocation/deallocation are
involved, or if HotSpot converts the code to native code, in which case one
can often find the Java code to be faster.

As always, predictions in any particular scenario are useless. Measurement
will tell.
I believe the principal two reasons for this are:

1) No overhead in basic data types. AIUI, Java will take many bytes to
store a simple int, just because of all the OO book-keeping that needs

Java takes four bytes to store a simple int.
to accompany every single object. Therefore, smaller slices of every
array can fit in cache ---> performance death.

An 'int' in Java is not an object. Some think of this as a flaw.
2) Java hides what's going on under the hood from the programmer. This
abstraction is great for reducing coding time, but it means people
unwittingly do things that cause lots of temporary variables to be
created (which might themselves depend on constructing half a dozen base
classes), or they keep generating lots of junk on the heap instead of
making one allocation and recycling it themselves, so that GC becomes a
killer.

Maybe, but you state this as if it were a sure thing, which is far from the
truth. If GC were to be a "killer", as you cutely put it, that would be
because you are allocating lots of objects. If you are allocating lots of
objects in C or C++, then memory management will be a "killer" there, too.
The difference is that the C/C++ code will require much more code to do the
trick, it'll actually take longer to manage its memory than the Java program,
and the risk of wild pointers or memory leaks is much, much higher.

It doesn't do any good to get a bug to crash your C program in half the time
it takes a Java program to run correctly.

Are you a Java programmer? Because you don't sound like it.
In Java (and C++ for that matter), the possible expansion factor of a
single source line into assembly instructions is essentially unlimited,
whereas with C you generally see what you're getting.

B.S.
 
L

Lew

Thomas said:
On all other instances I have come across, the speedup offered by C over
Java on pure computational, fit-in-L1-cache-and-no-IO work, is typically
between 2x and 3x (3x for array-intensive work, because of array length
checks upon access), never above 4x.

In "-server" mode, the HotSpot compiler will often eliminate array bounds checks.
 
A

Arne Vajhøj

I have a Java Applet which is quite slow.

There are a few functions that are called by the Java Applet. I want
those functions to be run as fast as possible.

Using applets for CPU intensive work is not an obvious choice.
Does an Applet support native language?

Can I create a C++ / C function and ask the applet to call that C
function that is run on Users Computer? And get back the output and
display on the Applet?

You can certainly call C code from Java using JNI.
How to distribute my applet with C/ C++ dll/ That Applet accesses?

If I remember correctly then applet and JNI requires the native
dynamic library (.dll, .so or whatever it is called on the specific
platform) to already be on the client.

Java Web Start may be different.
I want that users who are not satisfied with the slow version. They
will need to use the Signed Applet. Once they allow the Signed applet
to access the Computer. The applet will load the C/ C++ dll / ActiveX
on the Computer / Webpage.

I want communication between Activex and the Applet for quick
computation.

Why an ActiveX plugin?

Communication between an ActiveX plugin and an applet sounds
both cumbersome and slow.
Will the Activex/ DLL be 10-20 times faster than an Applet?

Most likely not.

You chances of winning in powerball is probably better.
Will I have to create different ddl/ ActiveX for different platforms?

Different JNI native dynamic library for every platform you want
to support.

ActiveX is Windows only.
Say for Mac os/ Linux/ Windows etc? Do I need to create a different
ActiveX?

Does not exist.
Which C/C++ free package should I use to create this function. I just
want a few functions to be executed quickly by native language and
return the output to the applet. So I want a free editor where I can
compile the C/ C++ functions.

To use JNI you just need Java and any C/C++ compiler for the platforms
you intend to suppport.

For ActiveX you should go for some combination of Visual C++
and Platform SDK.
Please suggest me a good example or diagram of how to proceed. Will I
need Corba/ XML feature for Applet& Activex communication?

I can not see any reason to also throw CORBA and XML into the mix.

Using any technology under the sun will not make your app faster.
Will this
setup work on all web browsers?

ActiveX will only work with IE.

JNI should work for all browsers on the platforms you create it for.
Does flash works faster than Java? Can I use those functions in Flash.
Wil a function run on Flash as fast as a Native Language?

I am far from a Flash expert.

But CPU intensive calculations does not seem to be something
Flash is used for (excluding video related calculations !), so
I very much doubt that Flash is optimized for such.

Arne
 
A

Arne Vajhøj

There is nothing wrong with the java code. I know some expressions in
C are working 10-20 times faster.

If you expect x10-20, then there is definitely something wrong with
your Java skills and therefore most likely something wrong with
your Java code as well.
Also I can configure Compilation in "C" such that it do not do error
checking at runtime speeding it up further.

That sounds more like Ada than like C.
My program does a lot of array sorting and array search and
comparisions. That is quite faster in C. Also lot of String Operation
is done.

In Java String Operations are 100 times slower than in "C". As copying
a string takes lots of time in Java.

Array work can be faster in C than in Java.

String operations are typical slower in C than in Java.

So you are basing your design on some very bad assumptions.
One more reasion to use "C" is to have my code encrypted. Java Code is
available to all so others can easily hack the java code. While
cracking an Activex is I suppose impossible.

You can obfuscate the Java code, but even obfuscated Java byte code
is a lot easier to reverse engineer than native executable.

So it is definitely a valid argument for native code.

But given your level of Java skills, then I don't think
there is any risk for you.
I have full understanding of these. Only problem is how Browser
accepts the Activex and Applet.

Will a firefox browser run an ActiveX on Non Windows OS?

No.

And not on Windows either.

Arne
 
A

Arne Vajhøj

To be honest, whatever stories people come up with about how good their
JIT compiler is at optimizing on the fly and such like, the truth is
that for many applications, rewriting the bottleneck in C will gain you
an order of magnitude.

I believe the principal two reasons for this are:

1) No overhead in basic data types. AIUI, Java will take many bytes to
store a simple int, just because of all the OO book-keeping that needs
to accompany every single object. Therefore, smaller slices of every
array can fit in cache ---> performance death.

I think we can stop reading here.

Anyone that has read "Java for absolute beginners" know that
int's in Java are not objects and use the exact same number
of bytes as C (on platforms where C int is 4 byte).

If you don't like Java, then by all means avoid coding in it,
reading about it or even think about it.

But why post to usenet about something you have not studied????

Arne
 
A

Arne Vajhøj

Perhaps .Net has improved in recent years, then. When I tried this,
about six or seven years ago (with the original intent of putting the
program into production), it was 50-60 times slower than C (admittedly
for a heavily recursive application).

That is not in any way typical.

It is completely off the scale for unlikelihood.

But if I remember correct from last time you gave
the story, then you can not explain exactly what the
code did.

So we can not explain why it was so.

We can just tell you that it is not what you usually see.

Arne
 
K

Keith Thompson

Arne Vajhøj said:
Anyone that has read "Java for absolute beginners" know that
int's in Java are not objects and use the exact same number
of bytes as C (on platforms where C int is 4 byte).
[...]

Since this is cross-posted to comp.lang.java.programmer and
comp.lang.c, let me clarify that point.

C defines an "object" as a "region of data storage in the execution
environment, the contents of which can represent values". This has
nothing to do with object-oriented programming. Thus a declared
variable of type int certain is an "object" if you use the C
definition of the term. (Note that C++ uses a very similar
definition.)

I don't know how "Java" defines the term.
 
L

Lew

Keith said:
Arne Vajhøj said:
Anyone that has read "Java for absolute beginners" know that
int's in Java are not objects and use the exact same number
of bytes as C (on platforms where C int is 4 byte).
[...]

Since this is cross-posted to comp.lang.java.programmer and
comp.lang.c, let me clarify that point.

C defines an "object" as a "region of data storage in the execution
environment, the contents of which can represent values". This has
nothing to do with object-oriented programming. Thus a declared
variable of type int certain is an "object" if you use the C
definition of the term. (Note that C++ uses a very similar
definition.)

I don't know how "Java" defines the term.

That may be, but the context to which Arne replied and that you excised
claimed that Java has tons of memory overhead to represent an 'int' by virtue
of being an object, which is a bloody falsehood. Clearly that poster was
using "object" in the current conventional computer-programming sense of the
word, and not in your more specialized frame.

FYI, and it absolutely freaking *ASTOUNDS* me that anyone presuming to call
themselves a programmer today has not gotten familiar with object-oriented
programming at least enough to know what an object is, I mean, come on,
already! - an object in Java is exactly what it is in any object-oriented
programming environment. Roughly it's a struct with built-in functions.

You really should expand your study. Start with the Wikipedia definition,
perhaps read Grady Booch. Being a C programmer is not a good excuse. In
fact, it's no excuse at all.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top