Friday, July 6, 2018

Integrate Keycloak with Spring Security

Keycloak can be very easily integrate with Spring Security. In this post I'm going to demonstrate, How to integrate Keycloak with Spring Security and How it works with Single Sign on.

If you are familiar with Spring Security, I think you may know about the Security Configuration file which extends WebSecurityConfigurerAdapter Similar to this, we can use KeycloakWebSecurityConfigurerAdapter to integrate Keycloak with Spring Security. If you follow Keycloak documentation, you will be able to find the Spring Security Adapter in Securing Apps tab. We have to follow few steps.
  • Add Keycloak Spring Security dependency in pom.xml
  • Add Keycloak configuration file which annotated @KeycloakConfiguration
  • Add Keycloak properties to application.properties file.
Lets create a very simple Spring Boot application as a web client. Here I use FreeMarker templates.

Project Structure




pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>com.example</groupId>
 <artifactId>product-app</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>

 <name>product-app</name>
 <description>Demo project for Spring Boot</description>

 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.3.RELEASE</version>
  <relativePath/>
 </parent>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
  <keycloak.version>3.4.2.Final</keycloak.version>
 </properties>

 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-freemarker</artifactId>
  </dependency>
  <dependency>
   <groupId>org.keycloak</groupId>
   <artifactId>keycloak-spring-boot-starter</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
  </dependency>
 </dependencies>

 <dependencyManagement>
  <dependencies>
   <dependency>
    <groupId>org.keycloak.bom</groupId>
    <artifactId>keycloak-adapter-bom</artifactId>
    <version>${keycloak.version}</version>
    <type>pom</type>
    <scope>import</scope>
   </dependency>
  </dependencies>
 </dependencyManagement>

 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>

</project>


ProductController.java

package com.example.productapp.controller;

import com.example.productapp.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ProductController {

    @Autowired
    private ProductService productService;

 @GetMapping(path = "/products")
 public String getProducts(Model model){
  model.addAttribute("products", productService.getProducts());
  return "products";
 }

 @GetMapping(path = "/logout")
 public String logout(HttpServletRequest request) throws ServletException {
  request.logout();
  return "/";
 }
}


ProductService.java

package com.example.productapp.service;

import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;

@Service
public class ProductService{

    public List getProducts(){
        return Arrays.asList("Mazda","Toyota","Audi");
    }
}


SecurityConfig.java

package com.example.productapp.security;

import org.keycloak.adapters.KeycloakConfigResolver;
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
import org.keycloak.adapters.springsecurity.KeycloakConfiguration;
import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider;
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper;
import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;

@KeycloakConfiguration
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {

 @Autowired
 public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
  KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
  keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
  auth.authenticationProvider(keycloakAuthenticationProvider);
 }

 @Bean
 @Override
 protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
  return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
 }

 @Bean
 public KeycloakConfigResolver keycloakConfigResolver(){
  return new KeycloakSpringBootConfigResolver();
 }

 @Override
 protected void configure(HttpSecurity http) throws Exception{
  super.configure(http);
  http.authorizeRequests()
    .antMatchers("/products*").hasRole("user")
    .anyRequest().permitAll();
 }
}


application.properties file

server.port=8090
keycloak.enabled=true
keycloak.auth-server-url=http://localhost:8080/auth
keycloak.realm=api
keycloak.resource=client1
keycloak.public-client=true

index.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Home</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
</head>

<body class="text-center">

<div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">
    <main role="main" class="inner cover">
        <h1 class="cover-heading">Apache Keycloak SSO demonstration</h1>
        <p class="lead">
        </p>
        <p class="lead">
            <a href="/products" class="btn btn-lg btn-secondary">Search products</a>
        </p>
    </main>
</div>

</body>
</html>


products.ftl

<#import "/spring.ftl" as spring>

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Keycloak</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
          integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

</head>

<body class="text-center">
<div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">

    <main role="main" class="inner cover">
        <h1 class="cover-heading">Apache Keycloak SSO demonstration</h1>

        <div style="width: 18rem; padding: 10px; display: block; margin-left: auto;margin-right: auto">
            <ul class="list-group">
                <#list products as product>
                    <li class="list-group-item">${product}</li>
                </#list>
            </ul>
        </div>

        <p class="lead">
            <a href="/logout" class="btn btn-lg btn-secondary">Logout</a>
        </p>
    </main>
</div>

</body>
</html>



Configure Keycloak server

I already configured Keycloak in this post. Since this is a client web application, we have to use Access type as public in Keycloak client configuration settings. Public clients do not require a client secret. 

Click to enlarge 

You have to do the same thing here,you can use any Realm name and client name for Keycloak configurations and you can use same data in Keycloak properties in application.properties file.

Run your application

Start the Keycloak server and run Spring Boot application. In my application Keycloak server is running on port 8080 and Spring Boot application is running on port 8090. 





Once you click on Search products, you will be redirected to Keycloak login screen. Because we have secured /products* URL pattern.


Once you provide authentication details, you will be able to access the secured content. 



Now you can see how Keycloak works with Spring Security. Lets see how we can use it on Single Sign On (SSO).

Keycloak with Single Sign On

You can create same kind of another application which is running on another port. application.property file and service file are different.

application.properties file

server.port=8092
keycloak.enabled=true
keycloak.auth-server-url=http://localhost:8080/auth
keycloak.realm=api
keycloak.resource=client2
keycloak.public-client=true


As you can see keycloak.realm is same for both applications (api), but keycloak.resource is different (client1, client2)

ProductService.java

package com.example.productapp.service;

import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;

@Service
public class ProductService{
    public List getProducts(){
        return Arrays.asList("Apple","Sony","Nokia", "Mi");
    }
}

And here Service is also different. Then run this Spring Boot application parallel with last application. Now two applications are running on port 8090 and 8092. Keycloak server is also running on port 8080.

Then you can try http://localhost:8092/products and you will be able to access this secured endpoint without going to Keycloak login page.  




Now you can see how SSO works with Keycloak and Spring Security. Here is the Git repository related to this project.

git clone https://github.com/raviyasas/SpringBoot-Keycloak-SpringSecurity-demo.git




Tuesday, June 26, 2018

Customizing Keycloak themes

When you integrating Keycloak with your web application, you may think to customize the default Keycloak theme. Keycloak templates are written using FreeMarker templates. You can customize it very easily. 

First you need to login as admin.




Go to Realm settings and select Themes tab.




Now you can see some options about themes and language support. There are several options to change the default theme. It can be changed the Login theme, Account theme, Admin console theme…etc. By default, two themes are provided (base and keycloak) for each option.

Before adding new themes

  • Before adding new themes, some configurations need to be done.
  • According to Keycloak documentation theme caching and template caching can be disabled. This allows user to edit themes without restarting the Keycloak server.
  • To change this, go to the standalone directory and then go inside configuration.
                    Keycloak -> standalone -> configuration -> standalone.xml
  • There are several files, but only standalone.xml should be changed. 
  • Please change it as follows


But please remember to re-enable it on production 

Add new themes

  • New themes can be added where Keycloak server is installed.
  • Basically Keycloak server looks like this. Please refer following image.

New themes should be added to themes directory.

  • By default, three Themes are available (base, keycloak and keycloak-preview)
  • Base theme consists of basic template files for each page without styles. It acts as the parent.

  • Keycloak theme extends Base theme and it has some specific styles.
  • Documentation says not to edit preloaded themes, instead create your own theme and extends the base theme according to your requirements.
  • You can change themes for account, admin, email, login and welcome pages. Above directory names should be exactly same. You cannot change those directory names.


Create your own theme

Let’s create a new theme called “myTheme”. In this theme I am going customize the login page. Create a folder inside the Theme directory and that folder name becomes the name of the theme. Here is the flow. Please use exact words for directories and files.
  1. Go to Keycloak then themes
  2. Create a directory called “myTheme”. This will be the theme name.
  3. Go to myTheme directory
  4. Create a directory called login. This specify that you are going to change the login theme. 
  5. Go inside of login directory
  6. Create a directory called resources and create a property file called theme.properties. Resources directory contains all resources files such as styles and images. 
  7. theme.properties file contains property definitions.
  8. Go inside of the resources directory and create two directories called css and img. 

What is theme.property file

theme.property file consists some basic configuration things.
  1. Parent class (parent=keycloak) 
  2. Where style sheets are located (styles=css/styles.css) 
  3. Keycloak tags related to Bootstrap tags (kcHtmlClass=login-pf) 

Here is the sample theme .property file.

parent=keycloak 
import=common/keycloak 

styles=lib/patternfly/css/patternfly.css lib/zocial/zocial.css css/login.css css/logo.css css/styles.css 
kcHtmlClass=login-pf 
kcContentClass=col-sm-12 col-md-12 col-lg-12 container 
kcContentWrapperClass=row 
kcHeaderClass=col-xs-12 col-sm-8 col-md-8 col-lg-7 
kcFeedbackAreaClass=col-md-12 
kcAlertIconClasserror=pficon pficon-error-circle-o 
kcFormAreaClass=col-xs-12 col-sm-8 col-md-8 col-lg-7 login 
kcFeedbackErrorIcon=pficon pficon-error-circle-o

Change styles related to your theme

Inside of the css directory you can create style sheets as you preferred. Once you create a stylesheet, it needs to be mentioned in the theme.properties file.

      styles=css/login.css

Change the template structure
  • If you want to change the structure of the template, you need to change the related FreeMaker template files.
  • There are two ways to change the template.
                     Change the Base template – NOT RECOMMENDED 
                     Override the template and change it – BEST OPTION

  • As I mentioned, ‘override the template’ is the best option.
  • Just what you need to do is, get a copy from template file and save it in your theme location.
  • Then you can edit saved template according to your requirements and you can add new styles as mentioned above.



Friday, May 18, 2018

Integrate Keycloak with Spring Boot


Security, I know this is so boring. But this is must. Years ago we have to expend much more time to implement the security of our enterprise applications, basically I'm talking about Web application security. But nowadays there are some Identity management tools that can be used to make easier our lives.

What is an Identity management tool ?

Simply it can be used as a security provider. We can delegate our security to a third party. It is just like hiring a security person or hiring a bodyguard. 

What is Keycloak ?

This is one of the best tools that can be used as an authentication management tool. Actually it is an identity provider. You can very easily integrate it to your Spring Boot applications and if you want you can integrate it with Spring Security also.

Advantages of Keycloak ?
  • It is light weight and fast.
  • Single sign on
  • It uses standard protocols such as OAuth 2.0, OpenID, SAML 2.0...etc.
  • Can be managed easily. 
  • Very easy to use with Keycloak adapters.
  • Very easy to enable social logins.

Here I'm not going to explain more details about Security concerns. I just wanted to explain the integration of Keycloak with Spring Boot.

First of all lets create a simple web application using Spring Boot. Go through following link to get started with Spring Boot if you are new to Spring Boot.


Here I'm going to create a simple web application to demonstrate this. 

ReservationController.java

package com.app.api;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ReservationController {

    @GetMapping("/")
    public String home(){
        return "index";
    }

    @GetMapping("/reservation")
    public String getReservations(){
        return "reservations";
    }

    @GetMapping("/logout")
    public String logout(HttpServletRequest request) throws ServletException {
        request.logout();
        return "index";
    }
}


index.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Home</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

    <h1>Home page</h1>
    <a href="/reservation">My Reservations</a>
</body>
</html>


reservations.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Reservations</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

    <h2>Reservations page</h2>

    <a href="/logout">Logout</a>

</body>
</html>



I changed the default server port to 8090 in application.properties file. Just go to following links and check your application is working or not. 


How to use Keycloak server


  • Unzip it in your machine.
  • Go to bin folder. If you are on Windows OS just you can run standalone.bat file or if you are using a Linux distribution, you may use standalone.sh file to start the server. 
  • Normally it will run on port 8080. But you can change it as your wish, go to standalone\configuration\standalone.xml and change the port.
  • Once you run the server, go to http://localhost:8080/auth/

You will be able to see as follows.


This is to create an admin user. You can give any username and password you like. Once you create an admin user, you will be redirected to following page. 


You can see the red square "Administration Console". Just click it and then you will be redirected to following page which asks your admin credentials for the admin you've already created.



Once you are logged, then you can see below page.


Then you have to create a Realm. Just point your mouse to left side and then you will be able to see a button like below image.


Then you can create a realm by giving a realm name. 


Once you create a realm you will be able to see following page.



Then you need to create a client for you application. Click on Client in the left menu.


Then you can give any name for Client ID, I'm using it as "reservations". Once you created a client, scroll down and then you will be able to see "Valid redirect URIs".


It is the entry point to your application after you logged in to it. You may use the port which your Spring Boot application is running. My application is running on port 8090.

Then you have to add new Role. Go to Roles in the menu and click on Add Role.




Once you click, you will be able to see like this.


Add role name, I use it as "user". We need to use this role in our Spring Boot application. Once you save your role, Click again on Roles in menu. Then go to Default Roles.


Then you need to add your role to Default Roles. Select your role and click Add selected.

Now you can create a new user. Click on Users in the menu.


Then click on Add users and give an username and click save. I used it as "client".


Once you saved, just go to Credentials tab in your user and reset your password. Turn off temporary tab for the password. 

Now everything is done on Keycloak configuration side. Ready to go with Spring Boot app.

Configure Spring Boot application

It is actually simple application. What you need to do is, add Keycloak dependencies to your pom.xml and add configurations to application.properties file. 

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>com.app</groupId>
 <artifactId>api</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>

 <name>api</name>
 <description>Demo project for Spring Boot</description>

 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.14.BUILD-SNAPSHOT</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
  <keycloak.version>3.4.2.Final</keycloak.version>
 </properties>

 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>org.keycloak</groupId>
   <artifactId>keycloak-spring-boot-starter</artifactId>
  </dependency>

  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
 </dependencies>

 <dependencyManagement>
  <dependencies>
   <dependency>
    <groupId>org.keycloak.bom</groupId>
    <artifactId>keycloak-adapter-bom</artifactId>
    <version>${keycloak.version}</version>
    <type>pom</type>
    <scope>import</scope>
   </dependency>
  </dependencies>
 </dependencyManagement>

 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>

 <repositories>
  <repository>
   <id>spring-snapshots</id>
   <name>Spring Snapshots</name>
   <url>https://repo.spring.io/snapshot</url>
   <snapshots>
    <enabled>true</enabled>
   </snapshots>
  </repository>
  <repository>
   <id>spring-milestones</id>
   <name>Spring Milestones</name>
   <url>https://repo.spring.io/milestone</url>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
  </repository>
 </repositories>

 <pluginRepositories>
  <pluginRepository>
   <id>spring-snapshots</id>
   <name>Spring Snapshots</name>
   <url>https://repo.spring.io/snapshot</url>
   <snapshots>
    <enabled>true</enabled>
   </snapshots>
  </pluginRepository>
  <pluginRepository>
   <id>spring-milestones</id>
   <name>Spring Milestones</name>
   <url>https://repo.spring.io/milestone</url>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
  </pluginRepository>
 </pluginRepositories>


</project>


application.properties

#server port of Spring Boot application is running
server.port=8090

#specify the url that keycloak server is running
keycloak.auth-server-url=http://localhost:8080/auth

#realm name which you used when you configured keycloak
keycloak.realm=api
keycloak.public-client=true
#client name you created
keycloak.resource=reservations

#created user, when you configured keycloak
keycloak.security-constraints[0].auth-roles[0]=user
#url pattern needs to be secured
keycloak.security-constraints[0].security-collections[0].patterns[0]=/reservation/*


This is a simple example of Spring Boot and Keycloak integration. You will be able to see more details, if you can go to Realm settings and then Login tab. Then you can very easily add functionalities for User registration, Remember me, Forgot password, Verify email...etc. You can download the full Spring Boot project from below.







Friday, April 20, 2018

Interviews FAQ 1


Here I'm not going to explain detailed overview of questions, it is just main points of FAQs that can be asked and this is a part one.

What are the features of Java ?

  • It is simple (Easy learning curve)
  • Robust (both compiletime/runtime error checking, Memory is managed by itself using Garbage collector)
  • Platform independent
  • High performance (With JVM)
  • Very secure (Java files to class files)

What is a class ?

  • Class is a blueprint of which object is created.
  • We can represent a real world object using a class.

What is an interface ?

  • Interface is a blueprint of a class.
  • Interfaces allow a class to behave like multiple types.

Why we need interfaces ?

  • Interfaces are mainly used for data abstraction.
  • We can achieve multiple inheritance using interfaces.

Interfaces vs Abstract class

What is a Java Bean ?

  • Java bean is a class which follows some conventions. 
  • It has no-arg constructor
  • It is serializable.
  • Its fields can only be accessed by getters and setters
  • Its instance variables are final.

What is a hashcode ?

  • Every object has a hashcode, it is unique number.
  • This is assigned by JVM.
  • Hash related data structures use this. (HashMap, HashList...etc)

What is called Serialization ?

  • This is the process of converting an object into a series of bytes.
  • This is very useful when transferring data, store them in sessions...etc

What is called String pool ?

  • It is a separate area of Heap which consist of String objects.
  • This is maintained by JVM.

Difference between == vs equals() 

  • == are used to compare reference and address.
  • equals() method is used to content comparison. 

Web server vs Application server

  • Application server is the super one.
  • Each application server contains a web server.
  • If you are not satisfied with inbuilt server, you can add another server.

Web serverApplication server
Ex: Tomcat, Jetty, ResinEx: Glassfish, Wildfly, JBoss, WebSphere
Not J2EE compatibleJ2EE compatible
Can be run web applications onlyCan be run both web and enterprise applications
Support for HTML, JSP, Servlets...Support for HTML, JSP, Servlets, EJB, JMS...etc

What is the garbage collector ?

  • Garbage collector is a part of JVM.
  • This is used to manage memory.
  • It runs on its own thread with own algorithm.
  • This will destroy useless data(objects without reference) from memory.

StringBuffer vs StringBuilder


StringBufferStringBuilder
Introduced in Java 1.0Introduced in Java 1.5
Every method is synchronizedNo method is synchronized
At a time only one thread is allow to operate.Multiple threads are allow to operate
Thread safeNot thread safe
Slow performances Fast performances 


What is toString() method ?

  • This is called when we trying to print object reference.
  • In collection framework, StringBuffer, StringBuilder, String class already override the toSting() method. 
  • If we didn't override toString() method, object's class toString() method will be called.

What is "volatile" keyword ?


Explain uses of "final" keyword

  • This can be applied to classes, methods and variables.
  • Final classes cannot be extended.
  • Final methods cannot be overridden.
  • Final variables cannot be changed, they are just constants. 

What is "ACID" in databases ?

  • A - Atomicity
  • C - Consistency 
  • I  - Isolation
  • D - Durability

To be continued...