In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the reasons why ava language is slower than CPP competitive programming". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
The most important factor is choosing the right language when starting competitive programming. Often, we choose languages that have short syntax, execute very fast or are familiar to us, and we know all the working patterns of a particular language, whether it's Java or C++.
Most programmers use C++ for competitive programming, and many older programmers switch to C++. Most acclaimed competitive programmers like Gennady Korotkevich, Errichto, and many others, use C++ for competitive programming, but why is there so much less Java for competitive programming than C++? let's look at
C++ Simple Addition Program:
Java Simple Addition Program:
We can see that the execution time and memory of C++ is much smaller than Java programs. For large programs, this is a big problem.
There are many reasons why Java is slower to program competitively compared to C++, which makes programmers avoid it. Some common ones are listed below.
1. Wrong class selected or syntax used for I / O operations
Compared to C++, Java is a relatively slow language. JAVA generally has two classes for I / O operations: the Scanner class and the Buffered Reader class. Most programmers, especially beginners, use the Scanner class for I / O operations and avoid using the Buffered Reader class for I / O because of the long syntax.
Internal parsing operations in the scanner class make program execution very slow, while the Buffered Reader class simply reads input and performs further parsing as needed for the operation. In competitive programming, use the Scanner class to create TLE problems for Java programs.
2. Compilation and execution process
Programming languages can be distinguished by program execution and compilation. Some languages are interpreter languages, meaning that the interpreter checks the grammar of a particular interpreter language line by line, such as Python.
Compiler languages convert programs directly into machine code. As a result, these languages are much faster than interpreter languages. Interpreters spend very little time analyzing source code. However, the overall time to execute the process is much slower. This makes the execution of Interpreted programming languages very slow compared to compiled languages such as C or C++. This is why Python is slower than C++ and Java.
Java is neither a compiled language nor an interpreted language. It's in the middle. Java is a platform-independent language and is therefore very popular in all programming languages. Bytecode makes it a platform independent language. This is Java's advantage.
It makes program execution slower than C++ programs because no intermediate operations for execution and compilation occur as Java does in C++. The reason for slow program execution is that it is expensive to start Java code if the virtual machine is not running.·
3. memory consumption
Java programs consume more memory than C++ programs.
We all know that Java manages memory itself and does not require explicit intervention from programmers. The garbage collector itself ensures that unused space is cleaned up and memory is freed when it is not needed. As a result, the extra garbage collector takes up extra memory to track all memory consumption by java programs.
For Java programmers, it is beneficial not to pay attention to memory management. It is done automatically by JVM and garbage collector, but garbage collector does not exist in C++. Memory leaks can occur, but this makes C++ programs very lightweight.
Therefore, C++ programs consume very little memory compared to Java programs. As a result, it helps to execute C++ programs quickly.
We can choose any language for competitive programming, but first we have to be clear about all its basic topics and how a particular language works, which will be very beneficial for beginners.
"ava language is slower than CPP competition programming what are the reasons" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.