Does Javac converts class into .h files

Discussion in 'Java' started by Sanny, Dec 11, 2006.

  1. Sanny

    Sanny Guest

    What does Javac does to a Java Class? I heard it generates .h files

    Does it convert Java Program into a C Program Any help will be
    expected. I am considering converting a Java Program into C Program to
    increase its efficiency.

    Bye
    Sanny
    Sanny, Dec 11, 2006
    #1
    1. Advertising

  2. Sanny

    Daniel Dyer Guest

    On Mon, 11 Dec 2006 10:45:40 -0000, Sanny <> wrote:

    > What does Javac does to a Java Class? I heard it generates .h files


    Javac is the standard Java compiler. It converts source files (.java)
    into class files (.class). Are you confusing it with javah, which
    generates C header files for classes with native methods?

    Dan.

    --
    Daniel Dyer
    http://www.dandyer.co.uk
    Daniel Dyer, Dec 11, 2006
    #2
    1. Advertising

  3. Sanny wrote:
    > What does Javac does to a Java Class? I heard it generates .h files


    You have now started three separate threads based
    around converting your Java into ..an exe or C++
    or whatever, based on the misunderstanding that it will
    become faster.

    Thus far, you have resisted my attempts to further
    analyse your applet so I might make recommendations.

    Basically - I am not convinced that
    - writing this applet in any other language
    will (necessarily) make it run faster.
    - the applet code is as fast as it might be.

    Perhaps you should be investigating why the code
    is so 'slow', before rushing off to other langauges
    or launch methods.

    So I repeat - what is an URL for the applet?

    Andrew T.
    Andrew Thompson, Dec 11, 2006
    #3
  4. Sanny wrote:

    > What does Javac does to a Java Class? I heard it generates .h files
    >
    > Does it convert Java Program into a C Program Any help will be
    > expected.

    It seems you are intermixing several different things:
    (1) The java-compiler javac (not javah) produces a Java class file (*.class)
    from java source file (*.java)
    (2) javah produces a C header file (*.h) from a from Java class file.
    It does not generate any executable C code. It generates only C
    declarations, which will be the interface between Java code (in *.class
    file, generated by the javac compiler) and C code (in *.c files, to be
    hand-written by you).

    > I am considering converting a Java Program into C Program to
    > increase its efficiency.
    >
    > Bye
    > Sanny


    --
    Thomas
    Thomas Fritsch, Dec 11, 2006
    #4
  5. Andrew Thompson wrote:
    > Sanny wrote:
    > > What does ...

    ....
    > So I repeat - what is an URL for the applet?


    E.G. is this the mess you are referring to?
    <LOUD sounds warning>
    http://www.getclub.com/Chess.html
    </LOUD sounds warning>

    That is one horrendously broken piece of (D)HTML.

    The page seems to be doing continual (and very
    irritating) fetches. The entire page needs to be
    validated, and the scripts externalised and debugged.

    The class file is not in a jar file (which compresses
    it and speeds download time). The music (whatever
    it is) should be included as a separate resource
    (or even better still, not included at all) and played
    only on request - who wants to listen to crappy,
    (through most soundcards) music while playing
    *chess* anyway?!

    ...Is that what that applet is for? I had refused the
    'give a nickname' crap and ended at some default
    screen, so it was impossible to go further.

    I can tell you this though. If your HTML and JS
    skills are indicative of your ability to write Java
    and C/C++,
    a) the applet is slow because of the code
    b) writing it in another language will result in
    another binary - that will also run slow.

    Andrew T.
    Andrew Thompson, Dec 11, 2006
    #5
  6. Sanny

    Sanny Guest


    > (2) javah produces a C header file (*.h) from a from Java class file.
    > It does not generate any executable C code. It generates only C
    > declarations, which will be the interface between Java code (in *.class
    > file, generated by the javac compiler) and C code (in *.c files, to be
    > hand-written by you).
    >


    Ok javah creates .h file for the Applet. Then how can I use .C files So
    that Applet Calls .c files to compute time intensive calculations.

    Could it be done.

    Say I have a Java class ABC.class with 3 functions

    I create ABC.h file for that class.

    Now I create ABC.c file which implements the three functions.

    Now I want to utilize functions in ABC.c So how will I make a call to C
    files created from the Java Applet ABC.class

    Bye
    Sanny
    Sanny, Dec 11, 2006
    #6
  7. Sanny

    Daniel Dyer Guest

    On Mon, 11 Dec 2006 12:05:52 -0000, Sanny <> wrote:

    >
    >> (2) javah produces a C header file (*.h) from a from Java class file.
    >> It does not generate any executable C code. It generates only C
    >> declarations, which will be the interface between Java code (in *.class
    >> file, generated by the javac compiler) and C code (in *.c files, to be
    >> hand-written by you).
    >>

    >
    > Ok javah creates .h file for the Applet. Then how can I use .C files So
    > that Applet Calls .c files to compute time intensive calculations.
    >
    > Could it be done.
    >
    > Say I have a Java class ABC.class with 3 functions
    >
    > I create ABC.h file for that class.
    >
    > Now I create ABC.c file which implements the three functions.
    >
    > Now I want to utilize functions in ABC.c So how will I make a call to C
    > files created from the Java Applet ABC.class
    >
    > Bye
    > Sanny


    This sounds like a bad idea. Firstly, applets aren't really intended to
    have native methods. Although it can be achieved with a signed applet, it
    isn't sensible because you have no idea what platform the user is going to
    be using. If you build an applet that runs only on Windows, I can't use
    it on my Mac or Linux machines. And even if I am using Windows, I'd have
    to be stupid to grant you the necessary privileges to get the code to run.

    Secondly, despite the myths, using JNI rarely improves performance
    significantly (there are exceptions), it often makes it worse. There was
    an article on java.net the other day about this
    (http://weblogs.java.net/blog/mlam/archive/2006/12/beware_of_the_n.html).

    You should address the issues that Andrew raised in his response before
    going down this route.

    Dan.

    --
    Daniel Dyer
    http://www.dandyer.co.uk
    Daniel Dyer, Dec 11, 2006
    #7
  8. Sanny

    Sanny Guest


    > Secondly, despite the myths, using JNI rarely improves performance
    > significantly (there are exceptions), it often makes it worse. There was
    > an article on java.net the other day about this
    > (http://weblogs.java.net/blog/mlam/archive/2006/12/beware_of_the_n.html).
    >
    > You should address the issues that Andrew raised in his response before
    > going down this route.
    >


    Thanks for your sincere help.

    Bye
    Sanny
    Sanny, Dec 11, 2006
    #8
  9. Sanny wrote:

    [...]
    > I am considering converting a Java Program into C Program to
    > increase its efficiency.

    Don't expect too much from this approach! Making a Java program more
    efficient very rarely needs developing new C code (with javah & JNI).

    (1) Usually the time-consumption of a Java program is concentrated around a
    few hot-spots instead of being uniformly distributed. Be sure to spot these
    performance bottle-necks by *testing* (with some kind of profiler tool)
    instead of by *reasoning*. Guessing the bottle-necks only by intuition is
    almost always (in my experience) wrong.
    (2) Tuning the performance in most cases (in my experience) can be achieved
    by optimizing the design of your Java code. There is rarely need for
    replacing Java code by native C code.
    (3) Be aware that there is already a huge amount of native C code (native
    DLLs in Sun's JRE) working behind the scenes. For example for file I/O,
    network I/O, uncompressing jar/zip/jpeg/gif files, painting on screen,
    playing sound, ....

    --
    Thomas
    Thomas Fritsch, Dec 11, 2006
    #9
  10. Thomas Fritsch wrote:

    <snip>
    All good explanations, but just wanted to requote this part..

    > ....Be sure to spot these
    > performance bottle-necks by *testing* (with some kind of profiler tool)
    > instead of by *reasoning*. Guessing the bottle-necks only by intuition is
    > almost always (in my experience) wrong.


    That is perhaps the best advice that has yet
    come out of this thread(s).

    Andrew T.
    Andrew Thompson, Dec 11, 2006
    #10
  11. Sanny

    Sanny Guest


    > (1) Usually the time-consumption of a Java program is concentrated around a
    > few hot-spots instead of being uniformly distributed. Be sure to spot these
    > performance bottle-necks by *testing* (with some kind of profiler tool)
    > instead of by *reasoning*. Guessing the bottle-necks only by intuition is


    What are profiler tools How to get them and use.

    Bye
    Sanny
    Sanny, Dec 12, 2006
    #11
  12. Sanny wrote:

    >
    >> (1) Usually the time-consumption of a Java program is concentrated around

    a
    >> few hot-spots instead of being uniformly distributed. Be sure to spot

    these
    >> performance bottle-necks by *testing* (with some kind of profiler tool)
    >> instead of by *reasoning*. Guessing the bottle-necks only by intuition is

    >
    > What are profiler tools How to get them and use.


    See for example <http://mindprod.com/jgloss/profiler.html>

    --
    Thomas
    Thomas Fritsch, Dec 12, 2006
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Klett
    Replies:
    0
    Views:
    312
    Steve Klett
    Nov 4, 2003
  2. Shadab
    Replies:
    3
    Views:
    8,314
    charly
    Dec 16, 2003
  3. Murrgon

    How does javac.exe work?

    Murrgon, Jun 22, 2004, in forum: Java
    Replies:
    8
    Views:
    3,345
    Roedy Green
    Jun 22, 2004
  4. imonline
    Replies:
    2
    Views:
    360
    Anthony Jones
    Jan 23, 2007
  5. Shadab
    Replies:
    1
    Views:
    97
    Thomas 'PointedEars' Lahn
    Dec 15, 2003
Loading...

Share This Page