Kayıtlar

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. ...

Pretenders, Contenders and Liars

Life is a way to the uncertainity. This is an exact fact. In this uncertain journey, we meet kinds of people of having different behaviours, and generally label them according to their behaviours. In this writing, i will try to write my understanding of three of these labels; pretenders, contenders and liars. Pretenders A pretender is a kind of people who pretends :) It does not do what it seems to do. It does what it does not seem to do. We frequently meet pretenders in our daily life. And if we catch a person pretending, then we feel that is not sincere. Okay, then here is a question sincerely to ask yourself; do you ever find yourself pretending ? Contenders A contender is a person who has a goal to reach and do not hesitate to fight for that goal. So a contender is sincere ? Absolutely yes, you may be completely opposite to a contender, but if you know that it's a contender, then you know that it's sincere in its behaviours. And sure it is, if you trus...

RPC or REST; Which one is best suited for your Web API ?

When we design an api for our software components, then a couple of confusing terms are just at the front of us. Let's first cope with the conceptual confusion about the terms in this question. What is an API ? API is the acronym for the Application Programming Interface. It is a group of methods  that is exported by a provider software components/modules  and is supplied to its consumer software components/modules and the messages(XML, JSON, etc.) of these method calls are transported accross the client and server sides. Web API In the context of web, an API is refered as a group of methods that is the web protocol HTTP is used for the communication  by transferring the messages,  generally of the form; XML or JSON format. Okay then, if a consumer is using an API; then it is communicating via a service provider with dependency to a contract defined by the API over some communication protocols such as HTTP and exchanging the messages in a s...

Spring Boot with H2

In this tutorial, we will examine the usage of the in-memory database h2 in a Spring Boot application. H2 is an in-memory database, we can use it for simple case-studies and quick show cases. Maven Dependencies This can be easily generated with Spring Starter. The dependency for Spring Data and JPA: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> The dependency for H2: <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> H2 Configuration Now, we can configure the database settings in application.properties file: spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.datasource.username=sa spring.datasource.password=password spring.h2.console.enabled...

Load Balancer

Resim
Websites may be in need of serving millions of incoming requests from clients. This high traffic leads us to scale the web application horizontally by adding more servers to the server pool. At this point, the network traffic should be directed to the servers in a way of well-balanced and this is called load balancing . A load balancer makes this balanced distribution of network traffic across servers. A load balancer may be of the form of a physical hardware device or a software. Load balancers mainly enable horizontally scaling with which the following benefits are implicitly gained: minimizes server response time maximizes throughput prevents bottlenecks avoids single points of failure  Load balancing algorithms Round Robin In Round robin load balancing; the requests are distributed sequentially to the servers. Round robin load balancing is easy to implement however it has a drawback that long-running requests are not taken into account and this lea...

Proxy Server

Resim
There are two kinds of proxy servers; forward proxy and reverse proxy. Forward Proxy A forward proxy is also known as proxy server or web proxy. Proxy servers are located in front of clients and provides managed access to outside of the internal network. In a typical scenerio; A client wants to access a website on the internet and makes a request over proxy. Why doesnot the client access directly ? Because the client is prevented direct connection to the internet for security concerns. The proxy executes some logic on the request decides whether to forward or not. The proxy forwards the request to where it's routed. The server to which the request is sent does not know about the client, it knows the proxy as the sender. The server responds back to the proxy. And the proxy route the response to the client. Use cases Enforcing security policies on clients in the internal network. Blocking access to certain websites. A blocked-ip-ranged client for a websi...