TCS RealTimeInterview
TCS RealTimeInterview
1. **Prototype Bean**: Each time you call `getBean()` for the prototype-scoped
bean, Spring will create a new instance of the prototype bean.
2. **Singleton Dependency**: The singleton-scoped bean inside the prototype bean
will not be recreated each time. Instead, the same instance of the singleton bean
will be injected into each new instance of the prototype bean.
### Scenario:
Suppose you have the following setup:
```java
@Component
@Scope("singleton")
public class SingletonClass {
// Singleton bean logic here
}
@Component
@Scope("prototype")
public class PrototypeClass {
@Autowired
private SingletonClass singletonClass;
**Example Output**:
If you call `getBean("prototypeClass")` three times, you may see output similar to:
```
Prototype instance: PrototypeClass@1a2b3c
Injected Singleton instance: SingletonClass@4d5e6f
This behavior ensures that the prototype bean can have unique instances, while its
singleton dependency remains consistent across the application.
===============================
If you have a **singleton-scoped bean** that contains a **prototype-scoped bean**
as a dependency, the behavior when calling the prototype bean can be
counterintuitive due to how Spring manages the lifecycle of beans:
### Problem:
Since the singleton bean is created only once and its dependencies are resolved at
that time, the prototype bean does **not** get recreated each time the singleton
bean accesses it. This is because the lifecycle of the prototype bean is controlled
by the singleton bean, which leads to unexpected behavior if you want fresh
instances of the prototype bean on each use.
### Summary:
- **By default**: A prototype-scoped bean inside a singleton bean behaves like a
singleton because only one instance is injected at the time of singleton bean
creation.
- **To get fresh instances**: Use `@Lookup`, `ObjectFactory`, or `Provider` to
ensure new instances of the prototype bean are retrieved each time it is accessed
in the singleton bean.
================================
In Spring Boot, the `@Qualifier` annotation is used to resolve the ambiguity when
there are multiple beans of the same type and you need to specify which one should
be injected. It helps Spring identify which specific bean should be used when there
is more than one candidate available for dependency injection.
### Example:
```java
@Component("beanOne")
public class ServiceA implements MyService {
// Implementation of ServiceA
}
@Component("beanTwo")
public class ServiceB implements MyService {
// Implementation of ServiceB
}
```
@Autowired
public ClientService(@Qualifier("beanOne") MyService myService) {
this.myService = myService;
}
```java
@Component
@Primary
public class DefaultService implements MyService {
// Default implementation
}
@Component("customService")
public class CustomService implements MyService {
// Custom implementation
}
```
**Injection without `@Qualifier` will use `DefaultService` due to `@Primary`**:
```java
@Autowired
private MyService myService; // Injects DefaultService
```
### Summary:
- **`@Qualifier`** is used to specify which bean to inject when multiple beans of
the same type exist.
- It helps avoid ambiguity and ensures the correct bean is chosen for dependency
injection.
- Works with `@Autowired`, constructor injection, and method parameter injection.
====================
Mocking `final` classes in JUnit 5 can be done using **Mockito** version 2 or above
with specific configuration. By default, earlier versions of Mockito didn't allow
mocking `final` classes or methods, but later versions introduced this capability.
1. **Ensure You Have Mockito 2+ or Above**: Use Mockito version 2.x or later,
ideally the latest version of Mockito 3 or 4, which supports mocking `final`
classes and methods out of the box.
**Maven Dependencies**:
```xml
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version> <!-- Use a suitable version -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.11.0</version> <!-- Same version as mockito-core -->
<scope>test</scope>
</dependency>
```
**Gradle Dependencies**:
```groovy
testImplementation 'org.mockito:mockito-core:4.11.0'
testImplementation 'org.mockito:mockito-inline:4.11.0'
```
@Test
void testMockFinalClass() {
// Create a mock of the final class
FinalClass finalClassMock = mock(FinalClass.class);
// Define behavior
when(finalClassMock.sayHello()).thenReturn("Mocked Hello!");
By following these steps, you can mock `final` classes and methods in JUnit 5 with
ease, ensuring better flexibility in writing unit tests for classes that are
otherwise non-mockable by default.
========================
Mocking static methods in JUnit 5 can be done using **Mockito** version 3.4.0 or
higher, which introduced built-in support for mocking static methods through the
`mockito-inline` module. Here's how to set it up and use it:
**Maven Dependencies**:
```xml
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version> <!-- Use the appropriate version -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
```
**Gradle Dependencies**:
```groovy
testImplementation 'org.mockito:mockito-core:4.11.0'
testImplementation 'org.mockito:mockito-inline:4.11.0'
```
**Example**:
```java
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
@Test
void testStaticMethodMocking() {
try (MockedStatic<StaticClass> mockedStatic =
Mockito.mockStatic(StaticClass.class)) {
// Define the behavior of the static method
mockedStatic.when(StaticClass::staticMethod).thenReturn("Mocked
Response");
3. **Explanation**:
- **`mockStatic()`**: Creates a mock for the specified class and allows stubbing
static methods.
- **Try-with-resources**: The `MockedStatic` object must be closed after use to
restore the original behavior of the static method. Using try-with-resources
ensures automatic closure.
- **`when()`** and **`thenReturn()`**: Used to define the behavior of the static
method when called.
**Example Verification**:
```java
mockedStatic.verify(StaticClass::staticMethod, times(1));
```
By following these steps, you can effectively mock static methods in your JUnit 5
tests with minimal configuration using modern Mockito features.
================================
Mocking constructors directly in JUnit 5 using **Mockito** is not supported
natively. However, **PowerMock** was traditionally used for mocking constructors.
If you need to mock constructors, consider using **PowerMock** or **Mockito-
inline** with tools like **Objenesis** for complex scenarios. Here’s how to handle
constructor mocking:
**PowerMock** allows you to mock constructors, static methods, and private methods,
but it has some limitations and may not be compatible with the latest versions of
JUnit 5 and Mockito. You may need to integrate it with JUnit 4 or use an older test
framework.
**Maven Dependencies**:
```xml
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.9</version> <!-- Ensure compatibility -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
```
**Example**:
```java
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(TargetClass.class)
public class ConstructorMockTest {
@Test
public void testMockConstructor() throws Exception {
// Mock the constructor of TargetClass
TargetClass mockInstance = PowerMockito.mock(TargetClass.class);
PowerMockito.whenNew(TargetClass.class).withAnyArguments().thenReturn(mockInstance)
;
// Define behavior
Mockito.when(mockInstance.someMethod()).thenReturn("Mocked Response");
If you want to avoid PowerMock and need an alternative for mocking constructors,
you can use **Objenesis** for creating objects without invoking constructors. This
approach is more complex and may be suitable for very specific use cases.
**Example**:
```java
public class Service {
private final Dependency dependency;
@Test
void testService() {
// Mock the dependency
Dependency mockDependency = mock(Dependency.class);
when(mockDependency.doSomething()).thenReturn("Mocked Result");
### Syntax:
```java
String substring(int beginIndex)
String substring(int beginIndex, int endIndex)
```
### Parameters:
- **`beginIndex`**: The starting index (inclusive) of the substring. It must be
between `0` and the length of the string.
- **`endIndex`** (optional): The ending index (exclusive) of the substring. It must
be between `beginIndex` and the length of the string.
### Explanation:
- The character at `beginIndex` is included in the substring.
- The character at `endIndex` is not included in the substring.
### Examples:
1. **Substring from a specified start index to the end**:
```java
String str = "Hello, World!";
String result = str.substring(7);
System.out.println(result); // Output: "World!"
```
- Starts at index `7` (`W`) and goes to the end.
```java
Boolean x = new Boolean("yes");
Boolean y = new Boolean("no");
System.out.println((x == y) + ":" + x.equals(y));
```
The `Boolean` class in Java interprets the strings `"yes"` and `"no"` differently
than you might expect. Here's a detailed explanation:
In your example:
- `new Boolean("yes")` creates a `Boolean` object with the value `false`.
- `new Boolean("no")` also creates a `Boolean` object with the value `false`.
---
```java
public class MyRunnableTask implements Runnable {
@Override
public void run() {
// Task to be executed in the thread
for (int i = 1; i <= 5; i++) {
System.out.println(Thread.currentThread().getName() + " is running: " +
i);
try {
Thread.sleep(500); // Simulate some delay
} catch (InterruptedException e) {
System.out.println("Thread was interrupted: " + e.getMessage());
}
}
}
thread1.start();
thread2.start();
}
}
```
**Advantages**:
- Allows extending other classes since you’re not bound to extend `Thread`.
- Promotes a cleaner design as tasks and thread behavior are decoupled.
---
```java
public class MyThread extends Thread {
@Override
public void run() {
// Task to be executed in the thread
for (int i = 1; i <= 5; i++) {
System.out.println(getName() + " is running: " + i);
try {
Thread.sleep(500); // Simulate some delay
} catch (InterruptedException e) {
System.out.println("Thread was interrupted: " + e.getMessage());
}
}
}
thread1.setName("Worker-1");
thread2.setName("Worker-2");
thread1.start();
thread2.start();
}
}
```
**Advantages**:
- Slightly easier for beginners to understand and implement.
- Involves fewer steps compared to implementing `Runnable`.
---
---
**Query Example:**
```sql
SELECT employees.name, departments.department_name
FROM employees
INNER JOIN departments
ON employees.department_id = departments.id;
```
---
**Query Example:**
```sql
SELECT employees.name, departments.department_name
FROM employees
LEFT JOIN departments
ON employees.department_id = departments.id;
```
---
**Query Example:**
```sql
SELECT employees.name, departments.department_name
FROM employees
RIGHT JOIN departments
ON employees.department_id = departments.id;
```
---
**Query Example:**
```sql
SELECT employees.name, departments.department_name
FROM employees
FULL OUTER JOIN departments
ON employees.department_id = departments.id;
```
---
**Query Example:**
```sql
SELECT employees.name, departments.department_name
FROM employees
CROSS JOIN departments;
```
---
**Query Example:**
```sql
SELECT e1.name AS Employee1, e2.name AS Employee2
FROM employees e1
JOIN employees e2
ON e1.manager_id = e2.id;
```
---
---
#### `employees`:
| id | name | department_id |
|----|-----------|---------------|
| 1 | Alice | 10 |
| 2 | Bob | 20 |
| 3 | Charlie | NULL |
#### `departments`:
| id | department_name |
|----|-----------------|
| 10 | HR |
| 20 | IT |
| 30 | Marketing |
---
**INNER JOIN:**
```sql
SELECT employees.name, departments.department_name
FROM employees
INNER JOIN departments
ON employees.department_id = departments.id;
```
| name | department_name |
|--------|-----------------|
| Alice | HR |
| Bob | IT |
---
**LEFT JOIN:**
```sql
SELECT employees.name, departments.department_name
FROM employees
LEFT JOIN departments
ON employees.department_id = departments.id;
```
| name | department_name |
|----------|-----------------|
| Alice | HR |
| Bob | IT |
| Charlie | NULL |
---
**RIGHT JOIN:**
```sql
SELECT employees.name, departments.department_name
FROM employees
RIGHT JOIN departments
ON employees.department_id = departments.id;
```
| name | department_name |
|--------|-----------------|
| Alice | HR |
| Bob | IT |
| NULL | Marketing |
---
| name | department_name |
|----------|-----------------|
| Alice | HR |
| Bob | IT |
| Charlie | NULL |
| NULL | Marketing |
---
This demonstrates how the type of JOIN determines what is "left after the join."
=============================================
In PostgreSQL, both `DELETE` and `TRUNCATE` are commands used to remove data from a
table, but they work in different ways and are used in different scenarios. Here's
a breakdown of the differences:
- **Behavior**:
- Deletes rows one by one, which can be slower for large tables.
- Can be rolled back if used inside a transaction (`BEGIN`/`COMMIT`).
- Fires any triggers associated with `DELETE` on the table.
- Does not reset the table's auto-incrementing `SERIAL` column (if applicable).
- **Use Case**:
- When you need to remove specific rows based on a condition.
- When you want to retain the table structure and any constraints (like foreign
keys) intact.
- **Behavior**:
- **Faster than DELETE**: It doesn't scan rows or fire triggers, so it can be
significantly quicker, especially for large tables.
- **Resets the auto-increment sequence**: If the table has a `SERIAL` column,
`TRUNCATE` will reset the sequence back to its starting value.
- **Cannot delete specific rows**: Unlike `DELETE`, `TRUNCATE` removes all rows
in the table.
- **Cannot be rolled back** in certain cases (depending on transaction settings).
If you're in a transaction block and the `TRUNCATE` command is issued, it can be
rolled back, but some database configurations may treat it differently.
- **No triggers fired**: Does not activate `DELETE` triggers.
- **Faster**: Since it doesn't involve scanning and row-by-row deletion, it's
faster than `DELETE` for clearing large tables.
- **Use Case**:
- When you want to completely empty a table (remove all rows) without concern for
individual row-level triggers or conditions.
- Useful for clearing tables in staging, testing, or during batch operations.
### Key Differences Between `DELETE` and `TRUNCATE`:
| Feature | `DELETE` | `TRUNCATE`
|
|------------------------|-------------------------------------|-------------------
---------------|
| Removes rows based on condition | Yes, you can specify a `WHERE` clause | No,
removes all rows |
| Performance | Slower for large tables due to row-by-row deletion |
Faster, no row-by-row deletion |
| Auto-increment reset | No | Yes
|
| Triggers | Fires `DELETE` triggers | Does not fire
triggers |
| Rollback | Can be rolled back in transactions | Can be rolled back
in some cases |
| Locking | Row-level locks | Table-level lock
|
| Foreign Key Constraints| Checked (can raise errors) | Depends on the
`CASCADE` option |
### 1. **@Controller**
The `@Controller` annotation is used to define a Spring MVC controller class. This
type of controller is typically used in **web applications** where the response is
often a **view** (e.g., a JSP, Thymeleaf template, or HTML page). It is part of the
**Model-View-Controller (MVC)** pattern.
#### Key Characteristics:
- **Return a View**: A controller annotated with `@Controller` typically returns a
**view name** (like "home" or "index") that will be resolved by a view resolver
(such as `Thymeleaf`, `JSP`, etc.) to render an HTML page.
- **Uses View Resolvers**: It often involves combining the model (data) with a view
(UI) to generate a response to the user.
- **Handles Form Data**: Commonly used to handle user input, form submissions, and
direct rendering of pages.
- **Response Body**: By default, methods in `@Controller` do not return the
response body directly; instead, they are generally used to return views, and the
view rendering is handled by the framework.
#### Example:
```java
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController {
- In this example, the `homePage()` method returns the name of a view (`home`),
which will be resolved to a file like `home.jsp` or `home.html` based on the
configured view resolver.
### 2. **@RestController**
#### Example:
```java
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyRestController {
class MyData {
private String greeting;
private String target;
| **Feature** | **@Controller** |
**@RestController** |
|------------------------------|------------------------------------------|--------
-----------------------------------------|
| **Purpose** | Used to define controllers that handle web
requests and return views. | Used to define RESTful web services that return data
(usually JSON or XML). |
| **Response Type** | Typically returns a **view name** (e.g.,
`home.jsp`) that gets rendered as HTML. | Returns data (POJOs) directly as JSON or
XML, automatically serialized. |
| **Return Value** | Returns a **view name** or **ModelAndView**. |
Returns the response body (e.g., a POJO, a list of objects). |
| **View Rendering** | Involves rendering views (e.g., JSP, Thymeleaf).
| No view rendering, just returning serialized data. |
| **Use Case** | Best for traditional **server-side rendered web
applications** (e.g., HTML pages). | Best for building **RESTful APIs** or
**microservices** that return data to the client. |
| **@ResponseBody** | Does not automatically apply `@ResponseBody` (you
can use it on individual methods). | Automatically applies `@ResponseBody` to all
methods. |
| **Example** | Typically returns HTML or a view to the browser.
| Typically returns JSON/XML data to the client. |
### Summary:
```java
class Parent {
private void show() {
System.out.println("Parent's private method");
}
}
```java
class Parent {
private static void show() {
System.out.println("Parent's private static method");
}
}
In this case:
- The `show()` method in `Child` **hides** the `show()` method in `Parent`, but
this is **not an override**.
- The method in the superclass is `private`, so the subclass cannot access it,
and the subclass defines its own method.
```java
class Parent {
public static void show() {
System.out.println("Parent's static method");
}
}
```java
public class Test {
public static void main(String[] args) {
Parent p = new Child();
p.show(); // Will call Parent's static method, not Child's, due to
method hiding
}
}
```
### 4. **Summary**:
- **Private Methods**: Private methods are not inherited or accessible by
subclasses, so they cannot be overridden. They are only accessible within the class
in which they are defined.
- **Static Methods**: Static methods can be hidden (not overridden) by a subclass
method with the same signature, but they are resolved at compile time based on the
reference type.
- If a static method in a parent class is private, it cannot be accessed or
hidden by a subclass.
### To conclude:
- **Private static methods cannot be overridden** (or even accessed) by subclasses.
- Static methods can be **hidden** in the subclass, but this is not true
overriding.
==================================================
In SQL, both the `LIKE` operator and the `GROUP BY` clause are used to filter or
organize data, but they serve different purposes. Let’s explore where and how each
of these can be used in SQL queries:
#### Syntax:
```sql
SELECT column1, column2
FROM table_name
WHERE column_name LIKE pattern;
```
#### Example 1: Match rows where a column starts with a specific string:
```sql
SELECT name
FROM employees
WHERE name LIKE 'J%'; -- Finds names starting with 'J'
```
#### Example 2: Match rows where a column ends with a specific string:
```sql
SELECT email
FROM users
WHERE email LIKE '%@gmail.com'; -- Finds emails ending with '@gmail.com'
```
#### Note:
- `LIKE` is case-insensitive in some databases (like MySQL) but case-sensitive in
others (like PostgreSQL). You can use `ILIKE` for case-insensitive matching in
PostgreSQL.
---
#### Syntax:
```sql
SELECT column1, aggregate_function(column2)
FROM table_name
WHERE condition
GROUP BY column1;
```
- This query groups the rows by `department` and calculates the average salary for
each group.
- This query groups the rows by both `country` and `city` and then counts how many
customers are in each unique combination of country and city.
```sql
SELECT department, COUNT(*)
FROM employees
GROUP BY department
HAVING COUNT(*) > 10; -- Only show departments with more than 10 employees
```
---
#### Example:
```sql
SELECT department, COUNT(*)
FROM employees
WHERE name LIKE 'J%' -- Find employees whose name starts with 'J'
GROUP BY department;
```
In this query:
- The `WHERE` clause filters employees whose names start with 'J' using the `LIKE`
operator.
- The `GROUP BY` clause groups the filtered results by `department`, and `COUNT(*)`
gives the number of such employees in each department.
---
### Summary:
- **`LIKE`**: Used in the `WHERE` clause for pattern matching in string columns.
Useful for filtering rows based on string patterns (e.g., starts with, ends with,
contains).
- **`GROUP BY`**: Used to group rows based on one or more columns and apply
aggregate functions (e.g., `COUNT()`, `SUM()`, `AVG()`) to summarize data.
Both operators can be combined in a single query to filter and summarize data at
the same time.
===================================
If you want to apply the `HAVING` clause in a query to filter only the **HR
department**, while still grouping by department and counting the employees, you
would typically use the `WHERE` clause to filter for the **HR** department
**before** performing the grouping, and then apply the `HAVING` clause to filter
based on the count condition.
### Explanation:
- **`WHERE department = 'HR'`**: Filters the rows to only include employees in the
**HR** department before the grouping happens.
- **`GROUP BY department`**: Groups the results by the department.
- **`HAVING COUNT(*) > 10`**: Filters the groups after the aggregation. It ensures
that only the HR department (if it has more than 10 employees) is included in the
result.
### What if you want to check for HR department and any other department with more
than 10 employees?
If you want to check **all departments** and also specifically look for the **HR**
department having more than 10 employees, you can keep the `GROUP BY` and `HAVING`
clauses as they were originally, and then add a condition to check for **HR**
department specifically in the result set. For example:
```sql
SELECT department, COUNT(*)
FROM employees
GROUP BY department
HAVING COUNT(*) > 10
OR department = 'HR'; -- Specifically show HR department if it has less than or
more than 10 employees
```
In this case:
- The query will show **all departments** with more than 10 employees, but also
show the **HR** department regardless of the employee count.
---
### Summary:
- Use `WHERE department = 'HR'` to **filter** the rows for HR before grouping.
- Use `HAVING COUNT(*) > 10` to apply the condition after the group is created.
- If you need to include specific conditions like showing HR **regardless of
employee count**, use `HAVING` with an `OR` clause for specific logic.
================================================
In Java, especially when working with Spring (e.g., **Spring Boot**), it's common
to define **custom exceptions** and create a **global exception handler** to handle
those exceptions in a structured way. A global exception handler ensures that
exceptions are handled consistently across the application, without needing to
write exception-handling code in each controller.
A **custom exception** allows you to define specific types of errors that can occur
in your application, with custom messages and properties.
Once you have created your custom exception, you can throw it when a specific error
condition occurs in your service or controller.
- If the user with the given `id` is not found in the repository, the custom
exception `ResourceNotFoundException` is thrown.
```java
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ControllerAdvice;
@ControllerAdvice
public class GlobalExceptionHandler {
#### Explanation:
- **`@ControllerAdvice`**: This annotation marks the class as a global exception
handler. It can be used to handle exceptions for all controllers in your
application.
- **`@ExceptionHandler(ResourceNotFoundException.class)`**: This method will handle
exceptions of type `ResourceNotFoundException` and return a custom response. In
this case, it returns a `404 Not Found` status code along with the exception
message.
- **`handleGenericException`**: This method is used for generic exceptions. It
returns a `500 Internal Server Error` status with a generic error message.
You can customize the response further by returning a more structured error object,
such as an error code, a timestamp, or additional details. Here's an example of
returning a structured response:
```java
public class ErrorResponse {
private String message;
private int statusCode;
private long timestamp;
```java
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<ErrorResponse>
handleResourceNotFoundException(ResourceNotFoundException ex) {
ErrorResponse errorResponse = new ErrorResponse(ex.getMessage(),
HttpStatus.NOT_FOUND.value());
return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleGenericException(Exception ex) {
ErrorResponse errorResponse = new ErrorResponse("An unexpected error
occurred: " + ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value());
return new ResponseEntity<>(errorResponse,
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
```
Now, instead of just returning a simple string message, the `ErrorResponse` object
is returned in the response body, providing a more structured and readable format.
---
```java
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
@ControllerAdvice
public class GlobalExceptionHandler {
This handles validation errors and builds a custom error message that lists all the
invalid fields and their respective error messages.
---