Code Pumpkin

CGI Interview Questions – Set 1

October 18, 2019
Posted by Pumpkin

CGI had arranged a walk-in drive at Bangalore location and I have appeared for Java Developer position. There were total three technical rounds and the difficulty level was easy to medium. I was allocated a slot from 9:30 am to 1:00 pm, but the interview process took a full day.

First Technical Round

  1. Tell me about yourself and your current project.
  2. What are the OOPs concepts?
  3. How do you use inheritance in your current project?
  4. Suppose I have two classes with some common functionality, tell me the scenario when you should use inheritance and when you should create a utility method.
  5. What design patterns have you used in your project?
  6. Have you worked on rest services? Which framework have you used for implementing web services? (Answer: Dropwizard, SpringBoot)
  7. Which framework do you use for creating documentation of web services? (Answer: Swagger)
  8. Which library have you used for serialization/deserialization? (Answer: Jackson, gson)
  9. We are having four JSON objects in the below format, write down code to check if these JSON objects are equal or not. For example, from below 4 JSON objects, Object 1, Object 2 and Object 3 are equal objects. Object 4 is not equal to any.

JSON Object 1

{
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}

JSON Object 2

{
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}

JSON Object 3 (Order of cars is different)

{
"name":"John",
"age":30,
"cars":[ "Ford", "Fiat", "BMW" ]
}

JSON Object 4

{
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat", "Ferrari" ]
}

(Answer: We should create JSON equivalent java objects i.e. DO (Domain Object) and override it’s equals() and hashcode() method. While implementing equals() method, special care is required for comparing cars array. We should first sort array and then perform deep equals. We can then convert JSON string to Java object using Jackson or gson serialization and compare objects using equals() method. )

  1. What approach you will use to process a very large text file?
  2. Typical self join SQL query of printing Employee and Manager Name from Employee table which has three columns EmployeedId, Name and ManagerId.
  3. How do you deploy your applications in your current project?

Second Technical Round

  1. How can we prevent methods in a parent class to be overridden by its child class? (Answer: by making all the methods final)
  2. Is there any way by which we can prevent method overriding without declaring each method final? (Answer: I am not sure, what answer the interviewer was actually looking for, but I told him that we can not override private and static methods as well)
  3. What is method chaining? Do you know any design pattern or Java libraries that use method chaining? (Answer: Builder Design Pattern, Java streams, Hibernate criteria queries)
  4. When should we use Builder design pattern? Can you please write code for implementing builder design pattern.
  5. Which design pattern will you use for this case:
    1. All employees in the office can give the print to any printer and printer prints them. (Answer: Producer-Consumer Design Pattern)
    2. Instead of storing the entire print object in a queue, can we store print() method inside queue and run those methods directly from printer instance. (Answer: We can use Command design pattern. something like Functions class in java 8)
  6. What are Bean scopes in Spring?
  7. How can we configure spring to create beans only when they are first used by any method?
  8. I have two java classes A and B. Both have a circular dependency as below. Can we initialize them using spring?
class A{
   B b;
}

class B{
   A a;
}

(Answer: We can create a bean of Class B using its default constructor injection, then create Bean of class A using constructor injection and then inject an object of A into B using setter injection. You can refer Spring documentation for circular dependency )

  1. How do you use spring for connecting to databases?
  2. What is the use of ApplicationContextAware?
  3. Suppose your clients are using your rest service. Now you are enhancing your rest service and changing the output format, but some clients still want to use the old output format. How do you achieve versioning here? What approach will you follow for versioning rest services using SpringBoot?
  4. Can we configure SpringBoot to use any other embedded server than Apache Tomcat
  5. I have two tables Employee Table with columns EmployeeId, Name, DepartmentId and Salary and Department table with DepartmentId and DepartmentName. Write a query to find an employee with a maximum salary from each department.
  6. Suppose we have one table with column having values like ‘abc’, ‘123’, ‘abc123’, ‘456’. Write a query to select only those rows which contain only numbers in this column. ie. ‘123’ and ‘456’.
    Answer: select * from table_name where lower(col_name) = upper(col_name)

Third Technical Round

  1. Tell me something about your current project.
  2. Explain the Architecture of your current project. (Answer: Draw design diagram for your project and explain)
  3. Design a system for inventory management of local shop where
    • shopkeeper receives predefined stock of items every day
    • If stock received is not the same as predefined value, the shopkeeper can manually update the data
    • display stock of items and
    • update stock when items are sold.
  4. Write a program for converting Binary Tree to Balanced Binary Tree.

This article is contributed anonymously by one of the CodePumpkin user. If you would also like to contribute your article or share interview experiences, you can create a contributor account with CodePumpkin by clicking here or you can send us a mail at admin@codepumpkin.com.

That's all for this topic. If you guys have any suggestions or queries, feel free to drop a comment. We would be happy to add that in our post. You can also contribute your articles by creating contributor account here.

Happy Learning 🙂

If you like the content on CodePumpkin and if you wish to do something for the community and the planet Earth, you can donate to our campaign for planting more trees at CodePumpkin Cauvery Calling Campaign.

We may not get time to plant a tree, but we can definitely donate ₹42 per Tree.



About the Author


A Blog that will help you to learn and refresh your knowledge on Core Java, Data Structure, algorithms, Design Patterns.



Tags: , , , , , , ,


Comments and Queries

If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code class="java"> 
String foo = "bar";
</code></pre>
For more information on supported HTML tags in disqus comment, click here.
Total Posts : 124
follow us in feedly

Like Us On Facebook