eatmore's blog

By eatmore, history, 4 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

»
4 years ago, # |
  Vote: I like it -14 Vote: I do not like it

your username is lit ;)

»
4 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 ((

»
4 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.

»
4 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it
String.repeat(int);

will repeat the string the given number of times. Apart from these 2 no CP specific changes. There are some for unmodifiable list but that is never used here. Also these are non LTS releases so won't have much changes. The next LTS release would be J11. Source.

EDIT: OK, I am wrong. Just checked. Repeat is apparently in J11.

»
4 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.

  • »
    »
    4 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++ ?

    • »
      »
      »
      4 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.

  • »
    »
    4 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

    • »
      »
      »
      4 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.