Category Archives: Java

Define Implementation at Runtime using Lambda Expression

import org.testng.annotations.Test; interface MathOperation { int operation(int a,int b); }   public class Lambda2 { @Test public void testLambda2() { MathOperation add=(int a,int b)->a+b; MathOperation mul=(int a,int b)->a*b; System.out.println(“Value after addition seen is “+add.operation(10, 20)); System.out.println(“Value after multiplication seen is … Continue reading

Posted in Java, Uncategorized | Leave a comment

Using Lambda Expression Java

import org.testng.annotations.Test; interface MultiplyByTwo { int Multiply(int num); } interface MathOperation { int operation(int a,int b); } interface Number { double getValue(); } interface Message { String getMessage(String msg); } public class Lambda2 { @Test public void testLambda2() { MathOperation … Continue reading

Posted in Java, Uncategorized | Leave a comment

Using unmodifiable list Java 9

package test;package test; import java.util.Collections;import java.util.Iterator;import java.util.List; public class listtest { public static void main(String[] args) { // TODO Auto-generated method stub List im=List.of(“one”,”two”,”three”); List imlist=Collections.unmodifiableList(im); imlist.add(“four”); Iterator itr=imlist.iterator(); while(itr.hasNext()) { System.out.println(itr.next()); } } } In this case if you … Continue reading

Posted in Java, Uncategorized | Leave a comment

Using List.of Java 9

package test;package test; import java.util.Iterator;import java.util.List; public class ListTest { public static void main(String[] args) { List im=List.of(); Iterator itr=im.iterator(); while(itr.hasNext()) { System.out.println(itr.next()); } } }

Posted in Java, Uncategorized | Leave a comment

Using Mockito and Testng in Java

I am using maven and have imported maven dependency for Mockito . import static org.mockito.Mockito.*; import java.util.List; import org.testng.annotations.Test; public class TestMockito { /** * Test Mockito using Java and TestNG. */ @Test public void testmock() { @SuppressWarnings(“unchecked”) List<String> list … Continue reading

Posted in Java, TestNG, Uncategorized | Leave a comment

Print Factorial of Number using Lambda Expression Java

import org.testng.annotations.Test; /** * Print Factorial of a Number using Lambda Expression Java * @author asharda * */ public class Factorial { interface Fact { int result(int n); } @Test public void testFactorial() { Fact f= (n) -> { int … Continue reading

Posted in Java, Uncategorized | Leave a comment

How to check if number is an even number using Lambda Expression -Java

import org.testng.annotations.Test; /** * Check if number is an even number using Lambda expression Java * @author asharda * */ public class TestLambdaExpression { interface MyNumber { boolean getVal(int n); } @Test public void testLambda() { MyNumber myNum; myNum= (n)-> … Continue reading

Posted in Java, Uncategorized | Leave a comment