Navigation Menu

Skip to content

josdem/java-workshop

Repository files navigation

CSV Transformer

How to read and write a CSV file using Apache Commons CSV

Read this as reference

To run the project

gradle test

Date And Time

A quick review to the java.util.Date API in Java 8

Read this as reference

To run the project

javac BetweenDays.java
java BetweenDays

javac DateOperations.java
java DateOperations

Excel Reader

How to read an Excel file using Apache POI

Read this as reference

To run the project

gradle test

Excel Filter Reader

How to read filtered rows in Excel file using Apache POI

Read this as reference

To run the project

gradle test

Hello AWS Lambda

Hello World using AWS Lambda

Read this as reference

To build the project

gradle buildJar

Java NIO Copy

Since Java 7 we can copy files in a easy way

Read this as reference

To build the project

javac FileCopier.java
java FileCopier

Properties Apache Commons

Generic configuration interface which enables a Java application to read configuration data

Read this as reference

To build the project

gradle buildJar

To run the project

java -jar properties-apache-commons-all-0.0.1.jar

S3 AWS Lambda

Read and copy files using AWS Lambda

Read this as reference

To build the project

gradle buildZip

To invoke the project

aws lambda invoke \
--invocation-type Event \
--function-name s3-aws-lambda \
--region us-west-1 \
--payload file://inputfile.txt \
outputfile.txt

Mailbox Reader

Configuration

In your computer's home directory: ${home}, create a directory called: .mailbox-reader then inside create a file called application.properties with this content

username=user@gmail.com
password=secret
pop3.server=pop.gmail.com
pop3.port=995
imap.server=imap.gmail.com
imap.port=993
ews.username=user@outlook.com
ews.password=secret
ews.server=https://exchange/EWS/Exchange.asmx
ews.protocol=https://

Build

gradle build

Run

 java -jar mailbox-reader-0.0.1-SNAPSHOT.jar

Features

  • This approach is using Gmail account with IMAP enabled (Settings > Forwarding and POP/IMAP)
  • Using Exchange Web Services EWS Java API
  • Read body email usgin text/plain as ContentType
  • Read body email using multipart/mixed as ContenType

Read this as reference

Stream

Stream interface is defined in java.util.stream package. In Java 8, collections will start having methods that return Stream. Streams support Aggregate Operations. The common aggregate operations are filter, map, reduce, find, match and sort.

Read this as reference

To build the project

javac ${JAVA_PROGRAM}.java
java -ea ${JAVA_PROGRAM}

Stream Filters

A stream represents a sequence of elements and supports different operations to perform calculations in those elements, here we review the filters:

Read this as reference

To build the project

javac ${JAVA_PROGRAM}.java
java -ea ${JAVA_PROGRAM}

Stream Collectors

How use collectors over streams to group by, concatenate, map and list.

Read this as reference

To run the project

javac ${JAVA_PROGRAM}.java
java -ea ${JAVA_PROGRAM}

Executors

How use Executors, Callable and Futures

Read this as reference

To run the project

javac ${JAVA_PROGRAM}.java
java ${JAVA_PROGRAM}

Generics

How we can use Generics in Java.

Read this as reference

To run the code:

javac ${JAVA_PROGRAM}.java
java -ea ${JAVA_PROGRAM}

To test the code:

gradle test

Functional Interfaces

A functional interface in Java is any with @FunctionalInterface annotation and with SAM(Single Abstract Method). It was introduced to facilitate Lambda expressions. Since a lambda function can only provide the implementation for one method, it is mandatory for the functional interfaces to have only one abstract method.

Read this as reference

To run the code

javac ConsumerExample.java
java ConsumerExample

To test the code using Gradle

gradle test

To test the code using Maven

mvn test

Lambda Expressions

Since Java 8 we have Lambda expressions which is a function defined under some interface contract and the main purpose is to implement functional programming in Java.

Read this as reference

To test the code using Gradle

gradle test

To test the code using Maven

mvn test

Using Optional

Once called a Billion-dollar mistake. NullPointerException is by far one of the most frequent exceptions in Java and since version 8 we can use it as a way to avoid this exception. Optional is a container that can has a value or not.

Read this as reference

To test

gradle test

About

Coding examples showing solutions to common Java project applications

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published