Блог пользователя eatmore

Автор eatmore, история, 6 лет назад, По-английски

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.

  • Проголосовать: нравится
  • +97
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится -14 Проголосовать: не нравится

your username is lit ;)

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

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 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

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 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 лет назад, # ^ |
        Проголосовать: нравится +18 Проголосовать: не нравится

      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.