public class FindTheClosest {

    private final Number target;
    private final Number[] numbers;

    public FindTheClosest(Number target, Number[] numbers) { = target;
        this.numbers = numbers;

    public Number execute() {
        Stream<Number> stream =;
        Optional<Number> optional = stream.min(Comparator.comparing(number -> {
            double delta = target.doubleValue() - number.doubleValue();
            return delta == 0 ? Integer.MAX_VALUE : Math.abs(delta + 1F / Integer.MAX_VALUE);
        return optional.orElse(target);

Generic Types (The Java Tutorials > Learning the Java Language > Generics (Updated))

By convention, type parameter names are single, uppercase letters. This stands in sharp contrast to the variable naming conventions that you already know about, and with good reason: Without this convention, it would be difficult to tell the difference between a type variable and an ordinary class or interface name.

The most commonly used type parameter names are:

  • E – Element (used extensively by the Java Collections Framework)
  • K – Key
  • N – Number
  • T – Type
  • V – Value
  • S,U,V etc. – 2nd, 3rd, 4th types

You’ll see these names used throughout the Java SE API and the rest of this lesson.

Source: Generic Types (The Java Tutorials > Learning the Java Language > Generics (Updated))

iluwatar/java-design-patterns: Design patterns implemented in Java

Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. Design patterns can speed up the development process by providing tested, proven development paradigms. Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.

Source: iluwatar/java-design-patterns: Design patterns implemented in Java

Deeplearning4j: Open-source, distributed deep learning for the JVM

Deeplearning4j is the first commercial-grade, open-source, distributed deep-learning library written for Java and Scala. Integrated with Hadoop and Spark, DL4J is designed to be used in business environments, rather than as a research tool. Skymind is its commercial support arm.Deeplearning4j aims to be cutting-edge plug and play, more convention than configuration, which allows for fast prototyping for non-researchers. DL4J is customizable at scale. Released under the Apache 2.0 license, all derivatives of DL4J belong to their authors.By following the instructions on our Quick Start page, you can run your first examples of trained neural nets in minutes.

Source: Deeplearning4j: Open-source, distributed deep learning for the JVM

What are the key differences between Scala and Groovy? – Stack Overflow

They’re both object oriented languages for the JVM that have lambdas and closures and interoperate with Java. Other than that, they’re extremely different.Groovy is a “dynamic” language in not only the sense that it is dynamically typed but that it supports dynamic meta-programming.Scala is a “static” language in that it is statically typed and has virtually no dynamic meta-programming beyond the awkward stuff you can do in Java. Note, Scala’s static type system is substantially more uniform and sophisticated than Java’s.Groovy is syntactically influenced by Java but semantically influenced more by languages like Ruby.Scala is syntactically influenced by both Ruby and Java. It is semantically influenced more by Java, SML, Haskell, and a very obscure OO language called gBeta.Groovy has “accidental” multiple dispatch due to the way it handles Java overloading.Scala is single dispatch only, but has SML inspired pattern matching to deal with some of the same kinds of problems that multiple dispatch is meant to handle. However, where multiple dispatch can only dispatch on runtime type, Scala’s pattern matching can dispatch on runtime types, values, or both. Pattern matching also includes syntactically pleasant variable binding. It’s hard to overstress how pleasant this single feature alone makes programming in Scala.Both Scala and Groovy support a form of multiple inheritance with mixins (though Scala calls them traits).Scala supports both partial function application and currying at the language level, Groovy has an awkward “curry” method for doing partial function application.Scala does direct tail recursion optimization. I don’t believe Groovy does. That’s important in functional programming but less important in imperative programming.Both Scala and Groovy are eagerly evaluated by default. However, Scala supports call-by-name parameters. Groovy does not – call-by-name must be emulated with closures.Scala has “for comprehensions”, a generalization of list comprehensions found in other languages (technically they’re monad comprehensions plus a bit – somewhere between Haskell’s do and C#’s LINQ).Scala has no concept of “static” fields, inner classes, methods, etc – it uses singleton objects instead. Groovy uses the static concept.Scala does not have built in selection of arithmetic operators in quite the way that Groovy does. In Scala you can name methods very flexibly.Groovy has the elvis operator for dealing with null. Scala programmers prefer to use Option types to using null, but it’s easy to write an elvis operator in Scala if you want to.Finally, there are lies, there are damn lies, and then there are benchmarks. The computer language benchmarks game ranks Scala as being between substantially faster than Groovy (ranging from twice to 93 times as fast) while retaining roughly the same source size. benchmarks.I’m sure there are many, many differences that I haven’t covered. But hopefully this gives you a gist.Is there a competition between them? Yes, of course, but not as much as you might think. Groovy’s real competition is JRuby and Jython.Who’s going to win? My crystal ball is as cracked as anybody else’s.

Source: What are the key differences between Scala and Groovy? – Stack Overflow

Menginstall JDK pada Ubuntu secara manual

Untuk menginstall JavaSE JDK di Ubuntu, terlebih dahulu download jdk yang diinginkan di Pilih file bin untuk di install di Ubuntu. Setelah filenya selesai didownload rubah file permisionnya dengan

sudo chmod a+x [FILE_JDK].bin

Copy file tersebut folder yang inginkan, semisal ke /usr/lib/local/, kemudian jalankan dengan perintah


yang akan menghasilkan folder instalasi jdk yang akan kita sebut dengan [JAVA_HOME]. Supaya dapat dikenali Ubuntu sebagai suatu library, perlu dibuat link ke [JAVA_HOME]/bin/java dengan perintah

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/local/[JAVA_HOME]/bin/java" 0
sudo update-alternatives --set "/usr/bin/java" "/usr/lib/local/[JAVA_HOME]/bin/java"

dan jangan lupa untuk menambahkan

export JAVA_HOME
export PATH

di file .bashrc pada /home/[USER]/