How to write Java lambda Expression ?

java lambda

Lambda expression is a new and important feature of Java which was included in Java SE 8. It provides a clear and concise way to represent one method interface using an expression. It is very useful in collection library. It helps to iterate, filter and extract data from collection. Before lambda expression, anonymous inner class was the only option to implement the method.

In other words, we can say it is a replacement of java inner anonymous class. Java lambda expression is treated as a function, so compiler does not create .class file.

Functional Interface

Lambda expression provides implementation of functional interface. An interface which has only one abstract method is called functional interface. Java provides an anotation @FunctionalInterface, which is used to declare an interface as functional interface.

Why use Lambda Expression

To provide the implementation of Functional interface.
Less coding.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

interface Drawable{
public void draw();
}
interface Sayable{
public String say();
}
interface Sayable2{
public String say(String name);
}
interface Operation{
int operate(int a,int b);
}

public class LambdaExpressionExample {

public static void main(String[] args) {
int width=10;
//
//Drawable d=new Drawable() {
// @Override
// public void draw() {
// System.out.println(“.draw() “+ width);
// }
// };
//

//with lambda
Drawable d=()-> {
System.out.println(“.draw() “+ width);
};

d.draw();

//——————Whith out prammters——————————-
//Sayable s= new Sayable() {
// @Override
// public String say() {
// return “I have nothing to say.”;
// }
// };

Sayable s= ()->{
return “I have nothing to say.”;
};

System.out.println(s.say());
System.out.println(“==========================================”);
//————– Single Parameter——————————–

Sayable2 s2=(String saySomething)->{
return saySomething;
};

System.out.println(s2.say(“Welcome back”));
System.out.println(“==========================================”);
//————– Multiple Parameters————————

Operation addation=(a, b) ->{return a+b;};
Operation substraction=(a,b)->{return a-b;};
Operation diviation=(a,b)->{return a/b;};
Operation Multiplication=(a,b)->(a*b); //without return keyword-

System.out.println(addation.operate(10,20));
System.out.println(substraction.operate(10,20));
System.out.println(diviation.operate(10,20));
System.out.println(Multiplication.operate(10,20));
System.out.println(“==========================================”);
//————Foreach Loop——————-
List list=new ArrayList();
list.add(“ankit”);
list.add(“mayank”);
list.add(“irfan”);
list.add(“jai”);

list.forEach((x)->System.out.println(x));

list.forEach((n)->System.out.println(n));
System.out.println(“==========================================”);
list.forEach((item)->System.out.println(item));
System.out.println(“==========================================”);
list.forEach(item->{
if(“C”.equals(item)){
System.out.println(item);
}});
System.out.println(“==========================================”);
list.forEach(item->{
if(“C”.equals(item)){
System.out.println(item);
}});
System.out.println(“==========================================”);
list.forEach(System.out::println); //method reference
System.out.println(“==========================================”);
//Stream and filter
list.stream()
.filter(k->k.contains(“f”))
.forEach(System.out::println);
System.out.println(“==========================================”);

Map<String, Integer> items = new HashMap<>();
items.put(“A”, 10);
items.put(“B”, 20);
items.put(“C”, 30);
items.put(“D”, 40);
items.put(“E”, 50);
items.put(“F”, 60);

for (Map.Entry<String, Integer> entry : items.entrySet()) {
System.out.println( entry.getKey() + ” = ” + entry.getValue());
}
System.out.println(“==========================================”);
//with foreach and lambada
items.forEach((k,v)->{
if(k.contains(“A”))
System.out.println(k+” = “+v);
}
);
System.out.println(“==========================================”);

//passing lambda as argument
LambdaExpressionExample l =new LambdaExpressionExample();
l.x((a,b)-> { return a*b;});
}
public void x(Operation operation){
operation.operate(0, 0);
}

}

Advertisements
Posted in java, Uncategorized | Tagged , | Leave a comment

shell script for automating Start OAM,OID weblogic domain for SSO

#!/bin/bash

su oracle -c “screen -dm -S OIDInstance /u01/Oracle/Middleware/oid_instance/bin/opmnctl startall”
sleep 30
su oracle -c “screen -dm -S OHSInstance /u01/Oracle/Middleware/Oracle_WT1/instances/instance2/bin/opmnctl startall”
sleep 30

su oracle -c “screen -dm -S NodeManager /u01/Oracle/Middleware/wlserver_10.3/server/bin/startNodeManager.sh”

sleep 30

su oracle -c “screen -dm -S OIDAdminServer /u01/Oracle/Middleware/user_projects/domains/OIDDomain/bin/startWebLogic.sh”
sleep 30
su oracle -c “screen -dm -S ODSManagedServer /u01/Oracle/Middleware/user_projects/domains/OIDDomain/bin/startManagedWebLogic.sh wls_ods1”
sleep 30

su oracle -c “screen -dm -S OAMAdminServer /u01/Oracle/Middleware/user_projects/domains/OAMDomain/bin/startWebLogic.sh”
sleep 30
su oracle -c “screen -dm -S OAMAServer /u01/Oracle/Middleware/user_projects/domains/OAMDomain/bin/startManagedWebLogic.sh oam_server1”
sleep 30
su oracle -c “screen -dm -S EBSAccessGateAdminServer /u01/Oracle/Middleware/user_projects/domains/EBSAccessGate/bin/startWebLogic.sh”
sleep 30
su oracle -c “screen -dm -S EBSAccessGateManagedServer /u01/Oracle/Middleware/user_projects/domains/EBSAccessGate/bin/startManagedWebLogic.sh new_ManagedServer_1″

 

MYPATH_LOCATION=”/u01/Oracle/Middleware/user_projects/domains/”
/bin/echo “OS Server Restarted and start up script run at: $(date +’%Y-%m-%d %I:%M:%S %p’) ” >> $MYPATH_LOCATION/restartOSServer.log

Posted in Uncategorized, Weblogic | Tagged , , , , | Leave a comment

Bulk deletes all OID users created by DIP profile

How to reset OID to default like fresh installation

cd /u01/Oracle/Middleware/Oracle_OID/bin

export ORACLE_HOME= /u01/Oracle/Middleware/Oracle_OID/

./ldapsearch -h ssostageapp.test.com -p 3060 -D “cn=orcladmin” -w oracle11g -b “dc=albilad,dc=com” -S uid -s sub “(creatorsname=orclodipagentname=ad_oid,cn=subscriber profile,cn=changelog subscriber,cn=oracle internet directory)” cn >users_createdby_dip.ldif

cp users_createdby_dip.ldif /u01/Oracle/Middleware/Oracle_OID/ldap/bin/users_createdby_dip.ldif

export ORACLE_INSTANCE=/u01/Oracle/Middleware/oid_instance/

./opmnctl stopall

cd /u01/Oracle/Middleware/Oracle_OID/ldap/bin/

./bulkdelete connect=oiddb file=users_createdby_dip.ldif

enter passord pf oid DB schema

 

————————————————————

Reading entries under BaseDN “cn=wvdiitsd0009,ou=vdi,ou=xendesktops,ou=citrix,cn=users,dc=albilad,dc=com”…

————————————————————

 

————————————————————

Reading entries under BaseDN “cn=wvdiitsd0009″…

————————————————————

 

————————————————————

374 Entries have been deleted.

————————————

 

 

start OID

cd /u01/Oracle/Middleware/oid_instance/bin

./opmnctl startall

 

 

Posted in IDM | Leave a comment

Export All OID Users

Set environment variables

[oracle@erpsso bin]$ pwd

/u01/app/Middleware/Oracle_OID/ldap/bin

 

Posted in IDM | Leave a comment

Excel to UCM Batch loader Format Parser

Utility developed to convert Excel sheet contains metadata for files to be check-in at UCM to UCM batch loader format

patch loader format

link to download

http://www.mediafire.com/file/36z34rauj545keh/Excel_Parser.rar

Posted in Oracle ECM, UCM, Uncategorized | Tagged , , , , , | Leave a comment

UCM Custom Export Utility

download attached Jar file

link to download JAR

https://www.mediafire.com/file/23fj8ls9xqxc03q/UCMExportUtility.jar

Upload it to UCM server

Follow instructions as screen shoots

Posted in ECM, Oracle ECM, UCM, Uncategorized | Tagged , , | Leave a comment

Identity And Access Management installation part9

Configuring IAM Domain

Image | Posted on by | Tagged , , , , | Leave a comment