So I have recently been learning java and everywhere I go I hear that java is a slow language compared to C or c++. I know that when it came out in the 90's that it was a lot slower, but I was wondering how much slower is it today. Also when writing java programs do you ever really run into issues with how slow it is?

javaAddict commented: For the signature. +13

Dani AI

Generated

Short answer: it depends. Modern JVMs use runtime compilation and heavy optimization, so for many long‑running, CPU‑bound services Java's steady‑state throughput can be in the same ballpark as well‑tuned C/C++. Where Java usually loses is startup latency, memory footprint, and latency predictability (GC pauses). Those tradeoffs explain the mixed impressions in this thread.

Several practical points that build on earlier replies: follow 's suggestion to test, but do it properly — realistic workload, JVM warm‑up, and repeated runs. Naive microbenchmarks often mislead because the JVM optimizes away work; use a proper harness (e.g., JMH) and measure both throughput and tail latency. is right that the runtime is highly optimized; is also right to flag memory usage; and the sluggish feeling described is commonly caused by GC or poor UI/threading, not an inherent impossibility for Java to be responsive.

If a real bottleneck appears after profiling, prefer algorithmic fixes or JVM tuning first (heap sizing, different garbage collector, inlining thresholds) before adding native code. JNI/native modules solve some cases but add complexity, portability and maintenance costs. For decisions: choose C/C++ when you need minimal memory footprint, hard real‑time guarantees, or the absolute lowest microsecond latency; choose Java for faster development, safer memory model, and strong libraries unless measurements force otherwise.

Quick checklist:

  • Measure the real workload (warm up, multiple runs).
  • Profile to find hotspots (CPU, GC, I/O).
  • Tune JVM and algorithmic choices.
  • Only then consider native code for measured hotspots.

Recommended Answers

All 5 Replies

Member Avatar for Member #114696

Well performance is hardly an issue for most applications(as its unnoticeable). Java is being successfully used in several areas. I'm not a good/experienced Java programmer, but the reason people use languages like Java, C#, Python is the increased productivity.

You can search for benchmarks or make yourself and see. The reason Java is slower than C/C++ is because Java is compiled into Bytecode which is interpreted during runtime by JVM. C/C++ on other hand is compiled to native code(the machine code you call).

If some Java application needs performance boost in specific areas, you can write those part in C and interface it with jav using JNI.

ah thanks that clears a lot up.

It's a myth that Java is slow. The JRE is highly optimised and performs comparably to ordinary C++ code. Only in the most performance-critical CPU-intensive tasks will you see any real benefit from properly tuned C++
Have a look at
http://scribblethink.org/Computer/javaCbenchmark.html
that was 2004, but the JRE has only improved since then.

Hmm why not test yourself. Write a test application that does the things with standard libraries and primitive constructs.

The problem with Java is not running slow but memory usage I think. You can watch and read what Stroustrup explains about Java, C# and C++.

I don't normally opt to use applications written in Java because they seem to not be as responsive on my system. If an application written in a different language is available I normally choose it.

If one day soon bleeding-edge PC games are written in Java I will be surprised, but until then I think C/C++ is really the performance king.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.