Answer the question
In order to leave comments, you need to log in
Java slows down, but C doesn't?
I don't understand Java at all and I don't know C++ professionally. Noob question.
I have my own controversial opinion that everything written in Java almost always uses computer resources much more wastefully and greedily than what is written in the C family of languages.
This is based solely on experience with software written in different languages. Everything written in Java feels slower and loads more.
Am I correct in my opinion?
Answer the question
In order to leave comments, you need to log in
C/C++ programs work faster due to the rejection of control over everything and everything (memory consumption, stack overflow, correctness of pointers), due to explicit and hard typing of variables, due to fewer wrappers around data types. But it allows the programmer to shoot himself in the foot in ways that Java never dreamed of.
What is more inhibitory Russian or Chinese? In my opinion, Chinese, but it seems to the Chinese that Russian is more retarded.
Theoretically, C++ MAY be faster due to the fact that it is immediately "translated" into machine code, but this entails a decrease in manageability and speed of writing code.
But in reality, the resource consumption depends on the architecture of the program and the algorithms used.
Therefore, it is impossible to say for sure.
I agree that Java is only partly slow. It is slow only in one thing - at the start of the application. Further, when the application has already started and performed the entire JIT compilation, the speed is very comparable to that of C / C ++ code. Well, a slow start is typical of all languages with a virtual machine, and there is nothing to cry about. Well, try to make an application for a week with dynamic loading of plugins, work with the database, balancing and servicing thousands of connections. If it worked out in C/C++, then congratulations, but you've got a clumsy buggy monster crashing into core.
In such cases, I always remember the quote from the advertisement "you just don't know how to cook them"
You can't deceive nature. Both for Java and for C ++, everything results in native code, which is executed in the same way. And, for example, starting in C ++ with direct work with buffers (supposedly for acceleration), a person comes to "smart pointers", their own allocators, and in a good case, to libraries (boost, stl).
As a result, the C++ code, in addition to the pure functionality laid down by the programmer, is overgrown with the execution of additional operations of standard libraries. Thus, the C++ code becomes not so fast as it seemed at first.
And another thought. In most cases, the trend is that it is more important that the code is created faster than it is executed .. "Narrow", special places are optimized according to the algorithm proposed by xandox above in the answers.
Yes, no, and you can write in java so that it doesn’t slow down. For some reason nobody does it...
Numerical code in Java is about 2-3 times slower than in C++ or, say, Delphi. So it seems in my own subjective experience. Because in Java, too many different features are docked in the bytecode purely mechanically.
But it is quite possible to write programs with quite satisfactory performance. Even numerological ones. For example, full processing of 10000 by 10000 rasters (binarization or other matrix filters) using native code (without native libraries) completes in seconds. without tiring the user. But! Here the question arises about the knowledge of algorithms, or rather, which one should be applied where.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question