When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

eatmore's blog

By eatmore, history, 6 years ago, In English

Java 10 has been released a few days ago, just six months after Java 9. In this version, I found only one new feature which is useful for competitive programming: Local-Variable Type Inferrence. It works similarly to auto keyword in C++. So now you can write something like this:

var map = new HashMap<Integer, List<String>>();
for (var entry : map.entrySet()) {
    var key = entry.getKey();
    for (var element : entry.getValue()) {
        System.out.println(key + " " + element);
    }
}

If you find any other relevant enhancements, please post them here.

  • Vote: I like it
  • +97
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
  Vote: I like it -14 Vote: I do not like it

your username is lit ;)

»
6 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

What about cool features which is useful for competitive programming in Java 9?

I've found only one blog about this, and it also contains only few features ((

»
6 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Does Codeforces already support Java 10? I can only find the Java 1.8.0_131 (Java 8) as available compiler. And I expect that most of the other platforms also still use an old version.

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The Java feature what should make the most impact in competitive programming is Ahead-of-time compilation. That should make Java solutions almost as fast as C++ solutions. JIT compiler needs a lot of warmup, and simply can't compile most programs in 2 seconds. That means, currently Java solutions are interpreted, thus very slow.

Unfortunately, AOT compilation is still experimental in Java 10.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This is awesome to hear for the future. Are we seriously talking about Java being as fast as C++ ?

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Almost as fast as C++ :) At least, magnitude faster than interpreted Java.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I don't think so.

    "It’s possible that the use of pre-compiled code could result in less-than-optimal code being used, resulting in a loss of performance. Performance testing shows that some applications benefit from AOT-compiled code, while others clearly show regressions." from http://openjdk.java.net/jeps/295

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it +18 Vote: I do not like it

      You are talking about JIT-compiled vs AOT-compiled. And I agree that JIT-compiled programs are generally more performant in the case of long running applications than AOT-compiled programs, because JIT compiler is able to use execution profile data.

      But the truth is that in programming competitions we never run JIT-compiled programs. JIT-compiler does its job at runtime, and simply can't compile anything during 1-3 second time limit. Before Java bytecode is compiled by JIT, it has to be interpreted, and execution by interpretation is much much slower than execution of machine code.

      On the other hand, AOT-compiler works at build step (like C++ compiler), so the code doesn't have to be interpreted.