Is java slower then c/c++

why does java code take more running time??is it actually very slow compared to c/c++

Yes it is slower than c++/c, that is why it is given 3 time amount of time then c++/c gets

the C++ solution is slightly
faster (around 10-15%). jvm
startup adds another 40% to the
runtime of the java program,
depending on use case that should be considered. Also, neither
solution is very optimized. The c++
code spends approx. 75%
allocating memory, that’s no way
to benchmark an algorithm. With
slight optimization of the c++ code it runs 4 times faster than the java
code

2 Likes

If you handle input-output operation in java correctly , Java speed is pretty good . Java also is a very stable language.

1 Like

Java is much slower than C/C++, not just 10-15%. Look at and compare the fastest solutions in Java and c++. A question like MCHAIRS taking 0.00 sec in cpp will take minimum 0.20 sec in Java, which is more than 20 times faster with same algorithms.This is true for many questions. Many times your algorithm with O(n^2) will get accepted in C++ and show TLE in Java. The good thing is with Java you will learn to write more optimized codes because margin of error is less.

Java code runs in a virtual machine and is both a compiled and interpreted language. C/C++ are only compiled but you shouldn’t be worried much about this, Java speed is pretty good and it is a very stable language.

Slower - TRUE, 3X time - FALSE

Ref : http://blog.codechef.com/2009/04/01/announcing-time-limits-based-on-programming-language/

yeah and adding to what @junior94 has mentioned, it has more support than c/c++ …it has a very big list of libraries and not just about contest programming, its quite broad!

Yeah, agreed @mecodesta, Java has the best documentation and comes with a lot of built in libraries covering many needs.