Competive programming language: C++ vs Java

Which is the better programming language for competitive programming : C++ vs Java?

1 Like

Most people use c++ because of it’s speed and stl. Even though I don’t

@pkien you can refer to this thread link, and it will be good to search on the discussion forum that whether your question has already been asked or not so that there would not be repetitive questions.

Here I have given a difference between C++ and Java.

Memory safe


C++ : No

Java : Yes

Note : This means that errors in Java programs are detected in defined ways—for example, attempting a bad cast or indexing an array out of bounds results in an exception. Similar errors in C++ lead to undefined behavior, where instead of raising an exception or crashing, your program might keep running and crash later or even give the wrong answer or behavior.

Platform dependent


C++ : Yes

Java : No

Note : At compilation time Java Source code converts into bytecode .The interpreter execute this bytecode at run time and gives output.

Java is interpreted for the most part and hence platform independent. C++ run and compile using compiler which converts source code into machine level languages so c++ is plate from dependents.

Performance


C++ : Faster

Java : Slower

Note : C++ design decisions always favor execution speed and lower memory usage first.Java was designed for simplicity and programmer productivity, rather than for execution speed.

Memory Consumption


C++ : Less

Java : More than C++

Operator overloading


C++ : Yes

Java : No

Native unsigned arithmetic support


C++ : Yes

Java : No

Note : At compilation time Java Source code converts into bytecode .The interpreter execute this bytecode at run time and gives output.

Write and Run


C++ : Write once, compile anywhere (WOCA).

Java : Write once, run anywhere/everywhere (WORA/WORE).

References:

https://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B

https://www.quora.com/What-are-major-differences-between-C+±and-Java

1 Like

C++ is the most preferred language for Competitive Programming.

c++ is use by most , java is used when we have to handle big integers which is currently not supported by c++.

C++ beats java in the following ways:

  1. C++ doesn’t punish for bound
  2. STL
  3. scanf to read some type of regex value (E:g comma seperated)
  4. Execution speed

Java on the other hand:

  1. BigInteger
  2. StringBuilder for string manipulation
  3. BitSet for bit maniupulation

Fact: 60%+ users were found using C++ in Google Code Jam (can’t find the reference, read it somewhere, could be incorrect)

Why does everybody seem to point out BigIntegers as an advantage for Java? After all it’s a complete memory hog, it will most easily exceed the memory limits of strict contests. Though the biggest advantage of C++ is its STL and a bit better speed, I guess you’ll be better off using what you can use the most effectively.

Even a language as old as Pascal can outperform C++ if used in the right way. Contests require you to know the right way to find solutions, you need not be a C++ guru. If you’re really worried about Java’s speed javac 8 is almost comparable to C++ in execution time, but having an old compiler like GCJ is just not good enough.

The only problem you’ll find mostly with Java is the long syntax, that’s about it.