Hardcore Java /JVM tasks

Hardcore Java /JVM tasks Performance problems from the Contour already were , it's our turn: we present hardcore tasks from the Java conference JBreak 201? aka " hell from Excelsior ".
The tasks are given in original formulations, in each problem there can be several correct answers, and for each problem a solution is given under the spoiler.
Problem 1
Your colleague read the Java Language Specification and wrote the following:
void playWithRef () {
Object obj = new Object ();
WeakReference ref = new WeakReference <>(obj);
System.out.println (ref.get ()! = Null);
System.gc ();
System.out.println ...

Development of highly loaded WebSocket service

How to create a web service that will interact with users in real time, while maintaining several hundred thousand connections at the same time?
Hello everyone, my name is Andrey Klyuyev, I'm a developer. Recently I came across such a problem - to create an interactive service where the user can get quick bonuses for their actions. The matter was complicated by the fact that the project had rather high demands on the load, and the deadlines were extremely low.
In this article, I will describe how I chose the solution for implementing a websocket server for the complex requirements of the ...

Binary-ternary bit magic

There is a classical problem for interviews, often formulated as follows:
There is an array of natural numbers. Each of the numbers is present in the array exactly twice, and only one of the numbers does not have a pair. It is necessary to propose an algorithm that, for the minimum number of passes through the array, determines a number that does not have a pair.
I suppose no one will be offended if I immediately bring up the solution of the problem: the unique element will coincide with
Binary-ternary bit magic
-sum of all elements of the array, calculated in linear time.
I propose to think about another variation of this problem...

The game with ormatas

I suggest you play the game. I give you a square grid on which some cells are painted over, and some may remain empty. We will call it a "template". For example, a grid can be one of these templates:
The game with ormatas
You have a stack of transparent plastic sheets, in size and shape matching the mesh, on which the patterns from the black dots are painted:

It is worth noting that in each of these patterns exactly three points, one point in each row and column. The six combinations shown are the only 3 × 3 meshes that have this property.
Your task is to collect a subset of transparent sheets and apply them to the template so that the points close all the filled squares, but do not fall into any of the empty ones. You can apply several points to any of the filled ...

Rust: states of types

Previously, there were state types in Rust that were removed from the language before the official release of the first version. In this article, I'll tell you a secret: Rust supports state types.
I ask under cat.
Enter , you are welcome.Previously, there were state types in Rust that were removed from the language before the official release of the first version. In this article, I'll tell you a secret: Rust supports state types. I ask under cat. Enter , you are welcome...

Scala - from the dead donkey ears

Scala is an amazing programming language that I enjoyed about 4 years ago. I was probably his fan: I bought books and courses on Coursera, I used in pet- and productive projects et cetera, et cetera, et cetera.
Scala opened for me the fascinating world of functional programming, returned to the times of students with "spherical tasks in a vacuum" from Martin Odersky
But here it is already two years since Scala is dead to me. The fault of this
Yes, no one forbids me to use Scala and IntelliJ IDEA for pet projects, but it's not so interesting and it's much more enjoyable ...