Maybe it's possible to write good java code but it seems to encourage being a sloth.
Correct. It is possible to write good java code and it does encourage inefficient practices. This stands in contrast to C++ which makes it rather difficult to write good code (assuming similar algorithms and data structures in both programs), but strongly discourages or even prevents things that cause sloth-like performance. By "good code" here I mean code that is secure and doesn't crash. Complex C++ codebases are invariably riddled with various kinds of exploitable overflows or code paths that trigger segfaults that tear down the entire process. It's especially unfair that Java got a bad rap for security partly due to bugs in the C++ code in the JVM!
That said ..... things are changing. There are actually high frequency trading firms that use Java, believe it or not. Some of the things they make the JVM do are quite impressive. Java's poor perceived performance on the desktop has historically come from several areas. To name just 4:
1) Excessive memory usage leading to swap hell. Garbage collection doesn't play nice with swapping either, due to lack of the right kernel support. A big offender here is the profligate use of pointers and especially inefficient representations of strings (always UTF-16). Also, garbage collectors that were tuned to look good in benchmarks by using larger and larger heaps didn't help.
2) Poorly optimised graphics stacks. Note that if you use Linux you suffered from this very badly because you probably got OpenJDK which used an open source but much slower 2D rendering system, vs the proprietary Sun/Oracle JRE which used a proprietary but much faster licensed renderer called Ductus.
3) Older JVMs weren't well optimised and did things that made them start slowly, like storing all their code as .class files inside zip files. Also, JVMs are huge downloads.
4) Java code has historically not had access to things like vector instructions, advanced data layout and inline assembly, all of which can be exploited to give huge performance gains in things like multimedia apps.
All of these things are being tackled quite energetically by the JVM team, however. The latest JVM can now do things like deduplicate strings in the heap, and in Java 9 (in development version) there's new code that switches the character encoding of strings between Unicode and non-Unicode depending on what's needed at the time. This change is especially impressive because it not only reduces memory usage but actually makes software go faster too due to better cache utilisation and less GC pressure. There's a long term project called Valhalla to upgrade the JVM with value types, which is where C++ gets a lot of its built-in advantage from, by giving the developer better control over data layout. There's also a project called Panama which is adding support for, amongst other things, inline assembly to Java. A prototype was recently posted to the OpenJDK lists. A new open source graphics rasteriser has been built that's faster than Ductus, so even the open source only OpenJDK users will soon have faster graphics, and a new UI toolkit to replace Swing has been developed called JavaFX. It uses hardware accelerated graphics everywhere via OpenGL and DirectX.
Also, Intel have been contributing much more advanced auto-vectorisation logic to the JVM's compilers, the Jigsaw and "minimal JVM" projects are allowing developers to statically link optimised JVMs with their app which then pre-process JARs into special file formats so the loading process is much faster, and there's also work on ahead of time compilation being done to get rid of the slowness at startup before the JITC has compiled all the code.
These are all projects that are either shipped already or in development now. The JVM guys do understand the causes of Java's slowness, they just aren't willing to sacrifice the convenience and robustness the platform offers developers in order to fix things. So, quite often, they find they have to develop new technology and do new research to find ways to have their cake and eat it.