Raja has Published 469 Articles

How to implement DoublePredicate using lambda and method reference in Java?

raja

raja

Updated on 16-Jan-2020 10:04:48

301 Views

DoublePredicate is a built-in functional interface defined in java.util.function package. This interface can accept one double-valued parameter as input and produces a boolean value as output. DoublePredicate interface can be used as an assignment target for a lambda expression or method reference. This interface contains one abstract method: test() and three default methods: and(),  or() and ... Read More

What are the rules to follow while using exceptions in java lambda expressions?

raja

raja

Updated on 20-Dec-2019 08:36:16

3K+ Views

The lambda expressions can't be executed on their own. It is used to implement methods that have declared in a functional interface. We need to follow a few rules in order to use the exception handling mechanism in a lambda expression.Rules for Lambda ExpressionA lambda expression cannot throw any checked ... Read More

How to pass a lambda expression as a method parameter in Java?

raja

raja

Updated on 19-Dec-2019 13:09:20

7K+ Views

A lambda expression is an anonymous or unnamed method in Java. It doesn't execute on its own and used to implement methods that are declared in a functional interface. If we want to pass a lambda expression as a method parameter in java, the type of method parameter that receives ... Read More

What kind of variables can we access in a lambda expression in Java?

raja

raja

Updated on 11-Dec-2019 12:30:52

1K+ Views

The lambda expressions consist of two parts, one is parameter and another is an expression and these two parts have separated by an arrow (->) symbol. A lambda expression can access a variable of it's enclosing scope. A Lambda expression has access to both instance and static variables of it's enclosing class and also it can ... Read More

How to write the comparator as a lambda expression in Java?

raja

raja

Updated on 06-Dec-2019 10:26:25

5K+ Views

A lambda expression is an anonymous method and doesn't execute on its own in java. Instead, it is used to implement a method defined by the functional interface. A lambda expression used with any functional interface and Comparator is a functional interface. The Comparator interface has used when sorting a collection of objects ... Read More

What is the data type of a lambda expression in Java?

raja

raja

Updated on 02-Dec-2019 09:14:51

1K+ Views

The lambda expressions have a very simple, precise syntax and provide flexibility to specify the datatypes for the function parameters. Its return type is a parameter -> expression body to understand the syntax, we can divide it into three parts.Parameters : These are function method parameters and match with the signature of ... Read More

Why the java file name should be always the same as a public class name?

raja

raja

Updated on 30-Jul-2019 22:30:26

18K+ Views

         In Java, the java file name should be always the same as a public class name.While writing a java program first it is saved as a ".java" file, when it is compiled it forms byte code which is a ".class" file as such that if we ... Read More

Can we access the instance variables from a static method in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

5K+ Views

We cannot directly access the instance variables within a static method because a static method can only access static variables or static methods.An instance variable, as the name suggests is tied to an instance of a class. Therefore, accessing it directly from a static method, which is not tied to ... Read More

Is it possible to assign a numeric value to an enum in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

864 Views

Yes, it's possible to assign a numeric value to an enum.Enum in Java is used to represent a list of predefined values. Most of the time, we probably not care about the associated value of an enum. However, there might be some times when we need to assign specific values ... Read More

Can an interface extend multiple interfaces in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

8K+ Views

Yes, we can do it. An interface can extend multiple interfaces in Java.Example:interface A {    public void test();    public void test1(); } interface B {    public void test();    public void test2(); } interface C extends A, B {    public void test3(); } class D implements ... Read More

Advertisements