
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

1K+ Views
Type Inference states that the data type of any expression. For instance, a method return type or argument type can be understood automatically by the compiler. Types in the argument list can be omitted since java already know the types of the expected parameters for the single abstract method of functional interface.Syntax(var1, var2 …) -> { method body }In the below example, we can sort a String[] array by its last character.Exampleimport java.util.Arrays; public class TypeInferencingLambdaTest { public static void main(String[] args) { String[] names = {"Raja", "Jai", "Adithya", "Surya", "Chaitanya", "Ravi", "Krishna"}; Arrays.sort(names, (s1, ... Read More

189 Views
The from() method of JavaScript is used to return the Array object from any object with a length property or an iterable object.The syntax is as follows −Array.from(obj, mapFunction, val)Above, the parameter obj is the object to convert to an array, mapFunction is a map function to call, val is a value to use as this when executing the mapFunction.Let us now implement the from() method in JavaScript −Example Live Demo Demo Heading var arr1 = Array.from("PQRS"); var arr2 = Array.from("12345"); document.getElementById("test").innerHTML = arr1 ... Read More

797 Views
The findIndex() method of JavaScript is used to return the index of the first element in an array, if the condition is passed.The syntax is as follows −array.findIndex(function(currentValue, index, arr), thisValue)Let us now implement the findIndex() method in JavaScript −Example Live Demo Rank Result Finding the index of the player with highest rank. var points = [100, 150, 200, 250, 300, 400]; function topRank(points) { return points >= 400; } function display() { ... Read More

398 Views
The fill() function is a built-in function of JavaScript which is used to fill all the elements of an array with a static value. This function modifies the original array and returns the modified array. The fill() function of JavaScript is a simple and basic function used to fill an array with a specified function. In this article, you will understand the usage and functionality of the fill() function of JavaScript. Syntax The basic syntax of the fill() function is mentioned below: array.fill(val, start, end) Let's understand the parameters used in the fill() function. ... Read More

2K+ Views
An interface defined with only one abstract method is known as Functional Interface. It's not mandatory to mark the functional interface with @FunctionalInterface annotation, the compiler doesn't throw any error. But it’s good practice to use @FunctionalInterface annotation to avoid the addition of extra methods accidentally. If an interface annotated with @FunctionalInterface annotation and more than one abstract method then it throws a compile-time error.Syntax@FunctionalInterface interface interface_name { // only one abstarct method declaration }Example@FunctionalInterface interface Shape { void printArea(int x); } public class SquareTest { public static void main (String args[]) { Shape square ... Read More

2K+ Views
The lambda expression composed of two parts, one is an argument and another one is code or expression. These two parts have separated by an arrow operator "->". We can use different IDE's like Netbeans, IntelliJ, and Eclipse to debug the lambda expressions in Java. It is always possible to create multi-line lambda expressions and use print statements to display the values of a variable. The debugger can also provide additional information about the state of a java program. It allows some variables to be modified while the debugger is executing.Syntax(parameters) -> expression or (parameters) -> { statements; }Exampleimport java.util.*; public class LambdaDebugTest { ... Read More

12K+ Views
Lambda expression is an anonymous method that has used to provide an implementation of a method defined by a functional interface. In Java 8, it is also possible for the body of a lambda expression to be a complex expression or statement, which means a lambda expression consisting of more than one line. In that case, the semicolons are necessary. If the lambda expression returns a result then the return keyword is also required.Syntax([comma seperated argument-list]) -> { multiline statements }Exampleinterface Employee { String displayName(String s); } public class MultilineLambdaTest { public static void main(String[] s) { ... Read More

7K+ Views
The java.util.function package defines several in-built functional interfaces that can be used when creating lambda expressions or method references.Inbuilt functional interfaces:1) Function InterfaceThe Function interface has only one single method apply(). It can accept an object of any data type and returns a result of any datatype.Exampleimport java.util.*; import java.util.function.*; public class FunctionTest { public static void main(String args[]) { String[] countries = {"India", "Australia", "England", "South Africa", "Srilanka", "Newzealand", "West Indies", "Scotland"}; Function converter = (all) -> { // lambda expression String names = ""; ... Read More

329 Views
A constructor reference is just like a method reference except that the name of the method is "new". It can be created by using the "class name" and the keyword "new" with the following syntax.Syntax :: newIn the below example, we are using java.util.function.Function. It is a functional interface whose single abstract method is the apply(). The Function interface represents an operation that takes single argument T and returns a result R.Exampleimport java.util.function.*; @FunctionalInterface interface MyFunctionalInterface { Employee getEmployee(String name); } class Employee { private String name; public Employee(String name) { this.name = name; } public String ... Read More

2K+ Views
When we are using a lambda expression for java listener, we do not have to explicitly implement the ActionListener interface. Instead, we can use the below syntax.Syntaxbutton.addActionListener(e -> { // some statements });An ActionListener interface defines only one method actionPerformed(). It is a functional interface which means that there's a place to use lambda expressions to replace the code.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class LambdaListenerTest extends JFrame { public static void main(String args[]) { new LambdaListenerTest(); } private JButton button; public ClickMeLambdaTest() { setTitle("Lambda Expression Test"); button = ... Read More