Java vs. C++

downhiller80

Platinum Member
Apr 13, 2000
2,353
0
0
C++ is obviously more powerful ultimately.

But let's say you have a relatively simple simulation program, something like iterating a cars acceleration or something.

How much faster would c++ be?

- seb
 

metalac

Member
Jan 5, 2002
61
0
0
well i dont know why but most universities including mine are switching to Java and I have no idea why, but it's nation wide since i got a lot of friends who are taking the Java classes too, while in the past it was C++
 

Turkey

Senior member
Jan 10, 2000
839
0
0
If you had your PC set up so that the VM would start when you double clicked a .java file, the C++ version would still be much faster to execute than the Java version because the VM would have to load before the program could start. If the VM was already loaded, there wouldn't be much difference between the two.
 

BFG10K

Lifer
Aug 14, 2000
22,709
2,995
126
I'm willing to bet that the development time will be shorter on C++ because you could jump right in without being forced to use classes.
 

Kinesis

Senior member
May 5, 2001
475
0
76
I don't agree. C++ is not truely and OOP language. It is a programming language, given some components to make it act like Object Oriented Programming. Yes it is faster, for reason stated above. But one must remember that a third the lines of code (easily) in Java would produce a superior result in things like web based apps than C++.

And as far as class creation. It is far easier to design a class, and instantiate it when ever you need an object of that class to perform a set of functions, etc. i.e. Servlet or Applets.

Just my own thoughts!
 

FOBSIDE

Platinum Member
Mar 16, 2000
2,178
0
0
Sun is just banking that JAVA will be around long enough so that the "on the fly" running of the programs won't be slow because of better, faster hardware. It's true to some extent. Faster processors and more ram make run time differences minimal, but then you'll just be pushing JAVA even more. What about games programmed in JAVA? They'd be great because they'd be platform independant but who is going to wait around for hardware to advance that much so JAVA first person shooters can be run? Even with hardware advances, JAVA is still limited by speed.
 

MrWhiteUK

Senior member
May 13, 2001
625
0
0
Just thought I'd add to this little discussion that a 'freind of mine' had written the towers of Hanoi function in a C++ app. After the program had calculated for so many amount of discs (so many million calculations) it displayed the time taken to complete the function.

He sent the source code to me, I copy/pasted it into a Java file (20 odd lines) and changed the Cout >> for System.out.print and ran them one after the other (several times).

C++ (compiled w MSVC) 16 secs
Java (1.4rc) 14.9 secs


Faster pff
 

FOBSIDE

Platinum Member
Mar 16, 2000
2,178
0
0
do you still have that code? id like to test it on my machines. PM me if you got it still.
 

downhiller80

Platinum Member
Apr 13, 2000
2,353
0
0
I am that guy. Here is the code I wrote:

#include <iostream>
#include <ctime>

using namespace std;

int moves=0;

void hanoi(int disks, int start, int end, int hold)
{
if (disks==0) return;

hanoi(disks-1, start, hold, end);
// cout << ++moves << ": Move disk " << disks << " from pole " << start << " to " << end << endl;
hanoi(disks-1, hold, start, end);
}


int main( )
{
long time1 = time( 0 );

hanoi(30,1,3,2);

long time2 = time( 0 );

cout << endl << time2-time1 << endl;

return 0;
}



If he didn't cheat and java is quicker I'm quite impressed. But we all know java's shortcomings are in the speed of its GUI etc.

I think the speed difference we noted was due to MSVC++ 6 being, what, 2 or 3 years old now. No doubt the Java compiler has better optimisations in it being so much more up to date.

- seb
 

MrWhiteUK

Senior member
May 13, 2001
625
0
0
Java source, converted from Sebs .cpp


final class HanoiApp


{




public static void main(String[] args)
{
long time1 = System.currentTimeMillis();
hanoi(30,1,3,2);
long time2 = System.currentTimeMillis();;

System.out.print(time2 - time1 + " milliseconds");

}




private static void hanoi(int disks, int start, int end, int hold)
{
if (disks==0) return;

hanoi(disks-1, start, hold, end);

hanoi(disks-1, hold, start, end);
}




}
 

thornc

Golden Member
Nov 29, 2000
1,011
0
0
Hehe, my dual pentium 3-450 katmai took 123 seconds.... with the c++ version...

I've to try installing in java and test it....

Has anyone tried this using Python??
 

manly

Lifer
Jan 25, 2000
11,836
2,794
136


<< I'm willing to bet that the development time will be shorter on C++ because you could jump right in without being forced to use classes. >>



*buzz*

Wrong answer. The reason that Java is successful in the marketplace is because it's a simpler language and allows many developers to be more productive in.

Not only more productive, but to have more reliable code since memory management is handled by the JVM.

As far as performance goes, there are many benchmarks where Java is competitive (not necessarily faster) than C/C++. Java isn't suitable for everything (i.e. systems programming), but it does well in many tasks.

Anyone who says Java is inherently limited in speed is misguided by M$ FUD. There are things Java is unsuccessful at, i.e. GUI apps, but this isn't because the language itself is slow, but because the libraries are not compelling.

For one example, remember id embeds a (custom?) Quake virtual machine in Quake 3 Arena for certain tasks; if the performance of that module is fast enough for a FPS game, that suggests it would be fast enough for many other more mundane jobs.

The biggest single reason that Java code runs slow is that programmers who come from a C/C++ background often have habits from the other languages that simply are bad mistakes in Java.

And finally, the comment that the Java compiler must be better optimized than VC++ is unlikely. Java compilers are pretty simple because the bytecode can't truly be optimized until runtime when it hits the JIT compiler. Remember Java bytecode is cross platform, and optimizations are often platform-dependent.
 

downhiller80

Platinum Member
Apr 13, 2000
2,353
0
0


<< Hehe, my dual pentium 3-450 katmai took 123 seconds.... with the c++ version...

I've to try installing in java and test it....

Has anyone tried this using Python??
>>



Compile it as release instead of debug and it's like 8 times quicker.

- seb
 

m0ti

Senior member
Jul 6, 2001
975
0
0


<< I'm willing to bet that the development time will be shorter on C++ because you could jump right in without being forced to use classes. >>



I'll agree with that statement for any really small programming assignment, but for any real project it's the design that makes or breaks it. Java is very good for rapid development, and integration is easier too.

As for graphics speed, yes Swing isn't the fastest out there, but nobody's trying to make games with it. Games are (and have been) written in Java (albeit, not that many) through the use of JavaGL (which gives Java access to OpenGL).

Performance wise, Java isn't quite at C++ standards, mainly because it's not as optimized when its compiled due to platform independence. Note that there are platform specific compilers for Java, which produce optimized code. A couple of these are free for non-commercial use (link) , and aren't that expensive for commercial use either.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |