Raja has Published 806 Answers

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

raja

raja

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

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

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

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

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

How to print the first character of each word in a String in Java?

raja

raja

Updated on 29-Aug-2019 14:49:49

A String class can be used to represent the character strings, all the string literals in a Java program are implemented as an instance of a String class. The Strings are constants and their values cannot be changed (immutable) once created.We can print the first character of each word in a string by ... Read More

When to use fillInStackTrace() method in Java?

raja

raja

Updated on 02-Aug-2019 12:52:21

The fillInStackTrace() is an important method of Throwable class in Java. The stack trace can be useful to determine where exactly the exception is thrown. There may be some situations where we need to rethrow an exception and find out where it is rethrown,  we can use the fillInStackTrace() method in such scenarios.Syntaxpublic ... Read More

How can we convert a hexadecimal value to a byte in Java?

raja

raja

Updated on 01-Aug-2019 12:50:08

A Byte class is a subclass of Number class and it can wrap a value of primitive type byte in an object. An object of type Byte contains a single field whose type is a byte. The important methods of Byte class are byteValue(), compare(), compareTo(), decode(), parseByte(), valueOf() and etc. We ... Read More

Can Enum implements an interface in Java?

raja

raja

Updated on 01-Aug-2019 11:01:00

Yes, Enum implements an interface in Java, it can be useful when we need to implement some business logic that is tightly coupled with a discriminatory property of a given object or class. An Enum is a special datatype which is added in Java 1.5 version. The Enums are constants, by default ... Read More

When can we call wait() and wait(long) methods of a Thread in Java?

raja

raja

Updated on 31-Jul-2019 13:56:22

Whenever the wait() method is called on an object, it causes the current thread to wait until another thread invokes the notify() or notifyAll() method for this object whereas wait(long timeout) causes the current thread to wait until either another thread invokes the notify() or notifyAll() methods for this object, or ... Read More

What is the use of StrictMath class in Java?

raja

raja

Updated on 31-Jul-2019 11:09:37

The java.lang.StrictMath is a final class and it is a subclass of Object class. The StrictMath class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. We need not create an instance for StrictMath class because all the methods in StrictMath class are static ... Read More

Advertisements