Posts

Private method in Java 9

Image
As we know till Java 7, we are not allowed to add any concrete function to the Interface, All the function should be abstract and must be implemented in Child class which is implementing the interface. i.e. an interface can only have Constant variable abstract method With Java 8, we can add static and default method as well in an Interface. Check my blog on Java 8 for more details. So, an Interface now can have Constant Variable Abstract Method Default Method Static Method and with Java 9, It become more powerful and now we can add private method and private static method. but why do we need private function in an Interface. Let’s understand this with an example. In above example, we can observe that all the default function has same code to create database connection (duplicate code) and fetching the data and database details is also exposed to outside the world. So over here, Private method will come to rescue. Che...

Access User Profile API via Google OAuth 2.0 Playground ?

Image
The OAuth Playground is an application/tool by Google for learning how OAuth works. It presents you with a three-step process for selecting the services you want to authorize, generating an access token, and making API requests. In OAuth terminologies, Google OAuth playground will act as a client Application which does contain client id, Client secret and OAuth Endpoints required to access Service provider. It also supports custom endpoints as well i.e. using Google OAuth playground you can connect to another service provider as well apart from Google like Salesforce. Resource Owner:  You Client Application:  Google OAuth 2.0 Playground Service Provider:  Google In this blog, I’ll only focus on Google API and will try to retrieve user profile via playground. Step 1: Hit https://developers.google.com/oauthplayground/ Step 2: You will see a list of scope using which you can access particular resources. As our aim is to fetch user profile so will...

Registering an Application with Facebook

Image
This guide walks you through the steps of registering an application to integrate with Facebook. Register a new application From  http://developer.facebook.com , click on "My Apps" at the top of the page to go to the application dashboard. The dashboard shows a list of applications that the developer has already created or you can create a new one by clicking on  Add a new App.   A dialog prompts you to name your application. Enter Display Name, Contact Email and Choose a category from drop down list and click on  Create App ID . After you click, Facebook performs a Captcha check to verify that you’re not setting up applications through an automated process. Once you’ve satisfied the verification process, your application is created. The next page you see is your application’s application page. Click on the  Settings  button and it will open you a setting page of your application. Now we can configure various det...

JWT: Symmetric and Asymmetric key Implementation

Image
Prerequisite : Understanding of JWT or read here to understand what is JSON Web token. As we already know that JWT is special because it is digitally signed and we can verify the authenticity of JWT using signature. Today, we will discuss on how we can actually sign this JWT using Symmetric and Asymmetric key. Symmetric key: Symmetric key uses the same key for the signature generation as well as at the time of token verification. So, extra precaution is required during the exchange of the secret key between sender and receiver. Use symmetric key if there is one sender and one receiver, the exchanging of the key will be easy.  Eg: One web application talking to the backend services. Asymmetric key: It uses a key pair. The key pair consists of a public key and a private key. JSON data will be signed using the private key and can be verified using the public key. Use Asymmetric key if you have one sender and multiple receivers as you cannot share the same key...

Synchronization in JAVA

Image
You should be aware of Synchronization if you are working on an application where multiple threads are accessing the same resources or else it will show you erroneous or unforeseen results. Imagine a scenario where you are doing the multiple transactions in your bank. I believe you don’t want one thread is updating your balance and in parallel, the other thread is reading your balance otherwise you will end up in error or unexpected results. Example 1: Public class HDFCBank {             Protected long balanace =1000;             Public void deposit( int amount) {                         this.balance = this.balance + amount;             } } Assume if two threads, A and B are executing t...

FAQ Questions on Spring Boot

How to control logging with Spring Boot? By default, the SLF4j Logging is included in the Spring Boot starter package. To enable logging, create a  application.properties  file in the root of the  resources  folder. 1. application.properties logging.level.org.springframework.web=ERROR logging.level.com.waheedtechblog=DEBUG # Logging pattern for the console logging.pattern.console= "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" # Logging pattern for file logging.pattern.file= "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" logging.file=/Users/waheed/application.log Similarly we can configure in application.yml as well. 2. application.yml logging:   level:     org.springframework.web: ERROR     com.waheedtechblog: DEBUG   pattern:     console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"     file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{3...