JavaHub - A Responsive Website which demonstrates some of the latest concepts with implementation in Java

“It is far easier to design a class to be thread-safe than to retrofit it for thread safety later.” ― Brian Goetz, Java Concurrency in Practice


Some of the implementations :-

  • Java
  • Spring
  • Rest
  • Microservices

Thursday, 24 January 2019

// // Leave a Comment

Spring Boot 2

Spring Boot 2!!!

         - Made Developer Life Easier 


As typical definition says Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".

Let me elaborate Top 5 Features on 2.x Upgrade.

1.Simplified Security 
2.HTTP/2 Support
3.Quartz Scheduler
4.HikariCP Connection Pool
5.Developer Tools

1.Simplified Security 

How about using custom security in a simple and easy way!!! Yes it does

By default, everything is secured, including static resources and Actuator endpoints. If Spring Security is on the classpath, Spring Boot will add @EnableWebSecurity and rely on Spring Security’s content-negoation to decide which authentication mechanism to use. 

Example 

http
    .authorizeRequests()
        //If your /Foo and /Foo1 endpoints do not require authentication just
        .requestMatchers(EndpointRequest.to("Foo", "Foo1"))
            .permitAll()

//If our actuator endpoints to be protected by the ACTUATOR role then
        .requestMatchers(EndpointRequest.toAnyEndpoint())
            .hasRole("ACTUATOR")

.// If static resource locations needs to be open to all
        .requestMatchers(StaticResourceRequest.toCommonLocations())
            .permitAll()

//If our application endpoints are protected by the USER role
        .antMatchers("/**")
            .hasRole("USER")

etc


2.HTTP/2 Support


1996 Traditional http/1 was launched now web changed the world to support http/2 just add

server.http2.enabled=true


3.Quartz Scheduler


Quartzis a richly featured, open source job schedulinglibrary that can be integrated within virtually any Java application - from the smallest stand-alone application to the largest e-commerce system.

Starter Dependency can be added Both in-memory and JDBC stores can be configuredby this way

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>


4.HikariCP Connection Pool


The default connection pool has switched from Tomcat to HikariCP. If you used spring.datasource.type to force the use of Hikari in a Tomcat-based application, you can now remove that override. Similarly, if you want to stay with the Tomcat connection pool, simply add the following to your configuration
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

5.Developer Tools

The Default configuration when application restarts, a report showing the condition evaluation delta is logged.
To disable that logging of report add to configuration

spring.devtools.restart.log-condition-evaluation-delta=false



Thanks for Reading!!!!

Please do comment for queries :)

Read More

Monday, 10 December 2018

// // Leave a Comment

Serialization :1 min study

Serialization

•Its concept provided by Java Prog. Lang. to persist the data into file.
•Serialization means change the status of an objects in bit or byte.
•While Serialization use public static final serialVersionUID to match the exact sender or receiver.

Advantages

•Serialization make an object serializable it will transfer through network.
•Using FileInputStream and FileOutputStream as well as ObjectInputStream and     ObjectOutputStream we make an object serializable.
•It contains bits or bytes of information.
•No need to verification while accessing the data.
•Data will be in high security mode while transmission.
•Serializable is the marker interface in Java. It doesn’t contains any methods.
•Static and final keywords are not usable in serialization.
•Transient keyword used to hide the data while serialization.
•We can perform operation on the serialized data.

 Disadvantages

•Serialization only used in Java it is not universal.
•We can stored multiple object using collection but it is complex to read and write.
•It is used by only programmer.
•It may fail while transmission the data from different platform.
Read More
// // 2 comments

Soap Vs Rest



SOAP – “Simple Object Access Protocol”

          is an XML-based messaging protocol for exchanging information among computers.
SOAP provides data transport for Web services, uses WSDl rules "web services description language".

REST – “Representational State Transfer”

is an architectural style not a protocol, you can use HTTP or FTP ot any other medium for data transfer.
In REST data can be transferred in XMl Json binary or any other format.

SOAP
REST
SOAP is a protocol.
REST can be defined as an architectural style.
SOAP can't use REST since it is a protocol.
REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.
SOAP defines standards to be strictly followed.
REST does not define too much standards like SOAP.
SOAP requires more bandwidth and resource than REST.
REST requires less bandwidth and resource than SOAP.
SOAP permits XML data format only.
REST permits different data format such as Plain text, HTML, XML, JSON etc.
SOAP is less preferred than REST.
REST more preferred than SOAP.


Read More

Friday, 7 December 2018

// // Leave a Comment

Service Choreography vs Service Orchestration

Service Choreography:

Choreography can be simply defined where several services are distributed where no centralized point and all services work with comman aim without any micro management.
Ex :Event Driven Process


Lets look at above diagram where all services are interconnected and they communicate for particular goal. 

Service Orchestration:

In Orchestration there will be centralized service monitoring like micro management which combines all services with a fixed logic.
Ex:BPEL

Lets analyse the above diagram where centralized service will communicate with each service for a particular goal.

Individual Service Api x,Api y and Api z will not be connected with each other it will be connected to central service which acts as orchestration. 

Concluding with both we cannot compare best of both it is all based on Business Requirements.

Read More

Thursday, 6 December 2018

// // Leave a Comment

REST-Annotations @Provider & @Context


@Provider:


@Provider is used to register the provider classes with the JAX-RS Runtime.

Different provider interfaces/classes where we can use @Provider Annotation:
There are some list of provider interfaces/classes are there which are going to registed using @Provider annotation which are given below

1. ParamConverterProvider-Contract for a provider of ParamConverter instances
2. MessageBodyReader-Contract for a provider that supports the conversion of a stream to a Java type
3. MessageBodyWriter-Contract for a provider that supports the conversion of a Java type to a stream
4. ContextResolver-Contract for a provider that supplies context information to resource classes and other providers 

 @Context: 

Purpose of @Context:
In order to access the predefined obj's there are there with the JAX-RS we need to use @Context annotaion so that JAX-RS Runtime will injects into our Resource class.

Different places where we can use @Contex Annotation:

There are predefined obj's that are there in JAX-RS API where if we wanted to access those obj so let the JAX-RS Runtime to inject those predefined obj's (like UriInfo obj) into pur Resource class for this we need to annotate with @Context annotation.

We can use @Context to get the predefined obj's that are there in JAX-RS API some of them are
1. UriInfo-An injectable interface that provides access to application and request URI information
2. HttpHeaders-An injectable interface that provides access to HTTP header information
3. Providers interface-An injectable interface providing runtime lookup of provider instances
4. SecurityContext
5. Request [For caching purpose]
Read More
// // Leave a Comment

Microservices: Best Practices

Building Microservices then below are the best practices to build a service in simple and clear way. 

Top 1 :Try to Achieve Fully Restful API

Writing an API then follow RMM (The Richardson Maturity Model)

RMM is used for checking API is fully Restful or Not.

Fully Restful API ↑ 

-Level 3:When you use HATEOS
-Level 2:Use of right HTTP methods(Get,Put,Post,Delete)
-Level 1:Resource URI-Profile Request to internal URI
-Level 0:Swamp of POX (No HTTP Contents only XML)

Top 2:Use HATEOS-Hyper Media As Engine of Application State

{
    "id": "123",
    "name": "Employee",
    "links": [{
        "rel": "emp",
    }, {
        "rel": "empDetails",
    }]
}

So that everytime you specify URI  client cannot hardcode.

Top 3:Documenting API

Ex: Swagger

Always document API’s so that it can be used to share documentation among product managers, testers and developers, but can also be used by various tools to automate API-related processes.

Top 4: Continuous Delivery

Continuous Delivery is extension of Continuous Integration,where teams ensure that every change to the system is releasable.

Its Recommended.
Read More

Monday, 3 December 2018

// // Leave a Comment

RabbitMQ- Introduction & Installation

Introduction

In the world of Micro'Services', These independent services will talk or communicate each other
for communication among these services we need broker to forward the sent message.

RabbitMQ do exactly same that is forwards the received message.



Lets observe the above diagram where API-X sends message to API-Y via messaging queue or broker this will forward the same.

Installation

Step 1: Download and install Erlang from below available site .

              Download Erlang

Step 2: Download and install RabbitMq

             Download RabbitMq

Step 3: Open RabbitMQ command prompt which will be available in bin usually it will be in below                 path

            Programs\RabbitMQ Server             

Step 4: Run rabbitmq-plugins enable rabbitmq_management


Step 5: Start Server 
          
            rabbitmq-service start


Step 6: Open Browser and hit below url

            http://localhost:15672





Step 7: Username:guest  Password: guest



Finally installation DONE Successully!!!!!!!!!!

Thanks for reading. comments & suggestions always welcome :)
Read More