Java Backend:
1. What are the key OOP principles in Java?
Answer:
• Encapsulation: Wrapping data and methods into a single unit (class).
• Inheritance: A child class inherits properties/methods from a parent class.
• Polymorphism: One method behaving differently based on the object (method
overloading/overriding).
• Abstraction: Hiding implementation details and showing only functionality.
2. How do you handle exceptions in Java?
Answer:
• Use try-catch blocks to handle expected exceptions.
• Use finally for cleanup code.
• Throw custom exceptions for business logic errors.
• Best Practices:
o Catch specific exceptions (IOException, SQLException, etc.)
o Don’t swallow exceptions silently.
o Always log errors with context.
3. How do you create a RESTful API in Spring Boot?
Answer:
1. Use @RestController to define the controller.
2. Use @GetMapping, @PostMapping, etc., for HTTP methods.
3. Use @RequestBody for input and @ResponseBody for output.
4. Use @PathVariable and @RequestParam to capture input from URL.
Java code:
@RestController
@RequestMapping("/api/users")
public class UserController {
@GetMapping("/{id}")
public ResponseEntity<User> getUser(@PathVariable Long id) {
return ResponseEntity.ok(userService.getUserById(id));
4. What are Spring Boot Starters?
Answer:
Spring Boot starters are pre-configured dependencies for common tasks.
Example:
• spring-boot-starter-web: Includes Spring MVC, embedded Tomcat.
• spring-boot-starter-data-jpa: For JPA and Hibernate integration.
5. What is Dependency Injection (DI)?
Answer:
A design pattern where Spring injects object dependencies automatically instead of you creating
them manually using new.
• Achieved using:
o @Autowired
o Constructor Injection (recommended)
6. Difference between SQL and NoSQL databases?
Answer:
1. Data Structure
• MySQL:
• Uses a tabular structure with rows and columns.
• Requires a predefined schema, making it suitable for structured data.
• NoSQL:
• Employs various data models such as document-based, key-value, column-family, or
graph-based.
• Allows for flexible schemas, accommodating unstructured or semi-structured data.
2. Scalability
• MySQL:
• Primarily vertically scalable, meaning it requires more powerful hardware to handle
increased loads.
• Scaling can be challenging due to its rigid schema.
• NoSQL:
• Horizontally scalable, allowing data to be distributed across multiple servers.
• Better suited for handling large volumes of traffic and data.
3. Query Language
• MySQL:
• Utilizes Structured Query Language (SQL) for data manipulation and retrieval.
• Well-suited for complex queries and transactions.
• NoSQL:
• Does not have a standard query language; each NoSQL database may use its own
syntax.
• Generally optimized for fast read/write operations.
4. Data Integrity and Consistency
• MySQL:
• Follows ACID properties (Atomicity, Consistency, Isolation, Durability) to ensure
reliable transactions.
• Ideal for applications requiring strong consistency, such as banking systems.
• NoSQL:
• Often follows BASE (Basically Available, Soft state, Eventually consistent) principles,
prioritizing availability over strict consistency.
• Suitable for applications where eventual consistency is acceptable.
5. Use Cases
• MySQL:
• Best for applications with complex queries and transactional systems (e.g., ERP,
CRM).
• Commonly used in legacy systems that require a relational structure.
• NoSQL:
• Ideal for big data applications, real-time web apps, and scenarios with rapidly
changing data structures.
• Frequently used in social media, content management systems, and applications
with unstructured data.
Examples of Each Database Type
• MySQL:
• Popular implementations include MySQL, PostgreSQL, Oracle, and Microsoft SQL
Server.
• NoSQL:
• Common examples include MongoDB, Cassandra, CouchDB, and Neo4j.
7. What are key features of Microservices?
Answer:
• Independent deployable services
• Own database per service (DB per microservice)
• Communicate via REST or messaging queues (e.g., RabbitMQ)
• Use Eureka for service discovery, API Gateway for routing
• Challenges: Data consistency, latency, distributed tracing
8. How do microservices communicate?
Answer:
• Synchronous: RESTful APIs (Spring Boot controllers)
• Asynchronous: Message queues (RabbitMQ, Kafka)
• Use Feign clients or RestTemplate/WebClient for service calls
9. How do you deploy Spring Boot on AWS?
Answer:
• Package your app as a .jar using Maven.
• Deploy to:
o EC2: Launch VM, install Java, and run java -jar app.jar
o Elastic Beanstalk: Managed environment for easy deployment
o ECS/EKS: For Dockerized microservices
• Store assets in S3, use RDS for databases
• Monitor via CloudWatch, manage access with IAM
10. Given an array arr[], check if it is sorted in ascending order or not. Equal values are allowed in
an array and two consecutive equal values are considered sorted.
Examples:
Input: arr[] = [10, 20, 30, 40, 50]
Output: true
Explanation: The given array is sorted.
Input: arr[] = [90, 80, 100, 70, 40, 30]
Output: false
Explanation: The given array is not sorted.
Answer:
class GFG {
static boolean isSorted(int arr[]) {
int n = arr.length;
// Iterate over the array and check if
// every element is greater than or
// equal to previous element.
for (int i = 1; i < n; i++)
if (arr[i - 1] > arr[i])
return false;
return true;
public static void main(String[] args) {
int arr[] = { 10, 20, 30, 40, 50 };
int n = arr.length;
if (isSorted(arr))
System.out.print("true\n");
else
System.out.print("false\n");
Output:- true.
// you can add some questions more as per your project need. Also you go in depth about his
project.
// You can also conduct the interview process as per our project need.