Java code and C# implementations