Found 7442 Articles for Java

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

raja
Updated on 14-Jul-2020 12:48:28

323 Views

DoubleUnaryOperator is a functional interface defined in java.util.function package. This functional interface expects a parameter of type double as input but produces the output of the same type. DoubleUnaryOperator interface can be used as an assignment target for lambda expression and method reference. This interface contains one abstract method: applyAsDouble(), one static method: identity() and two default methods: andThen() and compose().Syntax@FunctionalInterface public interface DoubleUnaryOperator {  double applyAsDouble(double operand); }Example of Lambda Expressionimport java.util.function.DoubleUnaryOperator; public class DoubleUnaryOperatorTest1 {    public static void main(String[] args) {       DoubleUnaryOperator getDoubleValue = doubleValue -> { // lambda expression          return doubleValue * 2;       }; ... Read More

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

raja
Updated on 14-Jul-2020 12:25:24

494 Views

LongSupplier is a built-in functional interface from java.util.function package. This interface doesn’t expect any input but produces a long-valued output. Since LongSupplier is a functional interface, it can be used as an assignment target for lambda expression and method reference and contains only one abstract method: getAsLong().Syntax@FunctionalInterface public interface LongSupplier {  long getAsLong(); }Example of Lambda Expressionimport java.util.function.LongSupplier; public class LongSupplierLambdaTest {    public static void main(String args[]) {       LongSupplier supplier = () -> {     // lambda expression          return 75;       };       long result = supplier.getAsLong();       System.out.println(result);    } }Output75Example ... Read More

How to Install Rundeck on a Debian 8 (Jessie) Server

Sharon Christine
Updated on 22-Jan-2020 07:16:25

269 Views

Rundeck allows you to run commands/scripts on a remote computer. It is used to create a job by defining a single step or a workflow that can execute any set of commands, scripts, or tools on any number of local or remote nodes. Jobs can be triggered by the scheduler or on-demand via the web interface or API. This article explains about ‘How to install Rundesk on Debian 8 server’Rundeck is written in java programming language, so it requires you to install java in your machine. To install Java programming on Debian, use the following commands –$ sudo dpkg --add-architecture ... Read More

How to Install Java with Apt-Get on Ubuntu 16.04

Sharon Christine
Updated on 22-Jan-2020 06:15:40

1K+ Views

Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core a component of Sun Microsystems’ Java platform (Java 1.0 [J2SE]).The latest release of the Java Standard Edition is Java SE 8. With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. Ex − J2EE for Enterprise Applications, J2ME for Mobile Applications.The new J2 versions was renamed as Java SE, Java EE and Java ME respectively. Java is guaranteed to be a Write Once, Run Anywhere.This article explains about ‘How to ... Read More

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

raja
Updated on 14-Jul-2020 12:06:47

274 Views

LongPredicate is a functional interface defined in java.util.function package. This interface can be used mainly for evaluating an input of type long and returns an output of type boolean. LongPredicate can be used as an assignment target for a lambda expression or method reference. It contains one abstract method: test() and three default methods: and(), negate() and or().Syntax@FunctionalInterface interface LongPredicate {  boolean test(long value); }Example of Lambda Expressionimport java.util.function.LongPredicate; public class LongPredicateLambdaTest {    public static void main(String args[]) {       LongPredicate longPredicate = (long input) -> {    // lambda expression          if(input == 50) {       ... Read More

How to create a constructor reference for an array in Java?

Aishwarya Naglot
Updated on 20-Aug-2025 12:22:04

4K+ Views

In Java, a constructor refers to a special method within a class that is always executed automatically while creating an instance of the class using the new keyword. Its main purpose is initializing the object by providing its fields with initial values so that it is ready for use. A constructor shares the name of the class itself, has no return type, and can be overloaded so that there will be different ways of initializing the objects. If you don’t provide one, Java inserts a default no-argument constructor automatically. What is a Constructor Reference in Java? Constructor reference is like ... Read More

Difference between Object level lock and Class level lock in Java

Himanshu shriv
Updated on 21-Jan-2020 10:10:57

7K+ Views

In multithreading environment, two or more threads can access the shared resources simultaneously which can lead the inconsistent behavior of the system. Java uses concept of locks to restrict concurrent access of shared resources or objects. Locks can be applied at two levels −Object Level Locks − It can be used when you want non-static method or non-static block of the code should be accessed by only one thread.Class Level locks − It can be used when we want to prevent multiple threads to enter the synchronized block in any of all available instances on runtime. It should always be used ... Read More

How to implement a constructor reference with one or more arguments in Java?

Aishwarya Naglot
Updated on 20-Aug-2025 12:24:21

9K+ Views

In this article, we are going to learn about implementing a constructor reference with an argument or multiple arguments in Java. Constructor references in Java provide us with a concise way of creating new objects via method references. These are going to enable us to reference a constructor without running the constructor itself so the code looks cleaner and it will be more readable. What is a Constructor Reference? A method reference may also be used with Java 8 constructors. A constructor reference may be defined by employing the class name and a new keyword. The constructor reference may be ... Read More

Difference between HashTable and ConcurrentHashMap in Java

Alshifa Hasnain
Updated on 27-Jun-2025 18:11:39

8K+ Views

In this article, we will learn about the ConcurrentHashMap and HashTable in Java. First, we will know about ConcurrentHashMap, the syntax of ConcurrentHashMap, and an example after that will learn about HashTable, the syntax of HashTable, and an example. At the end, we will see a table showing the difference between ConcurrentHashMap and HashTable. What is ConcurrentHashMap in Java? ConcurrentHashMap is a class that was introduced in JDK 1.5. The ConcurrentHashMap is threadsafe as it allows multiple threads to read and write the data without locking the entire map. ConcurrentHashMap applies locks only at the bucket level, called a fragment, while ... Read More

Difference between EnumMap and HashMap in Java

Alshifa Hasnain
Updated on 16-Jun-2025 16:40:48

928 Views

In this article, we will learn about the EnumMap and HashMap in Java. First, we will know about EnumMap, the syntax of EnumMap, and an example after that will learn about HashMap, the syntax of HashMap, and an example. At the end, we will see a table showing the difference between EnumMap and HashMap. What is EnumMap? EnumMap is introduced in JDK 5. It is designed to use an Enum as a key in the Map. It is an implementation of the Map interface. All of the keys in the EnumMap should be of the same enum type. Keys cannot be ... Read More

Advertisements