• The current version is 8u152 • No more public updates after September 2018 • Introduced a lot of new features, some originally planned for Java 7 • Interface default and static methods • Lambda expressions • Stream API • DateTime API • forEach
only methods declarations were possible in interfaces • Introducing a new method in an interface forced all implementing classes to create an implementation • Default and static method solve this problem • Declared by using the default keyword
a expression • They replace anonymous inner classes • Lambda expressions consist of three parts: • An argument list, e.g. (int x, int y) • An arrow token, e.g. -> • A body, e.g. x * y • The list of arguments can be empty • Method expressions are lambda expressions that refer to a method by name
in a declarative way • A stream doesn’t have a fixed size, it can produce elements on demand • Can be found in the java.util.stream package • Simplifies multithreading using the parallelStream() method to run operations in parallel • Allow intermediate operations (iterate, filter, map, match) and terminal operations (reduce, collect) • It’s possible to create streams from pretty much everything (Arrays, Collections)
support for Date and Time handling • Immutability to guarantee thread-safety • Following a DDD approach • Classes for Date and Time are strictly separated and the API is much more concise • Support for different calendaring system that differ from ISO-8601
val now = LocalDateTime.now(); val today = LocalDate.now(); val yesterday1 = LocalDate.parse("2018-01-18"); val yesterday2 = LocalDate.now().minus(Period.ofDays(1)); val tomorrow = LocalDate.now().plus(Period.ofDays(1)); val newYork = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("America/New_York")); val day = Duration.between(today, yesterday1);
production-ready Spring applications. Spring Boot favours convention over configuration and is designed to get you up and running as quickly as possible. • The project is around since 2014 • The current version is 1.5.9 • Convention over configuration approach • Suitable for REST-based micro services and rapid prototyping • Annotations, annotations, annotations to remove the XML configuration and automate whenever possible
in src/main/resources • It’s possible to use .properties, .conf or .yaml files • Standard XML configuration, like Log4J, is parsed as well • Profile-specific configuration can also be defined in application-{profile}.properties • The current profile can be set in various ways: • Using spring.profiles.active=dev,psql in application.properties • As a JVM system parameter using -Dspring.profiles.active=dev,psql • As a environment variable using EXPORT spring_profiles_active=dev • Configuration can be profile-specific by using the @Profile annotation
objects inside the IoC container • Use @Configuration and @Bean to create or overwrite global components • Use @Component (or @Controller, @Repository, @Service etc.) for application components • When using custom folder structures, make sure to use @ComponentScan • To inject objects into other components, use the @Autowired annotation • Works for one constructor, fields or setter methods
or @RestController • @Controller should when returning (HTML) views • @RestController is @Controller plus @ResponseBody • Should be used when returning (JSON) resources • Can be annotated with @RequestMapping to define controller-wide parameters • Can be annotated with @Validated to enable validation for all request parameters and bodies that are constrained
Defines the HTTP method, parameters, headers and media types required for matching an action • Use @GetMapping, @PostMapping or @DeleteMapping for better readability • Use @ResponseStatus to define the default status code for an action • Use @PathVariable to bind URI parameters • Use @RequestBody to bind POST bodies to models • Uses Jackson by default to map requests/responses from and to JSON
handling components • Introduced in Spring 3.2 • Define a handler method with @ExceptionHandler method that matches the exception type and returns an HTTP/JSON response • The response can be fully customised • It’s possible to map several exceptions to the same handler
provides Java developers with an object/relational mapping facility for managing relational data in Java applications. • The specification is around since 2006 • The current version is 2.1, introduced in 2013 • It's a specification that describes the management of relational data in the Java platform • Consists of four different parts: • The API itself (javax.persistence package) • The JPQL (Java Persistence Query Language) • The Java Persistence Criteria API • Object/relational mapping metadata (lots of annotations)
• Hibernate • EclipseLink • ObjectDB • Apache OpenJPA • Spring Data makes it easier to work with different databases (SQL, NoSQL) • Spring Data JPA sits on top of Hibernate and JPA
relational database • Specified by the @Entity annotation • They must have a primary key, annotated with @Id • Various strategies for generated keys are available (AUTO, IDENTITY, SEQUENCE, TABLE) • For UUID use @GeneratedValue(generator = “system-uuid") and @GenericGenerator(name = "system-uuid", strategy = "uuid") • Underlying tables can be annotated using @Table(name = "app")
@Column annotation • The column name can be given or is taken for the field name • Various constraints can be added, for instance unique = true/false, nullable = true/false, insertable = true/false or updatable = true/false • Relations to other entities are defined using annotations like @OneToMany, @ManyToOne or @ManyToMany • These can be refined by using @JoinTable or @JoinColumns • Operations can be cascaded using @OneToMany(cascade = {CascadeType.ALL})
countBy are parsed for query expressions • Properties found in the method name are used as WHERE expressions • Expressions can be chained together using And or Or • Between, LessThan, GreaterThan or Distinct are also supported • Ordering the result set by using OrderBy plus Asc or Desc • Limiting the result set by using Top • Supports nested properties, e.g. findByDeveloperName(DeveloperName name)
given as a value • Uses the SpEL (Spring Expression Language) • Parameter binding is position-based by default • Uses named parameters to bind certain values • Declare manipulating queries by using @Modifying
@Query("SELECT a FROM App a WHERE a.appId = ?1 AND a.release = ?2") App findRelease(final UUID appId, final Integer release); @Query("SELECT a FROM App a WHERE a.developerId = :developerId") List<App> findByDeveloper(@Param("developerId") final UUID developerId); }
Uses a domain object with relevant fields being populated as a probe • Uses an example instance with a matcher to create actual queries • Doesn’t support nested or grouped properties • Only supports basic string matching (starts, ends, contains, regex) and exact matching for other types
App probe = new App(); probe.setAppId(UUID.fromString("505f3009-fdca-4570-a067-ceabfd571a66")); probe.setRelease(12); Example<App> example = Example.of(probe); // equals SELECT a FROM App a WHERE a.appId = ?1 AND a.release = ?2 App app = appRepository.findOne(example);
• Can be chained together using Specifications.and(), Specifications.or() or Specifications.not() • Allow for re-use of certain criteria • Allow for building queries using the domain language
that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again. Early access to future java features such as val, and much more. • The project is around since 2009 • The current version 1.16.20 • Currently supports Java version 1.6 - 1.8, support for 1.9 is being worked on • Can be integrate using Maven, Gradle, Ant • IDE support available for IntelliJ, Eclipse, Netbeans
tags.add("stay"); for (final String tag: tags) { System.out.println("The tag is: " + tag + "."); } val tags = new ArrayList<>(); tags.add("search"); tags.add("book"); tags.add("stay"); for (val tag: tags) { System.out.println("The tag is: " + tag + "."); }
one another • Ignores static fields • Use @NoArgsConstructor to generate a constructor with no parameters • Can be forced with final fields being initialised with empty values (null, 0, false) • Use @RequiredArgsConstructor to generate a constructor for all final and @NotNull fields • Use @AllArgsConstructor to generate a constructor for all fields
final String title; public HttpProblem(URI type, String title) { this.type = type; this.title = title; } public URI getType() { return type; } } @Data class HttpProblem { private final URI type; private final String title; }
final String title; public HttpProblem(URI type, String title) { this.type = type; this.title = title; } public URI getType() { return type; } } @Value class HttpProblem { private final URI type; private final String title; }
classes or methods • On a class, it’s @AllArgsConstructor and the constructor annotated with @Builder • On a method, it generates an inner static builder class, fields and setters for each parameter, a factory method for the builder and a factory method to create new instances • Fields not set during the build process will be null, 0, false
a class, very explicit and verbose) • Widely adopted, good tool support • Tools specifically targeting web development (like PHP, Symfony) feel more mature • Annotations are convenient, but hard to debug • Booting up a Java application can consume a lot of resources • But once it’s up, it actually runs pretty smooth • Local development using Docker and Java are not the best friends