Thread: Will Java ever be as efficient as C or C++?

  1. #1
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166

    Will Java ever be as efficient as C or C++?

    Will Java code ever be as (or close to) efficient as C or C++? The reason I'm asking is because there's a small discussion about programs written in Java code vs. the same programs written in C++.

    The discussion primarily focuses on low level socket-based programs.

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    I'd say it's extremely unlikely unless lots of CPUs start supporting Java instructions natively.

    It's that simple: Java does not compile to machine code like C++ does, it compiles to intermediate code which then has to be interpreted into the host system's machine code. There is a computational cost to that. It could be argued that when we're cooking on 8GHz processors or whatever new CPU enhancement (e.g. multi-core) they come out with that this cost will become negligable, but it will always be there.

    Java is for multi-platform support without knowing anything about each platform. That's all it's for.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Will Java code ever be as (or close to) efficient as C or C++?
    Not as long as you use the JVM, since there's a level of abstraction that naturally effects performance when compared to native machine code. But if you compile Java to machine code using JIT, its performance is closer to C++ than C++ites would like you to believe.
    My best code is written with the delete key.

  4. #4
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    I think when mac and *nix take a bigger share of the OS market Java will become a more important tool. Until then, I hate it.

    [edit] Doesnt really answer the question, but yah..
    Hmm

  5. #5
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Probably not. One big thing they boast about for Java is the fact that the JVM makes it completely portable, but it also makes it not quite as low-level as C. It also doesn't give you the power to manage memory....which makes it weaker than C in my opinion. I still like how easy it is to program graphic applets with Java though.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The discussion primarily focuses on low level socket-based programs.
    Well the bottleneck for many socket-based programs is not CPU code execution, but rather socket IO. In that case, it can be said that java performance could be very close or equal to that of C++.

  7. #7
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Java and C++ are intended for different kind of problem solving... so any comparrision between them would not be fair.

  8. #8
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by vasanth
    Java and C++ are intended for different kind of problem solving... so any comparrision between them would not be fair.
    Yes but the same program can be coded in ANY language, just each in a different way.

  9. #9
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Quote Originally Posted by sand_man
    Yes but the same program can be coded in ANY language, just each in a different way.
    Write any program with a half decent looking UI in Java. It can't be done.

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Java and C++ are intended for different kind of problem solving... so any comparrision between them would not be fair.
    Indeed so.

    Nice to see you back vasanth.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Quote Originally Posted by stovellp
    Write any program with a half decent looking UI in Java. It can't be done.
    What do you mean by "half decent looking"? IMO, a UI should be chiefly be easy to understand and clean. There's no reason you can't do that in Java.

  12. #12
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    I thought java had reasonably good GUI's. I didn't realise they were that bad.

  13. #13
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by stovellp
    Write any program with a half decent looking UI in Java. It can't be done.
    Sure it can, just stay away from Swing and AWT.... There are more UI libraries than the default API's provide. SWT for example will give you a standard API to the native widget set on whatever platform you're using, the UI will look exactly the same as the same UI written in C/C++, python, perl, etc...

    Although, I would have to agree that "It can't be done" by a person that can't open their mind beyond the common stereotypes.

  14. #14
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    C++ rules
    Woop?

  15. #15
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    How does Java compile its programs? I was doing a test today on my mather parser to see how fast it would run, so I did a basic 3+3 and ran that through the parser a million times....it took 574 milliseconds. I then did the same thing in Java thinking it would take between 10-200 milliseconds or something....but it ran in 0, just like C++.

    Now, I know it's not *as* fast as C++, but how did they efficienize their parser so much?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  2. First Java Class at college
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 09-29-2004, 10:38 PM
  3. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  4. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM
  5. C or Java as a first language
    By CorJava in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 10-23-2002, 05:12 PM