Top Interview Questions For Java in Capgemini

Here are some commonly asked Java interview questions and answers for Capgemini:


Core Java Questions:

1. What are the main features of Java?

Answer:

  • Object-Oriented
  • Platform Independent (WORA – Write Once, Run Anywhere)
  • Automatic Memory Management (Garbage Collection)
  • Multi-threaded
  • Secure
  • Robust

2. Explain the difference between JDK, JRE, and JVM.

Answer:

  • JDK (Java Development Kit): Includes JRE + Development tools (compiler, debugger, etc.).
  • JRE (Java Runtime Environment): Provides runtime environment (JVM + libraries).
  • JVM (Java Virtual Machine): Converts bytecode into machine code.

3. What is the difference between == and .equals()?

Answer:

  • == checks reference equality (memory location).
  • .equals() checks content equality (overridden in classes like String, Wrapper classes).

4. Explain the concept of Java Memory Management.

Answer:

  • Heap Memory: Stores objects and class instances.
  • Stack Memory: Stores method calls and local variables.
  • Garbage Collection (GC): Automatically removes unused objects from the heap.

5. What are Wrapper classes in Java?

Answer:

Wrapper classes convert primitive data types into objects (Integer, Double, Character, etc.).
Example:

int x = 5;
Integer obj = Integer.valueOf(x);  // Boxing
int y = obj.intValue();  // Unboxing

OOPs (Object-Oriented Programming) Questions:

6. What are the 4 pillars of OOPs?

Answer:

  • Encapsulation: Hiding data using private variables and public methods.
  • Abstraction: Hiding implementation details using abstract classes and interfaces.
  • Inheritance: Acquiring properties of a parent class in a child class.
  • Polymorphism: Method Overloading (compile-time) and Method Overriding (runtime).

7. What is the difference between Abstract class and Interface?

FeatureAbstract ClassInterface
MethodsCan have abstract and concrete methodsOnly abstract methods (Java 7), default/static methods (Java 8)
VariablesCan have final/non-final variablesOnly public, static, final variables
InheritanceSingle inheritanceMultiple inheritance
UsageWhen classes have a common baseWhen different classes have common behavior

Example:
Abstract Class:

abstract class Animal {
    abstract void sound();
    void eat() { System.out.println("Eating..."); }
}

Interface:

interface Animal {
    void sound();
}

8. What is Method Overloading and Method Overriding?

Answer:

  • Method Overloading: Same method name, different parameters (Compile-time Polymorphism).
  • Method Overriding: Same method in parent and child class with the same signature (Runtime Polymorphism).

Example:
Overloading:

class MathOperations {
    int add(int a, int b) { return a + b; }
    int add(int a, int b, int c) { return a + b + c; }
}

Overriding:

class Parent {
    void show() { System.out.println("Parent Class"); }
}
class Child extends Parent {
    @Override
    void show() { System.out.println("Child Class"); }
}

Exception Handling & Multi-threading Questions:

9. What is Exception Handling in Java?

Answer:

Exception handling prevents program crashes and ensures smooth execution using:

  • try – Code that may cause an exception.
  • catch – Handles exceptions.
  • finally – Executes always, even if an exception occurs.
  • throw – Used to throw an exception explicitly.
  • throws – Declares exceptions that a method may throw.

Example:

try {
    int a = 10 / 0;
} catch (ArithmeticException e) {
    System.out.println("Cannot divide by zero.");
} finally {
    System.out.println("Finally block executed.");
}

10. What are Checked and Unchecked Exceptions?

Answer:

  • Checked Exceptions: Checked at compile-time (IOException, SQLException).
  • Unchecked Exceptions: Occur at runtime (NullPointerException, ArithmeticException).

11. Explain the life cycle of a thread in Java.

Answer:

  1. New – Thread created but not started.
  2. Runnable – Thread ready to run but waiting for CPU.
  3. Running – Thread executing.
  4. Blocked/Waiting – Thread waiting for resources.
  5. Terminated – Thread execution completed.

Example of thread creation:

class MyThread extends Thread {
    public void run() {
        System.out.println("Thread is running...");
    }
}
public class Test {
    public static void main(String[] args) {
        MyThread t = new MyThread();
        t.start();
    }
}

Spring & Hibernate Questions:

12. What is Spring Framework?

Answer:

Spring is a lightweight Java framework used for enterprise applications.

  • Core features: Dependency Injection, AOP, MVC, Security, etc.

13. What is Dependency Injection in Spring?

Answer:

Dependency Injection (DI) is a design pattern where dependencies are injected by the Spring container instead of being created manually.
Example:

class Car {
    Engine engine;
    Car(Engine engine) { this.engine = engine; }
}

14. What is Hibernate and why is it used?

Answer:

Hibernate is an ORM (Object Relational Mapping) tool that simplifies database operations.

  • Eliminates JDBC boilerplate code.
  • Uses HQL (Hibernate Query Language).
  • Supports caching for performance improvement.

Example:

@Entity
class Employee {
    @Id @GeneratedValue
    private int id;
    private String name;
}

Miscellaneous Java Questions:

15. What is the difference between HashMap and HashTable?

FeatureHashMapHashTable
SynchronizationNot synchronizedSynchronized
PerformanceFasterSlower
Null ValuesAllows one null key and multiple null valuesDoesn’t allow null keys or values

Example:

HashMap<Integer, String> map = new HashMap<>();
map.put(1, "Capgemini");
System.out.println(map.get(1));

16. What is the difference between Collections and Streams?

FeatureCollectionsStreams
StorageStores dataDoesn’t store data
IterationExternal iterationInternal iteration
ModificationCan be modifiedImmutable

Example:

List<String> list = Arrays.asList("A", "B", "C");
list.stream().forEach(System.out::println);

These questions cover both basic and advanced Java concepts, making them highly relevant for Capgemini interviews. Would you like help with any coding questions or mock interviews? 🚀

Leave a Reply

Your email address will not be published. Required fields are marked *