Java.Java8.What is stream in Java ?

✅ What is a Stream in Java?

A Stream is a sequence of elements that supports functional-style operations to process data.

You can think of a Stream as a pipeline of data that flows through map/filter/collect operations — without modifying the original source (like a list or array).

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What is stream in Java ?

Java.Java8.What is Optional?

Let’s talk about Optional — one of the most elegant additions in Java 8 to help us write cleaner, null-safe code.


✅ What is Optional in Java?

Optional<T> is a container object that may or may not hold a non-null value.

It’s Java’s answer to avoiding null checks and NullPointerException (NPEs).

📦 Where it lives:

import java.util.Optional;

🧠 Analogy:

Think of Optional<T> as a box:

  • If the box contains a value → use it
  • If the box is empty → handle it gracefully
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What is Optional?

Java.Java8.How do I call a static method of an interface?

✅ Syntax:

You must call it using the interface name, not an object or implementing class.

InterfaceName.methodName(args);
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.How do I call a static method of an interface?

Java.Java8.What is a static method of an interface?

✅ What Is a Static Method in an Interface?

A static method in an interface is a method that:

  • Belongs to the interface itself, not to the implementing class
  • Cannot be overridden
  • Can be used to define utility or helper methods related to that interface
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What is a static method of an interface?

Java.Java8.How do I call the default method of an interface in a class that implements this interface?

Calling a default method from an interface inside a class that implements it is straightforward, and it becomes especially important when there’s a conflict between multiple default methods.

✅ How to Call a Default Method in a Class

If you’re in a class that implements the interface, and you want to explicitly call the default implementation, use this syntax:

InterfaceName.super.methodName();

🧠 Example:

interface Greetable {
    default void greet() {
        System.out.println("Hello from Greetable");
    }
}

class Person implements Greetable {
    @Override
    public void greet() {
        System.out.print("Person says: ");
        Greetable.super.greet(); // Calls the default method
    }
}
new Person().greet(); // Output: Person says: Hello from Greetable
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.How do I call the default method of an interface in a class that implements this interface?

Java.Java8.What are the default methods of an interface?

✅ What Are Default Methods?

A default method is a method defined in an interface with a body using the default keyword.

🔧 Syntax:

public interface MyInterface {
    default void greet() {
        System.out.println("Hello from MyInterface");
    }
}

Default methods are optional to override in implementing classes

They provide concrete behavior inside interfaces — something that was not allowed before Java 8

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the default methods of an interface?

Java.Java8.What is StringJoiner?

✅ What is StringJoiner?

StringJoiner is a class in java.util that allows you to construct a sequence of characters separated by a delimiter, optionally with a prefix and suffix.

Think of it like a flexible alternative to StringBuilder when you’re building things like CSV rows, human-readable lists, or HTML attributes.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What is StringJoiner?

Java.Java8.What are the functional interfaces ObjDoubleConsumer, ObjIntConsumer, and ObjLongConsumer?

These interfaces:

  • Take two arguments: one of a generic object type T and one primitive (double, int, or long)
  • Return nothing (void)
  • Are used when you want to perform an action (consume values), without boxing the primitive
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces ObjDoubleConsumer, ObjIntConsumer, and ObjLongConsumer?

Java.Java8.What are the functional interfaces ToDoubleFunction, ToIntFunction, and ToLongFunction?

Let’s now explore the ToDoubleFunction<T>, ToIntFunction<T>, and ToLongFunction<T> functional interfaces. These are used when you want to map an object of type T to a primitive (double, int, or long) — without boxing.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces ToDoubleFunction, ToIntFunction, and ToLongFunction?

Java.Java8.What are the functional interfaces ToDoubleBiFunction, ToIntBiFunction, and ToLongBiFunction?

Excellent! These three interfaces are all part of Java’s primitive-specialized functional interfaces in the java.util.function package.

They are:

  • Bi-argument functions: take two inputs (T and U)
  • Return a primitive: double, int, or long
  • Designed to avoid boxing, making them faster and more memory-efficient than BiFunction<T, U, Double/Integer/Long>
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces ToDoubleBiFunction, ToIntBiFunction, and ToLongBiFunction?