Ritesh 116

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1)Lambda Expression:

a)convert Fahrenheit to calsius


b)convert kilometers to miles

package calculator;
@FunctionalInterface
interface Converter {
double convert(double input);
}

public class Pract {


public static void main(String[] args) {
Converter fahrenheitToCelsius = (fahrenheit) -> (fahrenheit -
32) * 5.0/9.0;
Converter kilometersToMiles = (kilometers) -> kilometers *
0.621371;
double celsius = fahrenheitToCelsius.convert(100);
System.out.println("100 degrees Fahrenheit is " + celsius + "
degrees Celsius.");
double miles = kilometersToMiles.convert(100);
System.out.println("100 kilometers is " + miles + " miles.");
}

Output:

Aim : Assignment based Aspect Oriented Programming.


1) Write a program to demonstrate Spring AOP – before advice.
CODE:
MyAspect
package com.aop.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class MyAspect {
@Before("execution(* com.aop.services.PaymentServiceImpl.makePayment(..))")
public void printBefore() {
System.out.println("Payment started..............");
}
}
PaymentServiceImpl.java
package com.aop.services;
public class PaymentServiceImpl implements PaymentService {
public void makePayment(int amount) {
//Payment COde
System.out.println(amount +" - " + "Amount Debited…");
}
}
PaymentService.java
package com.aop.services;
public interface PaymentService {
public void makePayment(int amount);
}
config.xml FYMCA Div B Roll No 104
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<aop:aspectj-autoproxy />
<!-- bean definitions here -->
<bean name="payment" class="com.aop.services.PaymentServiceImpl" />
<bean name="myAspect" class="com.aop.aspect.MyAspect" />
</beans>
App.java
package com.aop;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.aop.services.PaymentService;
import com.aop.services.PaymentServiceImpl;
public class App
{
public static void main( String[] args )
{
ApplicationContext context=new
ClassPathXmlApplicationContext("com/aop/config.xml");
PaymentService paymentObject= context.getBean("payment",
PaymentService.class);
paymentObject.makePayment(350);
} FYMCA Div B Roll No 104
}

OUTPUT:

You might also like