AddThis

Thursday 5 September 2024

Solving real time queries using java 8 features stream api with examples

package com.pse;


import java.util.ArrayList;

import java.util.Arrays;

import java.util.Comparator;

import java.util.DoubleSummaryStatistics;

import java.util.List;

import java.util.Optional;

import java.util.stream.Collectors;


/**

 * @author shailesh

 */

public class Java8Test {

static List<Employee> employeeList = new ArrayList<Employee>();

static {

employeeList.add(new Employee(111, "Jiya Brein", 32, "Female", "HR", 2011, 25000.0));

employeeList.add(new Employee(122, "Paul Niksui", 25, "Male", "Sales And Marketing", 2015, 13500.0));

employeeList.add(new Employee(133, "Martin Theron", 29, "Male", "Infrastructure", 2012, 18000.0));

employeeList.add(new Employee(144, "Murali Gowda", 28, "Male", "Product Development", 2014, 32500.0));

employeeList.add(new Employee(155, "Nima Roy", 27, "Female", "HR", 2013, 22700.0));

employeeList.add(new Employee(166, "Iqbal Hussain", 43, "Male", "Security And Transport", 2016, 10500.0));

employeeList.add(new Employee(177, "Manu Sharma", 35, "Male", "Account And Finance", 2010, 27000.0));

employeeList.add(new Employee(188, "Wang Liu", 31, "Male", "Product Development", 2015, 34500.0));

employeeList.add(new Employee(199, "Amelia Zoe", 24, "Female", "Sales And Marketing", 2016, 11500.0));

employeeList.add(new Employee(200, "Jaden Dough", 38, "Male", "Security And Transport", 2015, 11000.5));

employeeList.add(new Employee(211, "Jasna Kaur", 27, "Female", "Infrastructure", 2014, 15700.0));

employeeList.add(new Employee(222, "Nitin Joshi", 25, "Male", "Product Development", 2016, 28200.0));

employeeList.add(new Employee(233, "Jyothi Reddy", 27, "Female", "Account And Finance", 2013, 21300.0));

employeeList.add(new Employee(244, "Nicolus Den", 24, "Male", "Sales And Marketing", 2017, 10700.5));

employeeList.add(new Employee(255, "Ali Baig", 23, "Male", "Infrastructure", 2018, 12700.0));

employeeList.add(new Employee(266, "Sanvi Pandey", 26, "Female", "Product Development", 2015, 28900.0));

employeeList.add(new Employee(277, "Anuj Chettiar", 31, "Male", "Product Development", 2012, 35700.0));

}

public static void main(String[] args) {

// Query 3.1 : How many male and female employees are there in the organization?

employeeList.stream().collect(Collectors.groupingBy(Employee::getGender, Collectors.counting())).entrySet()

.forEach(System.out::println);

System.out.println();


// Query 3.2 : Print the name of all departments in the organization?

employeeList.stream().map(Employee::getDepartment).distinct().forEach(System.out::println);

System.out.println();


// Query 3.3 : What is the average age of male and female employees?

employeeList.stream()

.collect(Collectors.groupingBy(Employee::getGender, Collectors.averagingInt(Employee::getAge)))

.entrySet().forEach(System.out::println);

System.out.println();


// Query 3.4 : Get the details of highest paid employee in the organization?

Optional<Employee> employee = employeeList.stream()

.collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary)));

System.out.println(employee);

// Or

Optional<Employee> employee2 = employeeList.stream().max(Comparator.comparingDouble(Employee::getSalary));

System.out.println(employee2);

System.out.println();


// Query 3.5 : Get the names of all employees who have joined after 2015?

employeeList.stream().filter(e -> e.getYearOfJoining() > 2015).map(Employee::getName)

.forEach(System.out::println);

System.out.println();


// Query 3.6 : Count the number of employees in each department?

employeeList.stream().collect(Collectors.groupingBy(Employee::getDepartment, Collectors.counting())).entrySet()

.forEach(System.out::println);

System.out.println();


// Query 3.7 : What is the average salary of each department?

employeeList.stream()

.collect(

Collectors.groupingBy(Employee::getDepartment, Collectors.averagingDouble(Employee::getSalary)))

.entrySet().forEach(System.out::println);

System.out.println();


// Query 3.8 : Get the details of youngest male employee in the product

// development department?

Optional<Employee> youngestMaleEmployeeInProductDevelopmentWrapper = employeeList.stream()

.filter(e -> e.getGender().equals("Male") && e.getDepartment().equals("Product Development"))

.min(Comparator.comparingInt(Employee::getAge));

System.out.println(youngestMaleEmployeeInProductDevelopmentWrapper);

// Or

Optional<Employee> youngestMaleEmployeeInProductDevelopmentWrapper2 = employeeList.stream()

.filter(e -> e.getGender().equals("Male") && e.getDepartment().equals("Product Development"))

.collect(Collectors.minBy(Comparator.comparingInt(Employee::getAge)));

System.out.println(youngestMaleEmployeeInProductDevelopmentWrapper2);

System.out.println();


// Query 3.9 : Who has the most working experience in the organization?

Optional<Employee> mostWorkingExperienceEmployee = employeeList.stream()

.min(Comparator.comparingInt(Employee::getYearOfJoining));

System.out.println(mostWorkingExperienceEmployee);

// OR

Optional<Employee> mostWorkingExperienceEmployee2 = employeeList.stream()

.sorted(Comparator.comparingInt(Employee::getYearOfJoining)).findFirst();

System.out.println(mostWorkingExperienceEmployee2);

System.out.println();


// Query 3.10 : How many male and female employees are there in the sales and

// marketing team?

employeeList.stream().filter(e -> e.getDepartment().equals("Sales And Marketing"))

.collect(Collectors.groupingBy(Employee::getGender, Collectors.counting())).entrySet()

.forEach(System.out::println);

System.out.println();


// Query 3.11 : What is the average salary of male and female employees?

employeeList.stream()

.collect(Collectors.groupingBy(Employee::getGender, Collectors.averagingDouble(Employee::getSalary)))

.entrySet().forEach(System.out::println);

System.out.println();


// Query 3.12 : List down the names of all employees in each department?

employeeList.stream().collect(Collectors.groupingBy(Employee::getDepartment)).entrySet().forEach(e -> {

System.out.println(e.getKey());

for (Employee emp : e.getValue()) {

System.out.println(emp);

}

});

System.out.println();


// Query 3.13 : What is the average salary and total salary of the whole

// organization?

DoubleSummaryStatistics doubleSummaryStatics = employeeList.stream()

.collect(Collectors.summarizingDouble(Employee::getSalary));

System.out.println(doubleSummaryStatics.getAverage());

System.out.println(doubleSummaryStatics.getSum());

System.out.println();


// Query 3.14 : Separate the employees who are younger or equal to 25 years from

// those employees who are older than 25 years.

employeeList.stream().collect(Collectors.partitioningBy(e -> e.getAge() > 25)).entrySet()

.forEach(System.out::println);

System.out.println();


// Query 3.15 : Who is the oldest employee in the organization? What is his age

// and which department he belongs to?

employeeList.stream().max(Comparator.comparingInt(Employee::getAge)).ifPresent(System.out::println);

                //Query 3.16 : Sort employee in descending order based on salary employeeList.stream()         .sorted(Comparator.comparingLong(Employee::getSalary).reversed())         .collect(toList());


                //Query 3.17 : Find 10th highest salary employee employeeList.stream()         .sorted(Comparator.comparingLong(Employee::getSalary).reversed()) .skip(9) .limit(1)         .collect(toList());


//Find max number in the list of integers

List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);

Integer maxObj = numbers.stream().collect(Collectors.maxBy(Comparator.naturalOrder())).get();

System.out.println(maxObj);


//OR

Integer i = numbers.stream().sorted(Comparator.reverseOrder()).findFirst().get();

System.out.println(i);

//How do you find the frequency of element in an array

List<String> listOfStrings = Arrays.asList("Pen", "Eraser", "Note Book", "Pen", "Pencil", "Pen", "Note Book", "Pencil");

Map<String, Long> elementCountMap = listOfStrings.stream()

                                                       .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

//Or

IntStream.of( 1, 2, 3, 2, 1, 2, 3, 4, 2, 2, 2 )

   .boxed()

   .collect( Collectors.groupingBy( Function.identity(), Collectors.counting() ) ).entrySet().forEach(System.out::println);

   

//Sum number in a list

List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5);

Integer sum = integers.stream().mapToInt(Integer::intValue).sum();

//OR

integers.stream().collect(Collectors.summingInt(Integer::intValue));

//Or

integers.stream().reduce(0, Integer::sum);

//Find only duplicate numbers

List<Integer> numbers = Arrays.asList(new Integer[]{1,2,1,3,4,4});

numbers.stream().filter(i -> Collections.frequency(numbers, i) >1)

        .collect(Collectors.toSet()).forEach(System.out::println);

//OR

List<Integer> duplicates = IntStream.of( 1, 2, 3, 2, 1, 2, 3, 4, 2, 2, 2 )

   .boxed()

   .collect( Collectors.groupingBy( Function.identity(), Collectors.counting() ) )

   .entrySet()

   .stream()

   .filter( p -> p.getValue() > 1 )

   .map( Map.Entry::getKey )

   .collect( Collectors.toList() );

System.out.println(duplicates);

//Find distinct numbers in an array

int[] distinctArr = Arrays.stream(new int[] { 1, 2, 3, 2, 1, 2, 3, 4, 2, 2, 2 }).distinct().toArray();

Arrays.stream(distinctArr).forEach(System.out::println);

//Find distinct numbers in a list

Arrays.asList(new Integer[] { 1, 2, 3, 2, 1, 2, 3, 4, 2, 2, 2 }).stream()

.distinct().forEach(System.out::println);


                //Sort a map based on value

                Map<String, Integer> wordCounts = new HashMap<>();

wordCounts.put("USA", 100);

wordCounts.put("jobs", 200);

wordCounts.put("software", 50);

wordCounts.put("technology", 70);

wordCounts.put("opportunity", 200);

Map<String, Integer> sortedByCount = wordCounts.entrySet()

                .stream()

                .sorted(Map.Entry.comparingByValue())

                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1,                                 LinkedHashMap::new));

}

}


class Employee {

int id;

String name;

int age;

String gender;

String department;

int yearOfJoining;

double salary;


public Employee(int id, String name, int age, String gender, String department, int yearOfJoining, double salary) {

this.id = id;

this.name = name;

this.age = age;

this.gender = gender;

this.department = department;

this.yearOfJoining = yearOfJoining;

this.salary = salary;

}

public int getId() {

return id;

}

public String getName() {

return name;

}

public int getAge() {

return age;

}

public String getGender() {

return gender;

}

public String getDepartment() {

return department;

}

public int getYearOfJoining() {

return yearOfJoining;

}

public double getSalary() {

return salary;

}

@Override

public String toString() {

return "Id : " + id + ", Name : " + name + ", age : " + age + ", Gender : " + gender + ", Department : "

+ department + ", Year Of Joining : " + yearOfJoining + ", Salary : " + salary;

}

}

 

Monday 11 September 2023

100 AWS Services in Just One Line Each

 

100 AWS Services in Just One Line Each

  1. Amazon EC2: Virtual servers in the cloud.
  2. Amazon S3: Scalable object storage service.
  3. Amazon RDS: Managed relational database service.
  4. AWS Lambda: Serverless computing service.
  5. Amazon VPC: Virtual private cloud for network isolation.
  6. Amazon Route 53: Scalable DNS and domain registration service.
  7. Amazon CloudFront: Global content delivery network (CDN)
  8. AWS Elastic Beanstalk: Platform-as-a-Service (PaaS) for deploying applications.
  9. Amazon SNS: Pub/Sub messaging and mobile notifications service.
  10. Amazon SQS: Managed message queuing service.
  11. AWS Step Functions: Serverless workflow orchestration.
  12. Amazon DynamoDB: Managed NoSQL database service.
  13. AWS Fargate: Serverless compute engine for containers.
  14. Amazon ECR: Docker container registry.
  15. Amazon ECS: Container orchestration service.
  16. AWS CodeStar: Managed software development service.
  17. AWS CodeCommit: Private Git repository hosting.
  18. AWS CodeBuild: Managed build service.
  19. AWS CodeDeploy: Automated deployment service.
  20. AWS CodePipeline: Continuous delivery service.
  21. Amazon API Gateway: Create, publish, and manage APIs using this service.
  22. AWS AppConfig: Feature flag and application configuration service.
  23. Amazon Sagemaker: Managed machine learning platform.
  24. Amazon Comprehend: Natural language processing service.
  25. Amazon Lex: Conversational interfaces for applications.
  26. Amazon Polly: Text-to-speech service.
  27. Amazon Rekognition: Image and video analysis service.
  28. Amazon Textract: OCR and text extraction service.
  29. AWS Translate: Real-time text translation service.
  30. AWS Transcribe: Automatic speech recognition service.
  31. Amazon Connect: Cloud-based contact center service.
  32. Amazon WorkSpaces: Managed, secure Desktop-as-a-Service (DaaS).
  33. Amazon AppStream 2.0: Application streaming service.
  34. AWS Organizations: Centralized management of AWS accounts.
  35. AWS Control Tower: Automated landing zone setup and governance.
  36. AWS Config: Track resource inventory and changes.
  37. AWS CloudTrail: API activity logging and auditing.
  38. Amazon CloudWatch: Monitoring and observability for AWS resources.
  39. AWS Trusted Advisor: Infrastructure optimization recommendations.
  40. AWS Personal Health Dashboard: Personalized view of AWS service health.
  41. AWS Security Hub: Centralized view of security and compliance.
  42. Amazon Macie: Sensitive data discovery and protection.
  43. AWS Shield: Managed DDoS protection.
  44. AWS WAF: Web application firewall.
  45. Amazon GuardDuty: Continuous security monitoring and threat detection.
  46. AWS Key Management Service (KMS): Create and manage encryption keys.
  47. Amazon Inspector: Automated security assessment service.
  48. AWS Certificate Manager: Provision and manage SSL/TLS certificates.
  49. Amazon Cognito: User and identity management.
  50. AWS Directory Service: Managed Microsoft Active Directory.
  51. Amazon Elastic File System (EFS): Fully managed file storage service.
  52. Amazon Elastic Block Store (EBS): Block-level storage volumes for EC2 instances.
  53. AWS Storage Gateway: Hybrid cloud storage service.
  54. Amazon FSx: Fully managed file systems (Windows & Lustre).
  55. AWS Glue: Managed ETL (extract, transform, load) service.
  56. Amazon Redshift: Fully managed data warehouse service.
  57. Amazon EMR: Managed big data processing service.
  58. AWS Data Pipeline: Data movement and transformation service.
  59. AWS Lake Formation: Data lake management service.
  60. Amazon Athena: Serverless, interactive query service for data in S3.
  61. Amazon Kinesis: Real-time data streaming and analytics.
  62. Amazon Managed Streaming for Apache Kafka (MSK): Fully managed Apache Kafka service.
  63. AWS IoT Core: Managed IoT service for device connectivity and control.
  64. AWS IoT Device Management: Device organization and tracking for IoT.
  65. AWS IoT Analytics: IoT data analysis and processing.
  66. AWS IoT Greengrass: Local compute, messaging, and sync for IoT devices.
  67. AWS IoT Events: Event detection and response for IoT applications.
  68. AWS IoT SiteWise: Industrial data collection and monitoring.
  69. Amazon Elastic Kubernetes Service (EKS): Managed Kubernetes service.
  70. AWS Batch: Batch computing service for large-scale workloads.
  71. AWS Outposts: Extend AWS infrastructure and services to on-premises.
  72. AWS Snowball: Data transfer device for large-scale migrations.
  73. AWS Snowmobile: Exabyte-scale data transfer service.
  74. AWS Direct Connect: Dedicated network connection to AWS.
  75. AWS VPN: Virtual private network to securely access AWS resources.
  76. Amazon QuickSight: Business intelligence and visualization service.
  77. AWS Backup: Centralized backup service for AWS resources.
  78. AWS License Manager: Software license management service.
  79. AWS Service Catalog: Service catalogue for organizing and governing resources.
  80. Amazon Managed Blockchain: Managed blockchain network service.
  81. Amazon Quantum Ledger Database (QLDB): Ledger database with verifiable history.
  82. Amazon Elastic Inference: GPU-powered deep learning inference acceleration.
  83. Amazon Lightsail: Simplified compute, storage, and networking for basic applications.
  84. AWS Ground Station: Satellite data processing and analysis service.
  85. AWS AppConfig: Application configuration and feature flag management.
  86. AWS Chatbot: Monitor and interact with AWS resources via chat.
  87. AWS Cost Explorer: Visualize, understand, and manage AWS costs.
  88. AWS Marketplace: Marketplace for third-party software and services.
  89. AWS Migration Hub: Centralized service for application migration.
  90. AWS PrivateLink: Private access to services hosted on AWS.
  91. Amazon Elastic Transcoder: Media file transcoding service.
  92. AWS App Runner: Automatically build, deploy, and scale containerized applications.
  93. AWS Proton: Managed application delivery service for container and serverless applications.
  94. AWS RoboMaker: Robotics application development and simulation service.
  95. AWS Well-Architected Tool: Review workloads against best practices.
  96. AWS X-Ray: Distributed application tracing and analysis.
  97. Amazon Honeycode: Build web and mobile applications without programming.
  98. Amazon Chime: Communications service for meetings and chat.
  99. Amazon Pinpoint: Customer engagement and communication service.
  100. Amazon Kendra: Intelligent search service powered by machine learning.

Wednesday 7 April 2021

LDAP / LDIF fields / attributes meaning

LDAP attributes to field names

LDAP Attributes

Field Names

buildingname

Building

c

Country

cn

Full Name

co

Country

comment

Comment

commonname

Full Name

company

Company

description

Description

distinguishedname

Distinguished Name

dn

Distinguished Name

department

Department

displayname

Full Name

facsimiletelephonenumber

Facsimile

fax

Facsimile

friendlycountryname

Country

givenname

First Name

homephone

Home Telephone

homepostaladdress

Home Address

info

Information

initials

Middle Initial

ipphone

IP Telephone

l

City

mail

Email Address

mailnickname

User ID

rfc822mailbox

Email Address

mobile

Mobile Telephone

mobiletelephonenumber

Mobile Telephone

name

Full Name

othertelephone

Other Telephone

ou

Organizational Unit

pager

Pager

pagertelephonenumber

Pager

physicaldeliveryofficename

Office

postaladdress

Address

postalcode

Zip Code

postofficebox

Post Office Box

samaccountname

User ID

serialnumber

Serial Number

sn

Last Name

surname

Last Name

st

State

stateorprovincename

State

street

Street

streetaddress

Street

telephonenumber

Telephone

title

Title

uid

User ID

url

Other Web Page

userprincipalname

User ID

wwwhomepage

Main Web Page

Field names to LDAP attributes

Field Names

LDAP Attributes

Address

postaladdress

Address, Home

homepostaladdress

Building

buildingname

City

l

Comment

comment

Company

company

Country

cco friendlycountryname

Department

department

Description

description

Distinguished Name

distinguishedname dn

Email Address

mailrfc822mailbox

Facsimile

facsimiletelephonenumberfax

Information

info

Middle Initial

initials

Name, First

givenname

Name, Full

displayname name cn commonname name

Name, Last

snsurname

Office

physicaldeliveryofficename

Organizational Unit

ou

Pager

pager pagertelephonenumber

Post Office Box

postofficebox

Serial Number

serialnumber

State

st stateorprovincename

Street

street streetaddress

Telephone

telephonenumber

Telephone, Home

hometelephone

Telephone, IP

ipphone

Telephone, Mobile

mobile mobiletelephonenumber

Telephone, Other

othertelephone

Title

title

User ID

samaccountname uid userprincipalname mailnickname

Web Page, Main

wwwhomepage

Web Page, Other

url

Zip Code

postalcode

Solving real time queries using java 8 features stream api with examples

package com.pse; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.DoubleSummaryStatistics;...