Sunday, May 6, 2018

Markit Java Interview Questions

Core Java

  1. Explain the concept of String immutability. What is String pool. How will you create your own String like class.
  2. Explain Serialization. Overriding writeObject method.
  3. What is a class loader.
  4. What are Java locks. class level lock vs lock on objects.
  5. HashMap, ConcurrentHashMap, TreeSet internal implementation.
  6. What are Cyclic barrier and countdown latch.
  7. Implement producer-consumer problem.
  8. How to make a Lock object wait for lock.

Algorithm and Design

  1. You have an input stream of millions of numbers. Which is the suitable data structure for this kind of situation.
  2. He asked me about "Hashing" concept and how is it implemented in java.
  3. Design your own Queue, PriorityQueue(using heap).
  4. Program to find the highest prime number less than a given number.
  5. Design a stack using linked list
  6. Write a program to implement a binary search tree and print the elements in-order.

Design Patterns

  1. Discussion on singleton design pattern:- lazy initialization, eager initialization, also using inner classes. Difference between design patterns. why is one better than another.


  1. which one is better constructor injection or setter injection.


  1. What is Left Outer Join.
  2. SQL question including joins, group by
  3. 1 puzzle: there is a 2d array. the numbers in the array increase as you go down and as you move from left to right. find any given number with minimum complexity.
  4. A probability question (probability of getting minimum two 3’s if i roll 2 dice).
  5. why do I want to leave my current organization etc.

    You can buy my ebook for complete collection of questions and answer of Java Interview Questions

Cracking Microservices Architecture Java Interview Questions

Table of Contents

IDE and softwares required for microservices developmen

1. Core Concepts in Microservices

1.1. Cohesion

1.2. Coupling

1.3. Immutability in Microservices

1.4. Open/Close Principle

1.5. DRY (Don’t Repeat Yourself)

1.6. SOLID

1.7. Single Responsibility Principle

1.8. 8 Fallacies of Distributed Computing

1.9. Continuous Integration (CI)

1.10. CAP Theorem
1.11. 12 Factor App

1.12. Typical Git workflow for a real project.

2. Introduction to Microservices.

2.1. Characteristics of a microservices architectur

2.2. Benefits of using Microservices Architecture

2.3. Challenges in Microservices.

2.4. Difference between Microservices and SOA 

3. Microservices Interview Questions .

3.1. How will you define Microservices Architecture
3.2. What is Domain Driven Design?
3.3. What is Bounded Context?
3.4. What is polyglot persistence? Can this idea be used in monolithic applications as well?
3.5. Why Microservices are better than Monoliths?
3.6. Isn’t in process communication in monolithic application faster than tons of remote network
calls in microservices architecture?
3.7. How microservices are different than SOA?
3.8. What is difference between small-services and microservices?
3.9. What are benefits of using microservices architecture?
3.10. How to partition a large application into microservices architecture, correctly?
3.11. How big a single microservice should be?
3.12. How do microservices communicate with each other?
3.13. What shall be preferred communication style in microservices: synchronous or asynchronous?
3.14. What is difference between Orchestration and Choreography in microservices context?
3.15. How to maintain ACID in microservice architecture?
3.16. How frequent a microservice be released into production?
3.17. How to achieve zero-downtime during the deployments?
3.18. How to achieve zero downtime deployment(blue/green) when there is a database change?
3.19. How to slowly move users from older version of application to newer version?
3.20. How will you monitor fleet of microservices in production?
3.21. How will you troubleshoot a failed API request that is spread across multiple services?
3.22. What are different layers of a single microservice?
3.23. How will you develop microservices using Java?
3.24. Is it a good practice to deploy multiple microservices in a single tomcat container (servlet container)?
3.25. What are Cloud Native applications?
3.26. What is Spring Boot?
3.27. What is Spring Cloud?
3.28. What is difference between application.yml and bootstrap.yml?
3.29. How will you implement service discovery in microservices architecture?
3.30. How does Eureka Server work?
3.31. How to externalize configuration in a distributed system?
3.32. How will you use config-server for your development, stage and production environment?
3.33. What is difference between config first bootstrap and discovery first bootstrap in context of Spring Cloud Config client?
3.34. How to halt a Spring Boot based microservice at startup if it can not connect to Config Server during bootstrap?
3.35. How to refresh configuration changes on the fly in Spring Cloud environment?
3.36. How to achieve client side load balancing in Spring Microservices using Spring Cloud
3.37. How to use client side load-balancer Ribbon in your microservices architecture?
3.38. How to use both LoadBalanced as well as normal RestTemplate object in the single microservice?
3.39. How will you make use of Eureka for service discovery in Ribbon Load Balancer?
3.40. Can we use Ribbon without eureka?
3.41. How will you use ribbon load balancer programmatically?
3.42. What is difference between @EnableEurekaClient and @EnableDiscoveryClient?
3.43. How to make microservices zone aware so as to prefer same zone services for inter-service communication using Spring Cloud?
3.44. How to list all instances of a single microservice in Spring Cloud environment
3.45. What is API Gateway?
3.46. How to protect internal endpoints leaking from API Gateway?
3.47. How to protect Sensitive Security Tokens from leaking into downstream system?
3.48. How to retry failed requests at some other available instance using Client Side Load Balancer?
3.49. What is Circuit Breaker Pattern?
3.50. What are Open, Closed and Half-Open states of Circuit Breaker
3.51. What are use-cases for Circuit Breaker Pattern?
3.52. What are benefits of using Circuit Breaker Pattern?
3.53. Can circuit breaker be used in asynchronous communication?
3.54. What is Hystrix?
3.55. What are main features of Hystrix library?
3.56. How to use Hystrix for fallback execution?
3.57. When not to use Hystrix fallback on a particular microservice?
3.58. How will you ignore certain exceptions in Hystrix fallback execution?
3.59. What is Strangulation Pattern in microservices architecture?
3.60. What is Circuit Breaker?
3.61. What is difference between using a Circuit Breaker and a naive approach where we try/catch a remote method call and protect for failures?
3.62. What is Request Collapsing feature in Hystrix?
3.63. What is difference between Circuit Breaker and Hystrix?
3.64. Where exactly should I use Circuit Breaker Pattern?
3.65. What is bulkhead design pattern?
3.66. How does Hystrix implements Bulkhead Design Pattern?
3.67. What is Hystrix approach to Bulkhead Pattern?
3.68. In microservices architecture, what are smart endpoints and dumb pipes?
3.69. What is difference between Semaphore and ThreadPool based configuration in Hystrix?
3.70. How to handle versioning of microservices?
3.71. What is difference between partitioning microservices based on technical capabilities vs business capabilities? Which one is better?
3.72. Running Spring boot app at different port on server startup.
3.73. How will you run certain business logic at the app startup?
3.74. How to correctly implement a reporting microservice in a distributed system?
3.75. What is Event Sourcing and CQRS? When should it be used? Should be use it for the entire 84
3.76. How to send business errors from a RESTful microservice to client application?
3.77. Is it a good idea to share common database across multiple microservices?
3.78. How will you make sure that the email is only sent if the database transaction does not fail?
3.79. How will you atomically update the database and publish an event to message broker from single transaction?
3.80. How will you propagate security context of user when one microservice calls another microservice on behalf of user?
3.81. What is Token Relay in Spring Security?
3.82. How to Enable Token Relay?
3.83. How to revoke Access and Refresh Tokens on data breach to limit the damage?
3.84. Shall Authentication and Authorization be one service?
3.85. What is API Key security?
3.86. What are best practices for microservices architecture?
3.87. Shall we share common domain models or DTOs across microservices?
3.88. How to share common code across multiple microservices?
3.89. What is continuous delivery?
3.90. How will you improve the performance of distributed system?
3.91. How will you implement caching for microservices?
3.92. Which protocol is generally used for client to service and inter-service communication?.
3.93. What are advantages of using asynchronous messaging within microservices architecture?
3.94. What is good tool for documenting Microservices?
3.95. How will you integrate Swagger into your microservices?
3.96. What are common properties for a Spring Boot project

4. Security in Microservices.

4.1. Why Basic Authentication is not suitable in Microservices Context?
4.2. Why OAuth2?
4.3. How OAuth2 Works?
4.4. What are different OAuth2 Roles?
4.5. What are different OAuth 2.0 grant types (OAuth flows)?
4.6. When shall I use resource owner credentials
4.7. When shall I use Authorization Code grant
4.8. When shall I use client credentials?
4.9. OAuth2 and Microservice
4.10. What is JWT?
4.11. What are usecases for JWT
4.12. How does JWT looks like
4.13. What is AccessToken and RefreshToken
4.14. How to use a RefreshToken to request a new AccessToken?
4.15. How to call the protected resource using AccessToken?
4.16. Can a refreshToken be never expiring? How to make refreshToken life long valid?
4.17. Generate AccessToken for Client Credentials.
4.18. Why there is no RefreshToken support in Oauth2 Client Credentials workflow?
4.19. How to implement the Logout functionality using JWT?
4.20. Security in inter-service communication
4.21. How to setup multiple authentications in Spring Security?
4.22. What is purpose of @EnableResourceServer?
4.23. What is purpose of @EnableOAuth2Sso?
4.24. What is purpose of @EnableOAuth2Client?
4.25. How can we add custom claims to JWT AccessToken?
4.26. Security Best Practice
4.27. How to enable spring security at service layer?

5. Testing Spring Boot based Microservices

5.1. Tools and Libraries available for testin
5.2. What is Mike Cohn’s Test Pyramid?
5.3. Testing Strategies
5.4. Mock vs Stub?
5.5. Unit Testing
5.6. Integration Tests
5.7. Contract-Driven Tests
5.8. End to End Tests
5.9. Best Practices in Testing

For all these questions, buy my ebook:

Unix File Permission | Core Concepts

Unix File Permissions

  1. What does specific unix permission means
  2. How to change the file permissions
  3. How to change the ownership of a file/directory
Unix file permissions are quite different than that of windows/MS DOS.

Unix Security Model

In unix security model, a user may own files and directories. Permissions in unix security model are granted to three different entities:
  1. Owners
  2. Group Members
  3. Everyone else (the world)
Consider the following:
ls -ltr
rwx-xr-r   18 MunishChandel  staff  576 Apr 30 11:14 orders

Permission Attributes

There are 3 different permission attributes r, x and w. These 3 attributes have the following effect on files and directories:
Table 1. Permission Attributes
Allows a file to be written to or truncated, however this attribute does not allow files to be renamed or deleted. The ability to delete or rename files is determined by directory attributes.
Allows files within a directory to be created, deleted, and renamed if the execute attribute is also set.
Allows a file to be opened and read.
Allows a directory’s contents to be listed if the execute attribute is also set.
Allows a file to be treated as a program and executed. Program files written in scripting languages must also be set as readable to be executed.
Allows a directory to be entered, e.g., cd directory.
Few real life examples of file permission attributes are listed in the below table.
Table 2. Permission Attributes Examples
Permission AttributesMeaning
A regular file that is readable, writable and executable by file owner. others can read and execute it.
Only File owner can read and write the file. Others have no access.

Changing file permissions: chmod

chmod command is used to change the permissions of a file. Only file’s owner or the superuser can change the mode of a directory/file. To gain ownership of a file or directory you would like to execute chown command first.
changing file ownership using chown
sudo chown -R nexus:nexus /opt/oss
The above command recursively changes ownership of all files present in directory /opt/oss to user nexus.
There are broadly two distinct ways of changing file permissions using chmod:
  1. symbolic representation
  2. octal number representation

symbolic representation

We need to learn few more symbols other than r,w,x.
Table 3. Symbol meanings
short for all of the above
file or directory owner
group owner
chmod needs two inputs:
  1. who is affected (user/group/world/all)
  2. what will be permissions (r/w/x)
Add execute permission to the owner on
chmod u+x
Add execute permission to everyone (owner/group/world)
chomd a+x
Remove execute permissions from owner
chmod u-x
Please be noted here that specifying +x or -x just sets a single attribute (x) without disturbing other attributes of file permission (r & w). The same is not possible in octal notation.

Octal notation for chmod

A single digit octal notation is enough to specify 3 different permission attributes (rwx) combination for an entity. Overall we need to specify 3 digit octal numbers to specify file mode for owner, group and world.
Table 4. Octal Notation for File Modes
OctalBinaryFile Mode
Few examples of octal notation:
owner has file mode 6 (rw), group and world has 0.
owner has file mode 6 (rw), group and world has read permission (4-4)
owner has file mode 7 (rwx), group and world have no permissions.
To set 600 on
chmod 600

Saturday, May 5, 2018

How to reverse the sequence of words in a given string

Unlike C/C++, Java Strings are immutable, hence inline operations within a string are not possible. In fact, each time we make a modification to string, a new string literal is created and stored in String Pool internally. Probably doing manipulations using char array can give better performance.

Pseudo Code for Java

  1. Split the String into words using white space as separator
  2. Reverse the collection consisting of words
  3. Join the collections of word back into string
Java 8 Program to reverse the order of words in String
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ReverseWords {

    public String reverseJava8Style(String input){
        List<String> list = Arrays.asList(input.split("[\\s]"));
        return String.join(" ", list);

public class ReverseWordsTest {
    ReverseWords utils = new ReverseWords();

    public void reverseJava8Style() {
        String reverseJava8Style = utils.reverseJava8Style("My Name is Tanishq");
        assertThat(reverseJava8Style, equalTo("Tanishq is Name My"));

Time Complexity

Complexity corresponding to each pseudo step:
  • Step 1. O (n) where n is number of characters in string
  • Step 2. O (k) where k is the number of words. k < n
  • Step 3. O (K) where k is number of words, k < n
Overall time complexity is O(n).
If it was C/C++, we could have used a better approach that replaces everything inline without any additional memory:
  1. Reverse the entire string
  2. Reverse the characters inside each word
  3. Print the string
But this approach will not work due to Immutable nature of Strings in java, thus would generate too many string literals. So the second approach is not discussed here.

Top 50 Java Interview Questions | SDET Role

Oracle (and other companies) interview experience for SDET Java Role (Core Java - Basic Concepts, Algorithms & data structure, Cucumber framework, Selenium and TestNG, REST API)

Essential skills | SDET Java Role

Programming Languages
Knowledge of Java and Python is helpful. Basics of Core Java (Inheritance, OOPS, Collections, Exception handling)
Algorithms & DS
Basic understanding of Algorithms & DS (Sorting, Searching, recursion, dynamic programming, hash table and List etc.)
Testing Frameworks
Knowledge of Test Libraries for Unit, Acceptance and End To End Testing for e.g. JUNIT, TestNG, Hemcrest, Cucumber, Selenium and Rest Assured for REST API testing. Ability to write small framework for testing from scratch using Core Java.
SQL & UNIX Shell
Basic Knowledge of SQL, Database and Linux Shell Programming.
Build Tools and CI Pipeline
Knowledge of atleast one build tool- Travis CI, Jenkins CI, Teamcity, etc. Maven, Gradle, Vagrant, Docker, Build CI & CD and Automation Tools - Jenkins, ability to setup a build pipeline on Jenkins.
Quant and Aptitude
Puzzles and Quantitative aptitude

    Java Questions

    1. What is difference between JDK, JVM and JRE?
    2. What is super class in Java?
    3. How will you make sure that main thread is the last one to exit?
    4. Main Interfaces in Collections API - List, Set, Map. What is difference between them?
    5. Enumerator vs Iterator? Which one is thread safe?
    6. Can collection classes be made serializable. How to do that?
    7. catch NPE first and Exception in last, will that work? Discuss the exception hierarchy. What are the inheritance rules for Exceptions.
    8. Error and exception difference with example. StackoverflowError, OOMError, etc.
    9. Custom exceptions, how will you create one?
    10. How will you compare two java objects?
    11. Multiple inheritance in Java? [oracle]
    12. overriding and overloading difference.
    13. Inheritance vs Composition in Java.
    14. How to swap two numbers without a temporary variable? Discuss XOR approach. what are problems with addition approach? Integer overflow.

    Algorithms and DS

    1. Identify the pangram sentence from array of sentences. Pangram is a string that contains all the alphabets from a-z.
    2. Searching an elements from a sorted and rotated array.
    3. Find two numbers of which the product is maximum in an array. sort and multiply first or last two elements.
    4. Sorting algorithms
    5. How to find the relative efficiency of a given algorithms
    6. find first not-repeating character by iterating through the length of the string only once and by using constant space.
    7. Print fibonacci series
    8. Print prime numbers upto x
    9. Implement a stack data structure.
    10. Reverse the ordering of words in a string

    Testing Framework Questions

    1. JUNIT vs TestNG what are differences? Which one is better for QA?
    2. TestNG hierarchy - Tests, suites, classes, etc.
    3. Parameterization of tests in TestNG and data providers.
    4. TestNG Listeners. Uses
    5. Selenium and Rest API testing frameworks

    Linux & Shell

    1. How to run a program in background
    2. How to create a service for running jar
    3. How to make sure that a program is restarted if terminated
    4. How to list selected processes
    5. How to kill a process
    6. How to search for keywords in files in current directory
    7. What is awk command, sed command
    8. How to copy a file from one machine to another?
    9. Continuously monitor last 100 lines of a log file.
    10. How to connect to a remote server and execute certain commands.
    11. I want to read all input to the command from file1 direct all output to file2 and error to file 3, how can I achieve this? unix pipes.
    12. Unix permissions concepts chmod +x file.
    13. How does password less login works? At a higher level.

    Database and SQL

    1. Employee and Department table - all employees from employee table and only departments that exists for a employee from department table. Left outer join.
    2. How to delete duplicate records from a given table. (duplicate based on specified fields)
    3. 2nd highest salary in SQL, how will you find it out.

    Build Tools and CI/CD

    1. Maven and Gradle basics (PMD rules, Firebug, Code coverage tools, etc.)
    2. What is CI and CD
    3. How is your CI/CD and build environment setup in your project. Jenkins, Regression Test, etc. explain the stuff.
    4. How to setup a build pipeline in Jenkins
    5. How to seamlessly deploy to AWS EC2 cloud upon single commit in version control. Just the high level steps/approach.