Is it better to use c++ instead of Java for competitive Programming??
If you are comfortable pointers then go for C++.
Let me state few advantages of using c++ over java
C++ has power STL library
In c++ you don’t need to write too long too much useless stuff as you need to do in java
Java has lots of inbuilt functions and classes though it is powerful its useless for competitive programming purpose where speed is a critical factor
Mostly editorials in every site is written in c++ so it will be easy for you to understand where you may be wrong
C++ allows global declaration, reduces the lines of code significantly and reduces chances of SIGSEV error
#define can be used to shorten frequently used codes
Since inbuilt functions are less you can yourself explore and understand code than using inbuilt codes as in java to get you solution AC
If you know C, it’ll be easy to adapt c++, as in java everything is a class, somewhat difficult to manipulate for beginners
Though it has only one disadvantage handling big integer is tough.
Although both, Java and C++ are object oriented, you dont have to know OOPS to use C++. C++ is quite straightforward unlike Java. The C++ STL is sufficient for Competitive Programming. Competitive Programming does not require much knowledge about OOPS. As such, C++ does not give a big advantage over Java except for the time factor. Neither gives a big advantage over the other, so use the one you’re more comfortable with.
Yes, big integer can be a pain. I switch to python for such questions.
Also, +1 for " In c++ you don’t need to write too long too much useless stuff as you need to do in java"
(My sentiments in high school XD)
If u are good in java you can…but it’s my suggestion to start with C++ as stated by @neilit1992.
These advantages can help you to understand C++ better.
same here, i use python for big integers!
In C++, you can implement everything from scratch and thats what is fun, better to know lowest level of abstraction than being contained with highest level if abstraction
Nothing is better or worse, there have been top programmers in topcoder (petr) who’ve used Java just as successfully as C++. Contests are usually made to test the algorithmic knowledge of participants, rather than language understanding.
Also, -1 for the ‘speed advantage’ argument. Time limits are set according to the language, so its highly unlikely that a O(n2) solution starts getting accepted just because language was switched from Java to C++, for example.
Also I feel IDEs and debugging support for Java is much better for a beginner than C++, so you might want to consider that too. Ultimately, your algorithmic knowledge is what will get your solutions accepted, language is just a way to get there. So use whatever you’re comfortable with.
Java vs. C++ which is it most excellent? What are the Disadvantages and Advantages of Java vs. C++? Actually I have to make a website for Online Finance Essay Service can someone please help me?
I agree with @ebcidic666, but except for the statement
Time limits are set according to the language
Time limit set is same for any language you use, it doesn’t vary as you choose your language.
The other difference which i would like to add is that, Java consumes more memory compared to C++.
I personally use Java, as i am professional and also using the same to submit solutions.
except Hackerrank and hackerearth no platform provides time limit based on language.
[java v/s C++]
C++ is basically more power to the programmer (since one can break past all sorts of abstractions), and runs natively instead of on a virtual environment (and hence is also platform dependent). A C++ application can manage its own memory in more finer ways than a Java app can. In C++, one can overload operators, access physical addresses and override values there. One can throw and catch any type (…) and do some nasty stuff around all that. On the other hand, in Java, one can sit back and basically just deal with OO abstractions and code them up in one-way, regardless of the underlying platform. Fine-grained memory management is harder. One can play around with GC params for optimizations and get really far this way, but anything more is not really achievable. In C++, you can easily get as deep as you want to.
But, also remember, with great power comes great responsibility. An irresponsible Java developer would be less harmful to your software, than an irresponsible C++ developer would be. In that sense, Java is a relatively easier and simpler language to work with, than C++ is. With C++, a lot of responsibility and burden is on the shoulders of the programmer and with Java, a lot of this, is taken care of, by the system.
Actually, even codechef does apparently. Check this out! https://blog.codechef.com/2009/04/01/announcing-time-limits-based-on-programming-language/
For large input java is better… but C++ provides you the better speed
speed as well as less line of codes as compared to java is considered a major advantage of cpp in competitive programming.
Since we all know that time and accuracy is vital in competitive programming,LoC(Line of Code) becomes a important factor in deciding the winner of competition.
C++ is very effective in decreasing the LoC and space complexity.But we all know Java is more powerful than C++ as there are more predefined libraries in it.
Choosing a language for programming in competition must depend on the type of problem and its requirements.If a simple factorial or its extension is asked I would go for C++, but a complex derivative problem is asked i would go for Java.