Wells Fargo Java Interview Questions

As part of job search I have attended interview in couple of companies Wells Fargo is one among them. Here I am placing the list of interview questions which I have faced in a conference round of interview. I hope this will definitely help someone who is attending on below mentioned skill set.

Java

Microservices

Spring Boot

Spring Cloud

Pivotal Cloud Foundry(PCF)

Questions:

  1. Could you please explain about your techstack and previous project?
  2. Let’s start with Core Java:

  3. What is the output of below program?
  4. class A{
       private void method1(){
          System.out.println("Inside A method");
       }
    }
    class B extends A{
       public void method1(){
          System.out.println("Inside B method");
       }
    }
    public class Test{
       public static void main(String[] args){
           A a = new B();
           a.method1();
       }
    }
    
  5. Is above program violating the rules of Overriding or not?
  6. When do you go for Interface and abstract class?
  7. From Java 8 on wards, we are able to implement methods in interface. Then what is the need of Abstract Class?
  8. What all java 8 concepts you aware?
  9. What is functional interface and how it is different from normal interface?
  10. Have you worked on multithreading?
  11. How can you communicate from one thread to another?
  12. How thread pool works?
  13. What all the classes and interfaces you worked in Collection framework?
  14. How HashMap works internally?
  15. In Java 7, there are few changes came in HashMap. Do you know what are those?
  16. If I have two keys(Key1=1, Key2=10) with same hashcode, What will happen when we try to put int HashMap?
  17. How TreeSet can store elements in order?
  18. I have custom objects of Student. What should I do to store them in ascending order in TreeMap? TreeMap will take care internally or do I need to write logic for sorting?
  19. When we use Comparable and Comparator?
  20. Coming to WebServices, Spring, Spring Boot, Spring Cloud and Microservices:

  21. Have you worked on REST(REpresentational State Transfer) WS?
  22. How can you convert the JSON data into Java Object?
  23. How can you consume the endpoint from UI?
  24. What are different modules you worked in Spring framework?
  25. Can you explain me the steps how MVC works in Spring and Spring Boot?
  26. What are the advantages of using @RestController over @Controller?
  27. In normal Spring MVC, which you prefer to use either @RestController or @Controller? Why?
  28. What are the advantages of using Spring Boot?
  29. Do you know, how configuration will take care automatically in Spring Boot? Or Do you know, how autoconfiguration works in Spring Boot?
  30. When we declare web module in pom.xml, it download all the related dependencies(JAR’s). How it will identify, which jar is for which module?
  31. How can we run Spring Boot application?
  32. Which is the default server uses in Spring Boot? Does it require any configurations to add?
  33. If server is down, instead of showing default error message, we need to show Custom message. How will you do?
  34. Have you worked on feignClient?
  35. What are different tools you worked on Spring Cloud?
  36. Have you used inline DB?
  37. Do we need to provide any configuration details to use inline DB?
  38. Have you worked on WebLogic?
  39. Coming into PCF:

  40. What is Diego? what it will do?
  41. Can you explain about 12 factor apps?
  42. While pushing application into pivotal, which way you followed? direct or with manifest?
  43. We have different environments with different configurations like Development, Staging and Prod. How will you build and push application into different environments?
  44. I have a monolithic application, how can you push that into pivotal?
  45. My application data source configuration properties are placed in WebLogic server. How will you take care of those while pushing application into pivotal?
  46. Have you used any of User provided services?
Thanks for visiting. If anyone else has extra questions which you people faced, please write in comment.

push monolithic application into pcf – 1

In previous posts, we have seen how to create Microservices application with Spring Boot technology and push it into the pivotal cloud foundry. Since Spring Boot works on the concept of auto configuration, we easily pushed Spring Boot application into PCF without worrying about application configuration or running environment like Tomcat server and all.

When it come to normal Spring MVC application, Tomcat or any other web/application server is compulsory to use to run the application. Now the question is, how can we push monolithic Spring MVC application in Pivotal?

To get clarification about above question, we need to follow below steps.

  1. Create Spring MVC application in local environment.
  2. Test to get confirmation either working as expected or not in locally configured server.
  3. When it’s working in locally, push the same jar/war file into pivotal cloud foundry.
  4. Test by using application route provided by pivotal

Step1: Creating Spring MVC application

I am trying to create a sample application of using the below techstack to push that application into Pivotal Cloud Foundry. This application does not contain any database interaction.

Java – 1.8

Spring – 5.x

Maven – 3.5.x

STS – 4

Tomcat – 8.5

If you are not aware of how to create Spring MVC project in Spring Too Suite (STS) as Maven project. Follow the steps explain in this page.

The project might get generated in different structure. The below is my project structure look like,

pom.xml:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.monolithic.springmvc</groupId>
    <artifactId>monolithic-springmvc</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>monolithic-springmvc Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <spring.version>5.1.2.RELEASE</spring.version>
    </properties>
    <dependencies>
 <dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>3.8.1</version>
     <scope>test</scope>
 </dependency>
 <dependency>
            <groupId>org.springframework</groupId>
     <artifactId>spring-core</artifactId>
     <version>${spring.version}</version>
 </dependency>

 <dependency>
            <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
     <version>${spring.version}</version>
 </dependency>

 <dependency>
            <groupId>org.springframework</groupId>
     <artifactId>spring-webmvc</artifactId>
     <version>${spring.version}</version>
 </dependency>
 <dependency>
     <groupId>javax.servlet</groupId>
     <artifactId>jstl</artifactId>
     <version>1.2</version>
 </dependency>
    </dependencies>
    <build>
 <finalName>monolithic-springmvc</finalName>
 <plugins>
     <plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.6</version>
  <configuration>
        <warSourceDirectory>WebContent</warSourceDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
  </configuration>
     </plugin>
 </plugins>
    </build>
</project>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 <display-name>MonolithicSpringMVC</display-name>
 <description>Monolithic Spring MVC application created for
  pushing into pivotal cloud foundry</description>

 <welcome-file-list>
  <welcome-file>/index.jsp</welcome-file>
 </welcome-file-list>

 <servlet>
     <servlet-name>default</servlet-name>
     <servlet-class> 
                 org.springframework.web.servlet.DispatcherServlet 
            </servlet-class>
     <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/spring-servlet.xml</param-value>
            </init-param>
     <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
     <servlet-name>default</servlet-name>
     <url-pattern>/</url-pattern>
 </servlet-mapping>
 <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>/WEB-INF/spring-servlet.xml</param-value>
 </context-param>
 <listener>
     <listener-class> 
                org.springframework.web.context.ContextLoaderListener 
            </listener-class>
 </listener>
</web-app>

spring-servlet.xml: This file name you can change as you like. But, you should configure the same name in above web.xml file wherever configured. 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <mvc:annotation-driven />
    <mvc:default-servlet-handler />
    <context:component-scan
  base-package="com.monolithic.springmvc.controller" />

    <bean id="viewResolver"
     class="org.springframework.web.servlet.view.UrlBasedViewResolver">
 <property name="viewClass"
   value="org.springframework.web.servlet.view.JstlView"/>
 <property name="prefix" value="/WEB-INF/views/"/>
 <property name="suffix" value=".jsp"/>
    </bean>
</beans>
 
index.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Monolithic Spring MVC - Index</title>
</head>
<body>
    <center>
 <h2>Hey Monolithic</h2>
 <h3>
     <a href="welcome?name=JavaIsOcean">Click Here</a>
 </h3>
    </center>
</body>
</html>

welcome.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Monolithic Spring MVC - Welcome</title>
</head>
<body>
    <center>
 <h2>Hello ${name}</h2>
 <h2>
     ${message} 
 </h2>
    </center>
</body>
</html>

MonolithicController.java:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MonolithicController {
    String message = "Welcome to Monolithic Spring MVC Application!!!";
    @RequestMapping("/welcome")
    public ModelAndView showMessage(@RequestParam(value = "name", required = false, 
        defaultValue = "JavaIsOcean") String name) {
       ModelAndView mv = new ModelAndView("welcome");
       mv.addObject("name", name);
       mv.addObject("message", message);
       return mv;
    }
}

Let’s build the application source code by using the command of mvn clean install and get war file is generated or not in target directory. If the war file is not generated, your code is not correct. If you don’t wish to write all these code, you can also download from https://github.com/Nallamachu/Pivotal. So, now creating the sample Spring MVC project completed.

Step 2: Test application in local server:

To complete this step, we need a web/application server which is running locally. If you have already have configured any server, you can deploy the generated war file into it and test. Otherwise we need to download and configure.

To make it simple, I have downloaded the tomcat server with the version of 8.5 from official Tomcat website as a zip file and extracted locally. There might be a chance of facing startup issues. To avoid that, do the highlighted settings changes in your local as well.

Once you run the project successfully, you will get the output as index page As on when you hit the below URL. URL will be the combination of  host + port+ context name. Output look like below,

You will get the output as below, as on when you click on the Click Here hyper link.

So, our step 2 also completed.

Step 3: Push war file into Pivotal Cloud Foundry:

You should have valid credentials to login into Pivotal account prior doing any operations with Cloud foundry environment. If you don’t have follow these instructions to register and access in Pivotal and get 2 GB of free space.

If you already have valid account details, login into pivotal by using Cloud Foundry CLI with the command of cf login. If you didn’t have installed Cloud Foundry, follow these instructions.

Navigate into the target directory or where your war file located, and issue the below command to push into cloud foundry.

cf push monolithic-springmvc -p monolithic-springmvc.war

cf push  – is the command to push application into cloud foundry
monolithic-springmvc –  is the application name I am passing
-p  – is the parameter to specify the pushing file path where it located

Once we issue the above command, we will see the pushing progress like below,

Once it completed pushing and starting the application, you can access the URL, which is called as route in Cloud foundry terminology. In this case, monolithic-springmvc.cfapps.io is the route to access application. Look at the below screen to know about application details in pivotal application manager.

So, pushing war file into cloud foundry account is completed. Let’s move on to last step of testing the application.

Step 4: Test by using application route:

As I explained in Step 3, once we push application successfully in pivotal cloud foundry, it will generate a route to access application. As on you open the route, you will get the same output what we have got in Step 2 of testing in local tomcat environment. Look at the below screens,

We will get the below screen as on when we hit the Click Here hyper link shown in above screen,

 

Note: If you observe the above URL / Route, we are not passing any application context name like how we access in local. That will be taken care by Pivotal.

PCF Application Services

Service is one of the important factor in recommended 12 factor apps also a commonly used feature in cloud application deployment. Services has to be attached to resources either in the local or in production environment. Cloud Foundry build up on that idea where resource and provides the service instances. The basic idea what we have here is,

On-demand resources = Services

We can manage application services in two ways by using CF CLI and another is form marketplace. Marketplace helps you to use readily available services in Pivotal Cloud Foundry. You simply go to services tab in the Cloud Foundry or Marketplace to look services available. Assume that you want to see MySQL database in Cloud Foundry that locates in Marketplace. As on when you bind that service, you have service ready to use. This is also called as Provisioning.

Cloud Foundry services uses a provisions as a service. There is a command for managing services of application. That is, CF SERVICE command. There are two types of service instances,

Manage Service Instance

User provided Service Instance

Manage Service Instance: An instance which is created from the marketplace service is called as Manage service instance. which all services available in market place to bind with our application, these type of services called as managed services. As part of this, we use only create-service and bind-service commands to create and bind service with our application.

User provided Service Instance: An instance which is created from the user provided service is called as User provided service instance. The services which are not present in marketplace and created by the user is called as User provided services. To create user provided service, we use the command called create-user-provided-service. This command also has the alias name called as cups.

List of Service Commands:

Many service instances are advance that we use in Cloud Foundry itself. Such as the MySQL etc. These services are using Service Broker API to implement their all services. Cloud Foundry Marketplace advertise these all services and shows you all available services you can use.
As on when we select a service there will be options shows start, shutdown and bind. These are manage by Service Broker APIs. Once we can get the instance of manage broker API, we can use of it in our applications through binding. We can use CF BIND command in our manifest file.
So, when we pushed our application into Cloud Foundry, that service will be bind to our application. After that we can start using immediately. We can insert data, pull data and so on, it is a database instance.
Will definitely have demonstration of both the sides like managed and user defined services. User defined services are advance that we can provide to our applications and actual user seemly like to case in the manage services. Let’s assume that we have some environment variables that other people or application developers to use. So, we can create a User defined service and provide your variables through it. It works just like the manage services, so you can manifest to bind it to application or simply go to dashboard and bind it manually with the application.

Multiple Deployment Options:

There are couple of deployment options we have in Cloud Foundry which we can make use of it. So for service to be available for binding on the requirement is that, it should implement Service Broker API.
So assume that, we want to have a service definition, which goes into category of user defined service. We can simply attach that service as a resource to our application or for the other service deployment options, we can have our service defined and deployed in Cloud Foundry. Cloud Foundry platform is really flexible allowing use to know how we want it.