Nitin Agrawal
Contact -
  • Home
  • Interviews
    • Secret Receipe
    • InterviewFacts
    • Resume Thoughts
    • Daily Coding Problems
    • BigShyft
    • CompanyInterviews >
      • InvestmentBanks >
        • ECS
        • Bank Of America
        • WesternUnion
        • WellsFargo
      • ProductBasedCompanies >
        • CA Technologies
        • Model N India
        • Verizon Media
        • Oracle & GoJek
        • IVY Computec
        • Nvidia
        • ClearWaterAnalytics
        • ADP
        • ServiceNow
        • Pubmatic
        • Expedia
        • Amphora
        • CDK Global
        • CDK Global
        • Epic
        • Sincro-Pune
        • Whiz.AI
        • ChargePoint
      • ServiceBasedCompanies >
        • Altimetrik
        • ASG World Wide Pvt Ltd
        • Paraxel International & Pramati Technologies Pvt Ltd
        • MitraTech
        • Intelizest Coding Round
        • EPAM
    • Interviews Theory
  • Programming Languages
    • Java Script >
      • Tutorials
      • Code Snippets
    • Reactive Programming >
      • Code Snippets
    • R
    • DataStructures >
      • LeetCode Problems
      • AnagramsSet
    • Core Java >
      • Codility
      • Program Arguments OR VM arguments & Environment variables
      • Java Releases
      • Threading >
        • ThreadsOrder
        • ProducerConsumer
        • Finalizer
        • RaceCondition
        • Executors
        • Future Or CompletableFuture
      • Important Points
      • Immutability
      • Dictionary
      • URL Validator
    • Julia
    • Python >
      • Decorators
      • String Formatting
      • Generators_Threads
      • JustLikeThat
    • Go >
      • Tutorial
      • CodeSnippet
      • Go Routine_Channel
      • Suggestions
    • Methodologies & Design Patterns >
      • Design Principles
      • Design Patterns >
        • TemplatePattern
        • Adapter Design Pattern
        • Decorator
        • Proxy
        • Lazy Initialization
        • CombinatorPattern
        • RequestChaining
        • Singleton >
          • Singletons
  • Frameworks
    • Apache Velocity
    • Spring >
      • Spring Boot >
        • CustomProperties
        • ExceptionHandling
        • Issues
      • Quick View
    • Rest WebServices >
      • Interviews
      • Swagger
    • Cloudera BigData >
      • Ques_Ans
      • Hive
      • Apache Spark >
        • ApacheSpark Installation
        • SparkCode
        • Sample1
        • DataFrames
        • RDDs
        • SparkStreaming
        • SparkFiles
    • Integration >
      • Apache Camel
    • Testing Frameworks >
      • JUnit >
        • JUnit Runners
      • EasyMock
      • Mockito >
        • Page 2
      • TestNG
    • Blockchain >
      • Ethereum Smart Contract
      • Blockchain Java Example
    • Microservices >
      • Messaging Formats
      • Design Patterns
    • AWS >
      • Honeycode
    • Dockers >
      • GitBash
      • Issues
  • Databases
    • MySql
    • Oracle >
      • Interview1
      • SQL Queries
    • Elastic Search
  • Random issues
    • TOAD issue
    • Architect's suggestions
  • Your Views
package javaFeatures;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class MethodReferences {
 
 public int add(int a, int b) {
        return a + b;
    }
 
    public int mul(int a, int b) {
        return a * b;
    }
 
    public String lower(String a) {
        return a.toLowerCase();
    }
 
    public void printDate(Date date) {
        System.out.println(date);
    }
   
    public static boolean check(int value) {
     if(value > 100) {
      System.out.println("Value is greater than 100...");
      return true;
     }
     else {
      System.out.println("Value is lesser than 100...");
      return false;
     }
    }
   
    public void predicating(Predicate<Integer> pred, int a) {
     System.out.println("Before usage of Predicate with changed value...");
     a = 200;
     pred.test(a);
    }
 
    public void operBinary(BinaryOperator<Integer> operator, int a, int b) {
     System.out.println("About to apply the opration with changed values...");
     a = 5;
     b = 6;
        System.out.println(operator.apply(a, b));
    }
 
    public void operS(Function<String, String> stringOperator, String a) {
        System.out.println(stringOperator.apply(a));
    }
 
    public String operC(Supplier<GregorianCalendar> supplier) {
        return "Current date applied : " + supplier.get().getTime();
    }

   
    /**
     * In Below method both ways are shown, method reference & lambda expression
     */
    public static void main(String[] args) {
     MethodReferences mr = new MethodReferences();
     mr.operBinary((a, b) -> mr.mul(a, b), 1, 3);
//     mr.predicating((a) -> mr.check(a), 10);
     mr.predicating(MethodReferences::check, 10);
//     mr.operS(s -> s.toLowerCase(), "HELLO");
     mr.operS(mr::lower, "HELLO");
//     System.out.println(mr.operC(() -> new GregorianCalendar()));
     System.out.println(mr.operC(GregorianCalendar::new));
 }

}
Powered by Create your own unique website with customizable templates.