Java Eight

Back to Programming Languages forum

Vadim Tukaev     2015-08-23 11:35:03

What about Java 8 support?

Shoshannah     2015-08-24 06:53:57

Just curious (and because I'm your biggest fan ever): can you give us an example of your solution which uses Java 8?
Also, how is your do-not-drink-or-smoke-need-a-job-thing going?

Rodion (admin)     2015-08-24 08:47:54
User avatar

Vadim, Hi!

What do you mean by "support"? Is it about remote compiler/runner tool? I'll try to research this (since it is API of hackerrank, not of CodeAbbey). Though technically of course if you need not this functionality you can post solutions even in Java 9 and mark them as always, simply with "Java"...

> can you give us an example of your solution which uses Java 8

Huh, I'll try to rewrite some of my scala solutions and see how horrible they will look :)

Shoshannah     2015-08-24 09:33:37

Huh, I'll try to rewrite some of my scala solutions and see how horrible they will look :)

Yes, please!

Rodionische     2015-08-25 09:32:59
User avatar

Well, I'm quite sorry but it seems more difficult than I thought. I tried this solution for Collatz Conjecture and suddenly found that Java 8 have no ready takeWhile implementation.

Of course some workarounds could be undertaken, but the resulting solution looks too verbose and horrible.

Perhaps any of you have idea of another approach for I feel like stuck right now?

UPD After composing myself I thought I can rewrite the counting logic itself so that it use recursion. Of course java have no TCO as I remember so it is not great idea, but for this problem will work:

Collatz in Java8

P.S. As to original question, it seems currently there is no support of Java8 at Hackerrank API, I'm sorry - so we need to wait until we can have our own server with running tools... :(

Vadim Tukaev     2015-08-28 11:26:43

Also, how is your do-not-drink-or-smoke-need-a-job-thing going?

About a week ago I got a job in a very small office. It's some young ambitious people (I'm the oldest of them), no smoke or drink. Of course, this is a coincidence, I was not looking for such people specifically.

As to original question, it seems currently there is no support of Java8 at Hackerrank API, I'm sorry - so we need to wait until we can have our own server with running tools... :(

Java 8 present here - https://www.hackerrank.com/environment - or do you mean something else?

Rodion (admin)     2015-08-28 16:11:39
User avatar

> About a week ago I got a job in a very small office.

Wow, that sounds really great! I hope you will be able to tell more interesting things about your new project soon! Our congratulations! :)

> Java 8 present here

Yes, but our site uses their API and here in the list of languages I see no Java 8. Though probably we can e-mail them and ask - perhaps it is exposed under some undocumented ID...

Andrew Yefanov     2017-01-15 13:24:47

There is Java 8 now, and even Groovy! Hope they both will be added!

Alexander Dubinskij     2017-04-04 17:29:08
User avatar

What about the Java 8 support now?

It have not arrived to 'codeabbey.com' yet, don't it?

The following example code reads count ('n') from first line, and then reads 'n' next lines, "processes" them using Java 8 Stream API, and puts them to output.

import java.util.*;
import java.util.stream.*;

public final class Solution
{
    public static void main(String[] args)
    {
        final Scanner input = new Scanner(System.in);
        final int n = Integer.parseInt(input.nextLine());

        for ( int i = 0; i < n; ++i )
        {
            String x = input.nextLine();
            String f = x.chars().mapToObj(ch -> String.valueOf((char) ch)).collect(Collectors.joining());
            System.out.println(f);
        }
    }
}

This code works fine at my local machine, but crashes on this site (when "Code Running Tools" used).

I see the following error message into the "Your answer:" text field:

Solution.java:14: error: illegal start of expression            String f = x.chars().mapToObj(ch -> String.valueOf((char) ch)).collect(Collectors.joining());                                             ^1 error

I like to use Java 8 Stream API, and it is uncomfortable for me to copy/paste texts between browser window and IDE instead of running my code via this site directly.

Especially when the solution is invalid and requires the further improvement.

Please login and solve 5 problems to be able to post at forum