Kayıtlar

Java 14 New Features

Java SE 14 was released in March 2020. The full list of new features in JDK 14 can be found here: https://openjdk.org/projects/jdk/14/   In this tutorial, we will look over some of these new features and examine some of them. 1. JEP 305: Pattern Matching for instanceof (Preview) With this JEP, instanceof now allows casting of the checked object to a variable. Before Java 14: if (obj instanceof String) { String s = (String) obj; // use s } With Java 14: if (obj instanceof String s) { // can use s here } else { // can't use s here } 2. JEP 345: NUMA-Aware Memory Allocation for G1 This JEP i mproves G1 performance on large machines by implementing NUMA-aware( non-uniform memory access ) memory allocation. Use the  +XX:+UseNUMA option to enable it. 3. JEP 358: Helpful NullPointerExceptions This JEP  improves the usability of  NullPointerException  generated by the JVM by describing precisely which variable was  null . Let's look over the follo...

Java 13 New Features

Java SE 13 was released in September 2019. The full list of new features in JDK 13 can be found here: https://openjdk.java.net/projects/jdk/13/ In this tutorial, we will look over some of these new features and examine some of them. 1. JEP 350: Dynamic CDS Archives Application Class Data Sharing was introduced with JEP 310, Java 10. It allows class loaders to load archived classes with a pre-generated class-data archive file and improves the startup performance.  JEP-350 simplifies the generation of CDS archive files directly from the archive file, instead of providing a list of classes. Create a CDS archive file of a jar file: java -XX:ArchiveClassesAtExit=myapp.jsa -cp myapp.jar MyApp Run a jar file with an existing CDS archive file: java -XX:SharedArchiveFile=myapp.jsa -cp myapp.jar MyApp 2. JEP 351: ZGC: Uncommit Unused Memory Performance improvement for the new ZGC collector introduced in Java 11 with JEP 333. With this JEP, unused heap memory is now being returned to the oper...

Java 12 New Features

Java SE 12 was released in March 2019. The full list of new features in JDK 12 can be found here: https://openjdk.org/projects/jdk/12/   In this tutorial, we will look at some of these new features and examine some of them. 1. JEP 189:  Shenandoah: A Low-Pause-Time Garbage Collector (Experimental) Shenandoah is a new garbage collection (GC) algorithm which reduces GC pause times,  independent of heap size. This GC algorithm is experimental so in order to use it with Java 12, you have to enable it : -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC 2. JEP 325:  Switch Expressions (Preview) This JEP extends the switch statement to be used as either a statement or an expression. Meaning that we can now return a value from a switch expression. Before Java 12, we can return a value by assigning it to a variable: String getColor(int num) { String result = ""; switch (number) { case 1, 2, 3: result = "red, green or blue"; bre...

Java 11 New Features

Java SE 11 was released in September 2018. The full list of new features in JDK 11 can be found here: http://openjdk.java.net/projects/jdk/11/   In this tutorial, we will look at some of these new features and examine some of them. 1. JEP 181: Nest-Based Access Control Java 11 introduces the concept of nestmates. The main class and the types within that form a nest. Members of a nest are called nestmates of each other. JVM allows access to private members between nestmates. However, before Java 11, accessing to private members between nestmates over reflection api is denied. The JEP solves this problem. 2. JEP 318: Epsilon: A No-Op Garbage Collector Epsilon is a No-Op Garbage Collector which does collect nothing and when the heap is full then it will shut down the jvm. It could be used for testing use-cases.  Epsilon GC is experimental and could be used with the following jvm parameters: -XX:+UnlockExperimentalVMOptions -XX:+UseEp...

JLS, JSR, JEP

Groups  Individuals and organisations with a mutual interest around a broad subject or a specific body of code. Some examples are Security, Networking, Swing, and HotSpot. Projects Efforts to produce a body of code, documentation or other effort. Must be sponsored by at least one group. Recent examples are Project Lambda, Project Jigsaw, and Project Sumatra. JLS (Java Language Specification) This is a specification for the Java Language. The JLS specifies the syntax for the Java programming language and other rules that say what is or is not a valid Java program. It also specifies what a program means; i.e. what happens when you run a (valid) program. https://docs.oracle.com/javase/specs/index.html JEP (Java Enhancement Proposal) A JEP is a document that is proposing an enhancement to Java core technology. These are proposals typically for enhancements that are not ready to be specified yet. JEPs allow promoting a new specification informally before or in parallel to the JCP, when ...

Java EE Annotations

JSR 250 ( Common Annotations ) Since Java EE 5 (May 11, 2006) & Java SE 6 All non-Java EE JSR 250 annotations were added to the Java SE with version 6 (Generated, PostConstruct, PreDestroy, Resource, Resources). Yellow ones are security-related annotations. javax.annotation package Annotation Description @ Generated Marks sources that have been generated @ Resource Declares a reference to a resource, e.g. a database @ Resources Container for multiple Resource annotations @ PostConstruct Is used on methods that need to get executed after dependency injection is done to perform any initialization. @ PreDestroy Is used on methods that are called before the instance is removed from the container @ Priority Is used to indicate in what order the classes should be used. For, e.g., the Interceptors specification defines the use of priorities on inte...

Dependency Injection In Java and CDI

Dependency injection(DI) is one of the key techniques that enables a class or module to be injected into another, which also enables us to apply the principal of seperation of concerns via enabling a way of entity association and making wiring easy. Along with Java EE 5, dependency injection was made of a part of the specification with JSR 250 (Common Annotations). For basic usages of injection, it has been a good start for Java platform especially with the annotations; @ManagedBean and @Resource. Since Java EE 6, JSR 330 (Dependency Injection for Java) was introduced and the frequently used annotations like @Inject and @Named were made available. And ultimately, Contexts and Dependency Injection was also introduced with Java EE 6 which is built on top of JSR 330. Comparing to DI, CDI additionally provides an easy to use event mechanism, decorators and interceptors to add functionality to beans. Since Java EE 5 with the EJB 3.0 specification, Java EE also provides injection for E...

Configuring Spring Boot Application with Maven

You can build and manage your Spring Boot applications with Maven or Gradle. In this article we will explore the basics of maven configuration for Spring Boot applications. When we generate a Spring Boot application with Spring Initializr or Spring Boot CLI, a template Spring Boot project is generated for us having the selected dependencies. Let's examine the sections of the generated pom.xml. 1.Parent Pom In the heart of Spring Boot is inheriting the defaults from predefined configurations and that is the usage of starter pom files. A starter pom file includes convenient dependencies and versions in sync for your application; and when you import that starter you would automatically have the dependencies defined in that starter pom file. <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> </parent> In...

Spring Components & Auto Scanning & Configuration

Spring managed beans are declared with the stereotype annotations specialized from @Component or with the @Component annotation itself. When you declare a class with @Component[+derived] annotations, that bean is detected by Spring, via component scanning or explicitly wiring, and put into the ApplicationContext. 1. Component Scanning In a Spring application, you can declare your beans manually inside the bean configuration file, but most probably, auto scanning of components is the preferred way of registering your beans into the application context. You can configure auto scanning in bean configuration file or with the annotation. 1.1 Enable Auto-Scanning in Bean Configuration File This is available since Spring 2.5: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="ht...

Servlet

In Java EE world, Servlet simply is a web technology with which we can receive and handle the HTTP requests, create HTTP response and return that response back to the client. Servlet technology makes a basis for other Java web technologies on top of which other frameworks put their extensions. For example JSP, JSF, Spring MVC are such technologies which are uses Servlet technology at behind.  Servlets run on a web container such as Tomcat which provides the services on Java EE technology stack .  What is a servlet ? Servlet simply makes an object having HTTP-server functionality when its class extends HttpServlet class. A servlet is mapped to a URL to which clients request HTTP requests made to the URL is directed to the corresponding Servlet object Servlet implementation receives the request in the form of GET, POST, PUT or DELETE Servlet implementation runs a business logic and prepares an HTTP response and sends it back to the client just an HTTP server does Lif...

The Convergence of OpenJDK and the Oracle JDK

Resim
In 2018, Oracle changed the license of their JDK. Instead of a single JDK build available both for commercial and free users, they offered two different JDK builds: Oracle JDK (commercial), which can be used in development and testing for free, but you have pay to use it in production. Oracle Open JDK (open source), which can be used in any environment for free. JDK Builds There is only one set of source code for the JDK. It is hosted in Mercurial at OpenJDK. Anyone can take the source code, produce a build, and post it. So, Oracle created a certification process that should be used to ensure the build is valid. This certification is run by the Java Community Process, which provides a Technology Compatibility Kit (TCK or JCK as Java). If an organization produces an OpenJDK build that passes the TCK then that build can be described as "Java SE compatible". The most popular and famous builds are distributed by Red Hat, Azul and community-led Adopt OpenJDK. ...