<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vivek Nishant</title>
    <description>The latest articles on DEV Community by Vivek Nishant (@vivek1030).</description>
    <link>https://dev.to/vivek1030</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1485191%2F0d1ee284-2675-4a31-9ee7-351936096224.png</url>
      <title>DEV Community: Vivek Nishant</title>
      <link>https://dev.to/vivek1030</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vivek1030"/>
    <language>en</language>
    <item>
      <title>Kafka Top 10 Interview Questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Wed, 08 Jan 2025 12:24:46 +0000</pubDate>
      <link>https://dev.to/vivek1030/kafka-top-10-interview-questions-1876</link>
      <guid>https://dev.to/vivek1030/kafka-top-10-interview-questions-1876</guid>
      <description>&lt;p&gt;Here are &lt;strong&gt;10 commonly asked interview questions on Apache Kafka&lt;/strong&gt;:&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1. What is Apache Kafka, and what are its key components?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Kafka is a distributed event-streaming platform used for building real-time data pipelines and applications.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key components:&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Producer:&lt;/strong&gt; Sends data to topics.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumer:&lt;/strong&gt; Reads data from topics.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Broker:&lt;/strong&gt; Kafka server storing messages.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Topic:&lt;/strong&gt; Categories where records are sent.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zookeeper/Controller:&lt;/strong&gt; Manages the Kafka cluster metadata (Zookeeper is being replaced by Kafka Raft in newer versions).
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2. How does Kafka ensure message durability and fault tolerance?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Kafka achieves durability and fault tolerance through:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Replication:&lt;/strong&gt; Topics are divided into partitions, and each partition is replicated across multiple brokers.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Acknowledgements:&lt;/strong&gt; Producers can request acknowledgments (&lt;code&gt;acks&lt;/code&gt;) to ensure messages are written.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Commit Log:&lt;/strong&gt; Messages are stored in a log, making them recoverable even after crashes.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3. What is a Kafka partition, and how does it work?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;Partitions are the basic unit of parallelism in Kafka.
&lt;/li&gt;
&lt;li&gt;Each partition is an ordered sequence of records, and a topic can have one or more partitions.
&lt;/li&gt;
&lt;li&gt;Data is distributed across partitions using &lt;strong&gt;key-based partitioning&lt;/strong&gt; or &lt;strong&gt;round-robin (default)&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Consumers read data in order within a partition.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4. How does Kafka handle data retention?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Kafka retains data for a configured period (&lt;code&gt;log.retention.ms&lt;/code&gt;) or until a storage size limit (&lt;code&gt;log.retention.bytes&lt;/code&gt;) is reached.
&lt;/li&gt;
&lt;li&gt;Old records are deleted based on these configurations.
&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;cleanup policy&lt;/strong&gt; can also be set to &lt;code&gt;compact&lt;/code&gt; to keep only the latest key-value pairs.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5. What is the role of Zookeeper in Kafka?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Zookeeper manages Kafka metadata, including:&lt;/li&gt;
&lt;li&gt;Tracking brokers in the cluster.&lt;/li&gt;
&lt;li&gt;Leader election for partitions.&lt;/li&gt;
&lt;li&gt;Storing configurations for topics and ACLs.
&lt;/li&gt;
&lt;li&gt;Starting from &lt;strong&gt;Kafka 2.8&lt;/strong&gt;, Zookeeper is being replaced by &lt;strong&gt;KRaft&lt;/strong&gt; (Kafka Raft) for metadata management.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;6. How is Kafka different from traditional message queues like RabbitMQ?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Kafka is designed for distributed systems and focuses on scalability, durability, and high throughput.
&lt;/li&gt;
&lt;li&gt;Unlike RabbitMQ, Kafka:
&lt;/li&gt;
&lt;li&gt;Retains messages for a configurable period.
&lt;/li&gt;
&lt;li&gt;Decouples producers and consumers.
&lt;/li&gt;
&lt;li&gt;Supports event replay from logs.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;7. Explain the consumer group mechanism in Kafka.&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Consumers subscribe to topics as part of a &lt;strong&gt;consumer group&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Kafka ensures that each partition is consumed by only one consumer in a group for parallelism.
&lt;/li&gt;
&lt;li&gt;If a consumer fails, another in the group takes over its partitions.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;8. What is Kafka’s ISR (In-Sync Replica) mechanism?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;ISR refers to replicas of a partition that are fully synchronized with the leader partition.
&lt;/li&gt;
&lt;li&gt;Kafka writes only to partitions where all ISR members have acknowledged the write.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;9. How do you monitor Kafka performance?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Common monitoring tools include:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Metrics:&lt;/strong&gt; Kafka exposes JMX metrics, such as throughput, replication lag, and disk usage.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tools:&lt;/strong&gt; Prometheus, Grafana, Confluent Control Center.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logs:&lt;/strong&gt; Analyze broker, producer, and consumer logs for issues.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;10. What are the common challenges with Kafka, and how can they be mitigated?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data loss:&lt;/strong&gt; Configure proper replication and acknowledgment.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumer lag:&lt;/strong&gt; Monitor lag and scale consumer groups if needed.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partition imbalance:&lt;/strong&gt; Use partition rebalancing tools.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High latency:&lt;/strong&gt; Optimize producer/consumer configurations (e.g., batch size, compression).
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




</description>
    </item>
    <item>
      <title>Angular Interview Questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Mon, 30 Dec 2024 05:57:06 +0000</pubDate>
      <link>https://dev.to/vivek1030/angular-interview-questions-4pik</link>
      <guid>https://dev.to/vivek1030/angular-interview-questions-4pik</guid>
      <description>&lt;p&gt;Here’s a curated list of the &lt;strong&gt;top 20 most-asked Angular interview questions&lt;/strong&gt;, covering a mix of basic, intermediate, and advanced topics:&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1. What is Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain Angular as a TypeScript-based framework used for building web applications, focusing on features like modularity, components, and dependency injection.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2. What is the architecture of Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Discuss the structure of Angular applications, including &lt;strong&gt;Modules, Components, Templates, Services, Directives, and Routing&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3. What is a Component in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain that a Component is the building block of an Angular application, containing logic (TypeScript), view (HTML), and styling (CSS).&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4. What are Directives in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Define &lt;strong&gt;Directives&lt;/strong&gt; as classes used to modify DOM elements. Differentiate between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structural directives&lt;/strong&gt; (e.g., &lt;code&gt;*ngIf&lt;/code&gt;, &lt;code&gt;*ngFor&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attribute directives&lt;/strong&gt; (e.g., &lt;code&gt;[ngClass]&lt;/code&gt;, &lt;code&gt;[ngStyle]&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5. What are the types of Data Binding in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain the four types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Interpolation&lt;/strong&gt;: &lt;code&gt;{{expression}}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Property Binding&lt;/strong&gt;: &lt;code&gt;[property]="value"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Binding&lt;/strong&gt;: &lt;code&gt;(event)="handler()"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two-way Binding&lt;/strong&gt;: &lt;code&gt;[(ngModel)]="value"&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;6. What is Dependency Injection in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Describe how Angular provides &lt;strong&gt;services&lt;/strong&gt; to components and other services using its built-in dependency injection mechanism.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;7. What are Angular Modules?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Discuss how &lt;strong&gt;NgModules&lt;/strong&gt; group related components, directives, pipes, and services into cohesive blocks. Mention the &lt;code&gt;@NgModule&lt;/code&gt; decorator.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;8. What is the difference between &lt;code&gt;Template-driven&lt;/code&gt; and &lt;code&gt;Reactive&lt;/code&gt; forms?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Highlight key differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Template-driven forms: Simpler, uses HTML and directives like &lt;code&gt;ngModel&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reactive forms: More robust, uses &lt;code&gt;FormGroup&lt;/code&gt; and &lt;code&gt;FormControl&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;9. What are Angular Lifecycle Hooks?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Discuss hooks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ngOnInit()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ngOnChanges()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ngAfterViewInit()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ngOnDestroy()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;10. What is Angular Routing?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain how Angular uses the &lt;code&gt;RouterModule&lt;/code&gt; to define routes, navigate between views, and implement lazy loading for performance optimization.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;11. What is &lt;code&gt;HttpClient&lt;/code&gt; in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Describe it as the Angular service for making HTTP requests. Mention its support for &lt;strong&gt;Observables&lt;/strong&gt; and methods like &lt;code&gt;get()&lt;/code&gt;, &lt;code&gt;post()&lt;/code&gt;, &lt;code&gt;put()&lt;/code&gt;, and &lt;code&gt;delete()&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;12. What are Pipes in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain how &lt;strong&gt;Pipes&lt;/strong&gt; transform data in templates. Mention built-in pipes (&lt;code&gt;| currency&lt;/code&gt;, &lt;code&gt;| date&lt;/code&gt;, &lt;code&gt;| async&lt;/code&gt;) and how to create custom pipes.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;13. What is Change Detection in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain how Angular’s &lt;strong&gt;Change Detection&lt;/strong&gt; checks for updates in the application’s state and updates the DOM accordingly. Mention &lt;code&gt;Zone.js&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;14. What is the difference between &lt;code&gt;ViewChild&lt;/code&gt; and &lt;code&gt;ContentChild&lt;/code&gt;?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ViewChild&lt;/code&gt;: Accesses elements or components in the template.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ContentChild&lt;/code&gt;: Accesses projected content inside &lt;code&gt;&amp;lt;ng-content&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;15. What are Angular Guards?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Discuss different guards (&lt;code&gt;CanActivate&lt;/code&gt;, &lt;code&gt;CanDeactivate&lt;/code&gt;, &lt;code&gt;Resolve&lt;/code&gt;, &lt;code&gt;CanLoad&lt;/code&gt;) and how they manage navigation and route access.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;16. What is the purpose of &lt;code&gt;RxJS&lt;/code&gt; in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain how &lt;code&gt;RxJS&lt;/code&gt; provides &lt;strong&gt;Observables&lt;/strong&gt; for reactive programming, allowing you to handle asynchronous operations efficiently.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;17. What is the difference between JIT and AOT Compilation?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JIT (Just-in-Time)&lt;/strong&gt;: Compiles code in the browser at runtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AOT (Ahead-of-Time)&lt;/strong&gt;: Compiles code during the build process, leading to faster runtime.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;18. What is the difference between &lt;code&gt;Subject&lt;/code&gt;, &lt;code&gt;BehaviorSubject&lt;/code&gt;, and &lt;code&gt;ReplaySubject&lt;/code&gt;?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subject&lt;/strong&gt;: Basic observable emitting data to subscribers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BehaviorSubject&lt;/strong&gt;: Emits the latest value and initial value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ReplaySubject&lt;/strong&gt;: Emits a specific number of last values to new subscribers.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;19. How do you implement Lazy Loading in Angular?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Discuss splitting the application into feature modules and using &lt;code&gt;loadChildren&lt;/code&gt; in the route configuration.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;20. How do you handle error scenarios in Angular applications?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Talk about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using &lt;code&gt;HttpInterceptor&lt;/code&gt; for centralized error handling.&lt;/li&gt;
&lt;li&gt;Implementing &lt;code&gt;catchError&lt;/code&gt; in RxJS.&lt;/li&gt;
&lt;/ul&gt;




</description>
    </item>
    <item>
      <title>Database Interview Questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Fri, 20 Dec 2024 11:43:51 +0000</pubDate>
      <link>https://dev.to/vivek1030/database-interview-questions-j0m</link>
      <guid>https://dev.to/vivek1030/database-interview-questions-j0m</guid>
      <description>&lt;p&gt;Here are the top 20 most commonly asked interview questions for SQL and NoSQL, along with their answers:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;SQL Interview Questions with Answers&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; SQL (Structured Query Language) is a standardized programming language used to manage and manipulate relational databases. It is used for tasks such as querying data, updating data, inserting records, and deleting records.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between SQL and NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; SQL databases are relational, structured, and use tables to store data, while NoSQL databases are non-relational, flexible, and can store data in a variety of formats such as key-value, document, columnar, or graph formats. SQL is typically used in applications requiring strong consistency, while NoSQL is better suited for unstructured data and large-scale applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are the different types of JOINs in SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;INNER JOIN:&lt;/strong&gt; Returns records that have matching values in both tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LEFT JOIN (OUTER):&lt;/strong&gt; Returns all records from the left table and matched records from the right table. Unmatched records from the right table will be NULL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RIGHT JOIN (OUTER):&lt;/strong&gt; Returns all records from the right table and matched records from the left table. Unmatched records from the left table will be NULL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FULL OUTER JOIN:&lt;/strong&gt; Returns records when there is a match in either the left or right table. Unmatched records will be NULL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CROSS JOIN:&lt;/strong&gt; Returns the Cartesian product of both tables (every combination of rows from both tables).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is normalization and denormalization?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Normalization&lt;/strong&gt; is the process of organizing data in a way that reduces redundancy and dependency, typically through multiple tables linked by foreign keys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Denormalization&lt;/strong&gt; is the process of combining tables to improve read performance at the cost of redundancy and additional storage.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between WHERE and HAVING?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; &lt;code&gt;WHERE&lt;/code&gt; is used to filter rows before grouping (used in SELECT, UPDATE, DELETE queries), while &lt;code&gt;HAVING&lt;/code&gt; is used to filter groups after using aggregate functions (used with GROUP BY).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are aggregate functions in SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Aggregate functions operate on a set of values to return a single value. Common aggregate functions are:

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;COUNT()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SUM()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AVG()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MAX()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MIN()&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a primary key and foreign key?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Primary Key&lt;/strong&gt; uniquely identifies each record in a table. It must be unique and cannot contain NULL values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Foreign Key&lt;/strong&gt; is a field in one table that is a primary key in another table, used to create a relationship between the two tables.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is an index?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; An index is a database object that improves the speed of data retrieval operations on a table at the cost of additional space and maintenance time. It is created on columns that are frequently searched.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are subqueries and how do they differ from joins?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A &lt;strong&gt;subquery&lt;/strong&gt; is a query nested within another query. It is used to retrieve data that will be used by the outer query. A &lt;strong&gt;join&lt;/strong&gt; combines data from two or more tables based on a related column, whereas a subquery provides a result that is used in another query (SELECT, INSERT, UPDATE, DELETE).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a stored procedure?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A stored procedure is a precompiled collection of one or more SQL statements that can be executed as a single unit. It helps in encapsulating business logic, improving performance, and enhancing security.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are triggers in SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A trigger is a special type of stored procedure that automatically executes or fires when certain events occur, such as an &lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt;, or &lt;code&gt;DELETE&lt;/code&gt; operation on a table.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a transaction in SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A transaction is a sequence of one or more SQL operations that are treated as a single unit. It ensures data consistency using the ACID properties: 

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Atomicity&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistency&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isolation&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durability&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Explain the difference between UNION and UNION ALL.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;UNION&lt;/strong&gt; returns unique rows from multiple SELECT queries (removes duplicates).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UNION ALL&lt;/strong&gt; returns all rows, including duplicates.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a view in SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A view is a virtual table created by a SELECT query that presents data from one or more tables. It does not store data itself but provides a way to simplify complex queries or secure data access.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between a clustered and a non-clustered index?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clustered Index&lt;/strong&gt; determines the physical order of data in the table and can only have one per table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-clustered Index&lt;/strong&gt; creates a separate object that points to the table’s data and can have multiple indexes per table.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is data integrity and how is it ensured in SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Data integrity ensures the accuracy and consistency of data. It is enforced using constraints like &lt;strong&gt;PRIMARY KEY&lt;/strong&gt;, &lt;strong&gt;FOREIGN KEY&lt;/strong&gt;, &lt;strong&gt;UNIQUE&lt;/strong&gt;, &lt;strong&gt;CHECK&lt;/strong&gt;, and &lt;strong&gt;NOT NULL&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a schema in SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A schema is a logical container for database objects such as tables, views, and procedures. It is used to organize database elements and manage security.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Explain the difference between CHAR and VARCHAR data types.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CHAR&lt;/strong&gt; is a fixed-length character data type. If the data is shorter than the specified length, it is padded with spaces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VARCHAR&lt;/strong&gt; is a variable-length character data type, which uses only the necessary space to store the data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a composite key?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A composite key is a combination of two or more columns in a table that uniquely identifies a record. It is used when no single column can uniquely identify a row.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are transactions and what is their importance?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A transaction is a sequence of operations performed as a single unit. They are important for ensuring the database's ACID properties, ensuring data consistency and reliability in multi-step operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;NoSQL Interview Questions with Answers&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; NoSQL (Not Only SQL) refers to a class of databases that do not use the traditional relational model. NoSQL databases are flexible, scalable, and can handle unstructured or semi-structured data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are the types of NoSQL databases?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key-Value Stores:&lt;/strong&gt; Store data as key-value pairs (e.g., Redis, DynamoDB).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Document Stores:&lt;/strong&gt; Store data as documents (e.g., MongoDB, CouchDB).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Column-Family Stores:&lt;/strong&gt; Store data in columns rather than rows (e.g., Cassandra, HBase).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Graph Databases:&lt;/strong&gt; Store data as nodes and relationships (e.g., Neo4j).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the CAP Theorem?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; The &lt;strong&gt;CAP Theorem&lt;/strong&gt; states that a distributed database system can provide only two of the following three properties:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; Every read operation will return the most recent write.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Availability:&lt;/strong&gt; Every request will receive a response (either success or failure).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partition Tolerance:&lt;/strong&gt; The system can handle network partitions.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is sharding in NoSQL databases?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Sharding is the process of distributing data across multiple machines to improve scalability and performance. Each shard contains a portion of the data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is denormalization in NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Denormalization in NoSQL refers to storing data in a way that reduces the need for joins, often by storing repeated or redundant data to optimize read performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between SQL and NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; SQL databases are relational, table-based, and enforce a fixed schema, whereas NoSQL databases are non-relational, schema-less, and support a variety of data models like key-value, document, column-family, and graph databases.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a document store in NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A document store is a type of NoSQL database that stores data as documents (e.g., JSON, BSON, or XML) rather than rows and columns, making it highly flexible (e.g., MongoDB, CouchDB).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a key-value store in NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A key-value store is a NoSQL database that stores data as key-value pairs, where the key is a unique identifier and the value is the associated data (e.g., Redis, DynamoDB).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a column-family store?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A column-family store is a type of NoSQL database where data is stored in columns rather than rows. Each column family is a set of rows with a shared schema (e.g., Cassandra, HBase).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a graph database?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A graph database uses graph structures for semantic queries. Data is stored in nodes (entities) and edges (relationships) with properties (e.g., Neo4j).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is eventual consistency in NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Eventual consistency is the consistency&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;model used in many NoSQL databases, where updates to the data are propagated to all nodes eventually but not necessarily immediately.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is data replication in NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; Data replication is the process of copying data across multiple nodes or servers to ensure high availability and fault tolerance in NoSQL databases.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is an index in NoSQL databases?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; An index in NoSQL databases speeds up data retrieval by creating a reference (lookup table) for specific values, similar to indexing in relational databases.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;How do you scale NoSQL databases?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; NoSQL databases scale horizontally by adding more servers or nodes to handle increased load and distribute data. This is often done via sharding and replication.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is MapReduce in NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; MapReduce is a programming model used for processing large datasets in parallel. It divides the task into a "Map" step (distribute data) and a "Reduce" step (aggregate results).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are the limitations of NoSQL databases?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; NoSQL databases may lack full ACID transactions, making them less suitable for applications requiring strict consistency. They can also struggle with complex queries and relational data models.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is a document in MongoDB?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; A document in MongoDB is a record stored in BSON (Binary JSON) format. It is flexible, schema-less, and can contain nested structures.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;How does CouchDB handle conflicts in distributed systems?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; CouchDB uses Multi-Version Concurrency Control (MVCC) and resolves conflicts during replication by using versioning and allowing developers to manually resolve conflicting changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is an atomic operation in NoSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; An atomic operation ensures that a database operation is completed entirely or not at all, preventing partial updates that could cause data inconsistencies.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the role of a NoSQL database in big data?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt; NoSQL databases are ideal for handling big data because they support horizontal scaling, flexible data models, and high availability, making them suitable for processing large volumes of unstructured or semi-structured data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Microservice Interview Questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Fri, 20 Dec 2024 11:40:35 +0000</pubDate>
      <link>https://dev.to/vivek1030/microservice-questions-46kb</link>
      <guid>https://dev.to/vivek1030/microservice-questions-46kb</guid>
      <description>&lt;p&gt;Here are the &lt;strong&gt;Top 20 Most Asked Microservices Interview Questions&lt;/strong&gt; along with detailed answers:&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1. What are microservices, and how do they differ from monolithic architectures?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Microservices are an architectural style where an application is composed of small, independent services that communicate over a network. Each microservice handles a specific business capability and is independently deployable, scalable, and testable.&lt;br&gt;&lt;br&gt;
In contrast, a &lt;strong&gt;monolithic architecture&lt;/strong&gt; is a traditional design where the application is built as a single unit. This can lead to scalability and maintenance challenges as the application grows.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2. What are the advantages and disadvantages of a microservices architecture?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Each service can be scaled independently based on its load.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resilience:&lt;/strong&gt; Failures in one service do not directly affect others.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility:&lt;/strong&gt; Services can use different technologies, programming languages, or databases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster development:&lt;/strong&gt; Smaller teams can work on different services independently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt; Managing many services can become difficult.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data consistency:&lt;/strong&gt; Ensuring consistency between services can be challenging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network overhead:&lt;/strong&gt; Communication between services introduces latency.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3. How does a microservices architecture improve scalability and fault tolerance?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Microservices can be scaled independently. If one service experiences high load, it can be scaled without affecting other services. Fault tolerance is improved by isolating failures: if one service fails, it doesn’t bring down the entire application. Techniques like &lt;strong&gt;circuit breakers&lt;/strong&gt;, retries, and &lt;strong&gt;replication&lt;/strong&gt; are used to ensure resilience.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4. What is an API Gateway, and why is it important in a microservices architecture?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
An API Gateway is a server that acts as an entry point for all client requests in a microservices-based system. It routes requests to the appropriate service, handles authentication, and aggregates responses. It simplifies the client-side logic by providing a single endpoint, reducing the need for clients to manage multiple service endpoints.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5. How do microservices communicate with each other?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Microservices communicate using lightweight protocols such as HTTP/REST or gRPC. Common communication methods include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous communication:&lt;/strong&gt; Using HTTP/REST for real-time communication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous communication:&lt;/strong&gt; Using message brokers like Kafka or RabbitMQ to decouple services.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;6. What is service discovery, and how does it work in a microservices environment?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Service discovery enables microservices to dynamically find and communicate with each other. When a new service instance is deployed, it registers with a service registry (like &lt;strong&gt;Consul&lt;/strong&gt;, &lt;strong&gt;Eureka&lt;/strong&gt;). Other services can query this registry to locate and interact with the required service.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;7. What is the role of containers (e.g., Docker) in microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Containers (such as Docker) provide a lightweight, portable way to package microservices. Each service is isolated in its container, ensuring consistency across different environments (development, testing, production). Containers allow microservices to be easily deployed and scaled in a cloud environment.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;8. What is a database-per-service pattern, and why is it beneficial in microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;database-per-service&lt;/strong&gt; pattern means that each microservice owns its own database. This ensures that services are loosely coupled, as they don't share a single database. It enables independent scaling, better fault isolation, and allows each service to choose the most appropriate database technology for its needs.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;9. What are some common challenges you face when implementing microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt; Managing multiple services increases operational complexity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data consistency:&lt;/strong&gt; Handling consistency across distributed services can be difficult.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitoring and debugging:&lt;/strong&gt; Troubleshooting issues in a distributed system can be challenging without the right tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inter-service communication:&lt;/strong&gt; Managing communication and network latency between services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Ensuring secure communication between services.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;10. What is the Circuit Breaker pattern, and why is it used in microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Circuit Breaker&lt;/strong&gt; pattern prevents a service from making requests to a failing service. If a service is down or underperforming, the circuit breaker "trips," and further calls are blocked for a period. This prevents cascading failures and gives the system time to recover.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;11. How do you handle authentication and authorization across microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Authentication and authorization are typically handled using a centralized identity provider (e.g., &lt;strong&gt;OAuth&lt;/strong&gt;, &lt;strong&gt;JWT&lt;/strong&gt;). The API Gateway validates incoming requests and passes the user’s identity and permissions to microservices. Each service uses the information for fine-grained access control.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;12. What is the role of a message broker (e.g., RabbitMQ, Kafka) in microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A &lt;strong&gt;message broker&lt;/strong&gt; allows microservices to communicate asynchronously. It decouples services, enabling them to operate independently and improve fault tolerance. Common message brokers include &lt;strong&gt;Kafka&lt;/strong&gt; (for high-throughput event streaming) and &lt;strong&gt;RabbitMQ&lt;/strong&gt; (for reliable message delivery).&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;13. What is the difference between synchronous and asynchronous communication in microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous communication&lt;/strong&gt; occurs when a client sends a request and waits for a response (e.g., RESTful HTTP API).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous communication&lt;/strong&gt; allows services to send a message and proceed without waiting for an immediate response (e.g., messaging systems like Kafka, RabbitMQ).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;14. How do you ensure eventual consistency in a distributed system?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Eventual consistency ensures that updates across services will propagate over time, even if they don't happen immediately. Techniques include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Event-driven architecture&lt;/strong&gt;: Using events to propagate changes across services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sagas&lt;/strong&gt;: A pattern to manage distributed transactions with compensation for failure.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;15. How would you design a fault-tolerant microservices system?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A fault-tolerant system includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Redundancy:&lt;/strong&gt; Deploying services in multiple instances.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Circuit Breaker pattern:&lt;/strong&gt; To prevent failures from cascading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retries and timeouts:&lt;/strong&gt; To handle transient failures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Failover mechanisms:&lt;/strong&gt; For automatic service recovery.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Graceful degradation:&lt;/strong&gt; To continue functioning with limited capabilities when some services fail.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;16. What tools or strategies do you use for monitoring microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Monitoring tools for microservices include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prometheus&lt;/strong&gt; (metrics collection).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grafana&lt;/strong&gt; (visualization of metrics).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ELK Stack (Elasticsearch, Logstash, Kibana)&lt;/strong&gt; for logging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jaeger&lt;/strong&gt; or &lt;strong&gt;Zipkin&lt;/strong&gt; for distributed tracing.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;17. How do you ensure security in microservices, especially when communicating between them?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Security measures include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TLS/SSL encryption&lt;/strong&gt; for secure communication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OAuth 2.0 / JWT&lt;/strong&gt; for authentication and authorization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Gateway&lt;/strong&gt; for centralized security policies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service mesh&lt;/strong&gt; (e.g., Istio) to enforce security policies across services.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;18. What is the role of a service mesh (e.g., Istio) in microservices architecture?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A &lt;strong&gt;service mesh&lt;/strong&gt; provides a dedicated infrastructure layer for managing microservices communication. It handles load balancing, service discovery, observability, and security without requiring changes to the services themselves. Tools like &lt;strong&gt;Istio&lt;/strong&gt; allow you to enforce policies, monitor traffic, and secure communications.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;19. What is API versioning, and how do you handle it in microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
API versioning is the process of managing changes to an API without breaking client applications. In microservices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;URI Versioning&lt;/strong&gt;: E.g., &lt;code&gt;/v1/resource&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Header Versioning&lt;/strong&gt;: E.g., using HTTP headers to specify the API version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Semantic Versioning&lt;/strong&gt;: Versioning the API based on the impact of changes (major, minor, patch).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;20. How do you approach splitting a monolithic application into microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identify business capabilities&lt;/strong&gt;: Break the monolithic app into domains (e.g., order, inventory, payments).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Define service boundaries&lt;/strong&gt;: Ensure each service is loosely coupled and has its own database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start with a small module&lt;/strong&gt;: Convert one or two modules into microservices to test the approach.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gradual migration&lt;/strong&gt;: Migrate the remaining components in phases to avoid disruption.&lt;/li&gt;
&lt;/ul&gt;




</description>
    </item>
    <item>
      <title>Node JS top 20 questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Fri, 20 Dec 2024 11:36:38 +0000</pubDate>
      <link>https://dev.to/vivek1030/java-stream-notes-obl</link>
      <guid>https://dev.to/vivek1030/java-stream-notes-obl</guid>
      <description>&lt;p&gt;Here’s a list of &lt;strong&gt;20 Node.js interview questions&lt;/strong&gt;, covering both &lt;strong&gt;basic&lt;/strong&gt; and &lt;strong&gt;advanced&lt;/strong&gt; topics for a comprehensive preparation:&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Basic Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is Node.js, and why is it used?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js is a server-side runtime environment based on the V8 JavaScript engine, used for building fast and scalable network applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Explain the event loop in Node.js.&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The event loop is the mechanism that handles asynchronous callbacks in a single thread by delegating tasks to the system and processing them as events return.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are streams in Node.js?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Streams are objects used for reading or writing continuous chunks of data. Types include:

&lt;ul&gt;
&lt;li&gt;Readable (e.g., file read streams)&lt;/li&gt;
&lt;li&gt;Writable (e.g., file write streams)&lt;/li&gt;
&lt;li&gt;Duplex (e.g., sockets)&lt;/li&gt;
&lt;li&gt;Transform (e.g., zlib for compression).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between &lt;code&gt;setImmediate()&lt;/code&gt; and &lt;code&gt;process.nextTick()&lt;/code&gt;?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;setImmediate()&lt;/code&gt;: Executes after the current event loop completes.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;process.nextTick()&lt;/code&gt;: Executes before the next event loop iteration begins.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;How does Node.js handle concurrency?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js uses an event-driven, non-blocking I/O model via the event loop. Heavy computations are offloaded to worker threads or background processes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;How do you handle uncaught exceptions in Node.js?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the &lt;code&gt;process.on('uncaughtException', callback)&lt;/code&gt; event to handle uncaught exceptions, but it's recommended to exit the process after logging the error.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Intermediate Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What is middleware in Node.js? Provide an example.&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Middleware functions in frameworks like Express.js process requests and responses.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

   &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Middleware executed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Passes control to the next middleware/route handler&lt;/span&gt;
   &lt;span class="p"&gt;});&lt;/span&gt;

   &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
   &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How do you manage environment variables in Node.js?&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Use the &lt;code&gt;dotenv&lt;/code&gt; package to load environment variables from a &lt;code&gt;.env&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MY_VARIABLE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What are worker threads in Node.js?&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Worker threads are used to execute CPU-intensive JavaScript code in parallel, enabling better performance for heavy computations:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Worker&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;worker_threads&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;worker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./worker.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Explain the cluster module in Node.js.&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The cluster module allows Node.js to spawn multiple processes (workers) sharing the same server port to leverage multi-core CPUs:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cluster&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cluster&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cluster&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isMaster&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cluster&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fork&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Create worker processes&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between blocking and non-blocking I/O?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blocking I/O&lt;/strong&gt;: Operations that block the event loop until completion (e.g., &lt;code&gt;fs.readFileSync&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-blocking I/O&lt;/strong&gt;: Operations that allow the event loop to continue while waiting for execution (e.g., &lt;code&gt;fs.readFile&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the &lt;code&gt;libuv&lt;/code&gt; library in Node.js?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;libuv&lt;/code&gt; is a C library used by Node.js to handle the event loop, asynchronous I/O, and thread pool.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Advanced Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are the differences between &lt;code&gt;spawn()&lt;/code&gt;, &lt;code&gt;fork()&lt;/code&gt;, and &lt;code&gt;exec()&lt;/code&gt; in the &lt;code&gt;child_process&lt;/code&gt; module?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;spawn()&lt;/code&gt;: Executes a command and streams the output.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fork()&lt;/code&gt;: Spawns a new Node.js process for IPC (Inter-Process Communication).
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;exec()&lt;/code&gt;: Executes a command and buffers the output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the purpose of the &lt;code&gt;cluster&lt;/code&gt; module in scaling Node.js applications?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;cluster&lt;/code&gt; module enables horizontal scaling by creating worker processes to handle concurrent requests using multi-core CPUs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between &lt;code&gt;req.params&lt;/code&gt;, &lt;code&gt;req.query&lt;/code&gt;, and &lt;code&gt;req.body&lt;/code&gt; in Express.js?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;req.params&lt;/code&gt;: Retrieves route parameters (e.g., &lt;code&gt;/users/:id&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;req.query&lt;/code&gt;: Retrieves query string parameters (e.g., &lt;code&gt;/users?id=123&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;req.body&lt;/code&gt;: Retrieves payload data from POST/PUT requests.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;How do you secure a Node.js application?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use HTTPS.
&lt;/li&gt;
&lt;li&gt;Validate and sanitize inputs to prevent SQL injection and XSS.
&lt;/li&gt;
&lt;li&gt;Implement rate limiting to prevent brute force attacks.
&lt;/li&gt;
&lt;li&gt;Use libraries like &lt;code&gt;helmet&lt;/code&gt; for HTTP header security.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What are memory leaks in Node.js, and how can you debug them?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory leaks occur when objects are no longer needed but not garbage-collected. Tools like &lt;code&gt;node --inspect&lt;/code&gt;, Chrome DevTools, or &lt;code&gt;heapdump&lt;/code&gt; can help identify leaks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is event emitter, and how is it used in Node.js?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;EventEmitter&lt;/code&gt; class allows objects to subscribe to and emit events:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;events&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;event&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Event triggered&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;event&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;How does Node.js handle large file uploads efficiently?&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By using streams, Node.js processes chunks of data rather than loading the entire file into memory:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createWriteStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;file.txt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Upload complete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Explain the role of &lt;code&gt;package-lock.json&lt;/code&gt; and why it is important.&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;package-lock.json&lt;/code&gt; locks dependency versions to ensure consistent installs across environments, improving reproducibility and avoiding unexpected issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Bonus Topics
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Explain how you would implement WebSockets in Node.js.&lt;/li&gt;
&lt;li&gt;Discuss the advantages and challenges of serverless with Node.js.&lt;/li&gt;
&lt;li&gt;Implement a custom middleware in Express.js.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Java Stream Notes</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Fri, 20 Dec 2024 11:31:06 +0000</pubDate>
      <link>https://dev.to/vivek1030/java-stream-notes-592f</link>
      <guid>https://dev.to/vivek1030/java-stream-notes-592f</guid>
      <description>&lt;p&gt;Java Streams are part of the Java Collections Framework and were introduced in Java 8. They provide a powerful way to process data in a functional style, making it easier to work with collections and perform tasks like filtering, mapping, and reducing. Streams enable concise, declarative, and readable code.&lt;/p&gt;

&lt;p&gt;Here’s a breakdown of key concepts and features of Java Streams:&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1. What is a Stream?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A Stream is a sequence of elements supporting various operations to process data. It doesn’t store data itself but operates on the source (e.g., a collection, array, or I/O channel).&lt;/p&gt;

&lt;p&gt;Key Characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lazy Evaluation:&lt;/strong&gt; Operations are executed only when a terminal operation is invoked.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pipeline Processing:&lt;/strong&gt; Operations can be chained (filter, map, etc.), forming a pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Immutable:&lt;/strong&gt; The original source is not modified.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2. How to Create a Stream&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Streams can be created in several ways:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.stream.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StreamExamples&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// From a collection&lt;/span&gt;
        &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"C"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// From an array&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"X"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Y"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Z"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
        &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// From a range of numbers&lt;/span&gt;
        &lt;span class="nc"&gt;IntStream&lt;/span&gt; &lt;span class="n"&gt;stream3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;range&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1, 2, 3, 4&lt;/span&gt;

        &lt;span class="c1"&gt;// From static methods&lt;/span&gt;
        &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"World"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Infinite streams&lt;/span&gt;
        &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;iterate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 0, 2, 4, 6, ...&lt;/span&gt;
        &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream6&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Math:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;3. Types of Stream Operations&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Intermediate Operations&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;These return a new stream and are lazy (not executed until a terminal operation is invoked).&lt;/li&gt;
&lt;li&gt;Common Intermediate Operations:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;filter(Predicate)&lt;/code&gt;&lt;/strong&gt;: Filters elements based on a condition.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;map(Function)&lt;/code&gt;&lt;/strong&gt;: Transforms each element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;sorted()&lt;/code&gt; / &lt;code&gt;sorted(Comparator)&lt;/code&gt;&lt;/strong&gt;: Sorts elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;distinct()&lt;/code&gt;&lt;/strong&gt;: Removes duplicates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;limit(n)&lt;/code&gt; / &lt;code&gt;skip(n)&lt;/code&gt;&lt;/strong&gt;: Limits/skips elements.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;evenNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Keep even numbers&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;         &lt;span class="c1"&gt;// Square each number&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;collect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toList&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Collect to a list&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;evenNumbers&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: [4, 16]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Terminal Operations&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;These produce a result or a side effect.&lt;/li&gt;
&lt;li&gt;Common Terminal Operations:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;collect(Collector)&lt;/code&gt;&lt;/strong&gt;: Collects elements into a collection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;forEach(Consumer)&lt;/code&gt;&lt;/strong&gt;: Performs an action for each element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;reduce(BinaryOperator)&lt;/code&gt;&lt;/strong&gt;: Reduces the stream to a single value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;count()&lt;/code&gt;&lt;/strong&gt;: Counts elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;anyMatch()&lt;/code&gt;, &lt;code&gt;allMatch()&lt;/code&gt;, &lt;code&gt;noneMatch()&lt;/code&gt;&lt;/strong&gt;: Match predicates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;findFirst()&lt;/code&gt; / &lt;code&gt;findAny()&lt;/code&gt;&lt;/strong&gt;: Finds an element.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Charlie"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;startsWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// Keep names starting with "B"&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findFirst&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orElse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No match"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: Bob&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;4. Stream Collectors&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Collectors&lt;/code&gt; utility class provides ways to collect data from streams.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;To List:&lt;/strong&gt; &lt;code&gt;collect(Collectors.toList())&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To Map:&lt;/strong&gt; &lt;code&gt;collect(Collectors.toMap(keyMapper, valueMapper))&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Joining Strings:&lt;/strong&gt; &lt;code&gt;collect(Collectors.joining(", "))&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summarizing Statistics:&lt;/strong&gt; &lt;code&gt;collect(Collectors.summarizingInt())&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jane"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jack"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;collect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;joining&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;", "&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// "John, Jane, Jack"&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;5. Parallel Streams&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Parallel Streams divide tasks into smaller chunks and process them in parallel using multiple threads.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parallelStream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mapToInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sum&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 55&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;6. Advanced Features&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FlatMap:&lt;/strong&gt; Flattens nested streams (e.g., converting a list of lists into a single stream).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Primitive Streams:&lt;/strong&gt; Specialized streams for &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, and &lt;code&gt;double&lt;/code&gt; (e.g., &lt;code&gt;IntStream&lt;/code&gt;, &lt;code&gt;DoubleStream&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom Collectors:&lt;/strong&gt; Create custom reduction operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of &lt;code&gt;flatMap&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;nestedList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"C"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"D"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;flatList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nestedList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flatMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;List:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Flatten nested lists&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;collect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toList&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flatList&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: [A, B, C, D]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;7. Best Practices&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use parallel streams only when operations are computationally intensive and thread-safe.&lt;/li&gt;
&lt;li&gt;Avoid modifying the original collection in stream pipelines.&lt;/li&gt;
&lt;li&gt;Use method references (e.g., &lt;code&gt;Class::method&lt;/code&gt;) for concise code.&lt;/li&gt;
&lt;/ul&gt;




</description>
    </item>
    <item>
      <title>Springboot Interview Questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Fri, 20 Dec 2024 11:28:46 +0000</pubDate>
      <link>https://dev.to/vivek1030/springboot-interview-questions-27g4</link>
      <guid>https://dev.to/vivek1030/springboot-interview-questions-27g4</guid>
      <description>&lt;p&gt;Here are &lt;strong&gt;20 top important Spring Boot interview questions&lt;/strong&gt; every developer should prepare for:&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1. What is Spring Boot? Why is it used?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Spring Boot is a framework designed to simplify the development of Java applications by eliminating boilerplate configurations. It provides features like auto-configuration, embedded servers, and starter dependencies for faster and easier application development.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2. What are the key features of Spring Boot?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Auto-configuration of Spring components.&lt;/li&gt;
&lt;li&gt;Embedded servers like Tomcat, Jetty, and Undertow.&lt;/li&gt;
&lt;li&gt;Starter dependencies for preconfigured setups.&lt;/li&gt;
&lt;li&gt;Spring Boot Actuator for monitoring and management.&lt;/li&gt;
&lt;li&gt;Externalized configuration using &lt;code&gt;application.properties&lt;/code&gt; or &lt;code&gt;application.yml&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3. What is the purpose of the &lt;code&gt;@SpringBootApplication&lt;/code&gt; annotation?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Combines:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Configuration&lt;/code&gt;: Marks the class as a configuration class.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@EnableAutoConfiguration&lt;/code&gt;: Enables Spring Boot's auto-configuration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@ComponentScan&lt;/code&gt;: Scans the package for components.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4. What is the difference between Spring and Spring Boot?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Spring Framework:&lt;/strong&gt; Requires manual configuration of beans, XMLs, and dependencies.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spring Boot:&lt;/strong&gt; Provides auto-configuration, embedded servers, and opinionated defaults to simplify setup.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5. How do you configure a database connection in Spring Boot?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Add the following in &lt;code&gt;application.properties&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;  &lt;span class="py"&gt;spring.datasource.url&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;jdbc:mysql://localhost:3306/mydb&lt;/span&gt;
  &lt;span class="py"&gt;spring.datasource.username&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;root&lt;/span&gt;
  &lt;span class="py"&gt;spring.datasource.password&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;password&lt;/span&gt;
  &lt;span class="py"&gt;spring.jpa.hibernate.ddl-auto&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;update&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Include the database driver dependency in your &lt;code&gt;pom.xml&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;6. How do you create a RESTful web service in Spring Boot?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Use &lt;code&gt;@RestController&lt;/code&gt; to create endpoints. Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nd"&gt;@RestController&lt;/span&gt;
  &lt;span class="nd"&gt;@RequestMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/users"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Charlie"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;7. What are Spring Boot starters?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Starters are pre-configured dependencies for specific functionalities. Examples:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;spring-boot-starter-web&lt;/code&gt;: For web applications.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;spring-boot-starter-data-jpa&lt;/code&gt;: For JPA and Hibernate.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;spring-boot-starter-security&lt;/code&gt;: For Spring Security.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;8. What is the Spring Boot Actuator?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
A module for monitoring and managing applications in production. It provides endpoints like &lt;code&gt;/actuator/health&lt;/code&gt; and &lt;code&gt;/actuator/metrics&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;9. How do you handle exceptions in Spring Boot?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Use &lt;code&gt;@ControllerAdvice&lt;/code&gt; and &lt;code&gt;@ExceptionHandler&lt;/code&gt; for global exception handling:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nd"&gt;@ControllerAdvice&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GlobalExceptionHandler&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="nd"&gt;@ExceptionHandler&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RuntimeException&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handleException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RuntimeException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMessage&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;INTERNAL_SERVER_ERROR&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;10. What is the difference between &lt;code&gt;@RestController&lt;/code&gt; and &lt;code&gt;@Controller&lt;/code&gt;?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@RestController&lt;/code&gt;: Combines &lt;code&gt;@Controller&lt;/code&gt; and &lt;code&gt;@ResponseBody&lt;/code&gt;. It returns data (JSON/XML).
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Controller&lt;/code&gt;: Used for building web pages (views).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;11. What is Spring Data JPA?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
A Spring module for simplifying data access using JPA. It provides repository interfaces like &lt;code&gt;JpaRepository&lt;/code&gt; for common database operations.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;12. What is the difference between &lt;code&gt;CrudRepository&lt;/code&gt; and &lt;code&gt;JpaRepository&lt;/code&gt;?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;CrudRepository&lt;/code&gt;: Basic CRUD operations.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;JpaRepository&lt;/code&gt;: Extends &lt;code&gt;CrudRepository&lt;/code&gt; and adds support for JPA-specific features like pagination and batch processing.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;13. What is dependency injection, and how does Spring Boot implement it?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Dependency Injection (DI) is a design pattern where objects are injected into a class rather than being created within it. Spring Boot uses annotations like &lt;code&gt;@Autowired&lt;/code&gt; to implement DI.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;14. What are Spring Profiles?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Profiles allow you to define environment-specific configurations (e.g., dev, prod). Activate a profile using:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;  &lt;span class="py"&gt;spring.profiles.active&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;15. How does Spring Boot implement security?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
By adding the &lt;code&gt;spring-boot-starter-security&lt;/code&gt; dependency, basic authentication is enabled by default. For custom security configurations, you can extend &lt;code&gt;SecurityFilterChain&lt;/code&gt; or use &lt;code&gt;WebSecurityConfigurerAdapter&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;16. What is the purpose of the &lt;code&gt;@Qualifier&lt;/code&gt; annotation?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Used to resolve ambiguity when multiple beans of the same type exist. Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nd"&gt;@Service&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="nd"&gt;@Autowired&lt;/span&gt;
      &lt;span class="nd"&gt;@Qualifier&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"beanName"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;MyBean&lt;/span&gt; &lt;span class="n"&gt;myBean&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;17. What is the use of &lt;code&gt;@EnableAutoConfiguration&lt;/code&gt;?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
It enables Spring Boot’s auto-configuration mechanism, scanning the classpath and configuring beans automatically based on the dependencies.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;18. How does Spring Boot support microservices?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Embedded servers for standalone deployment.
&lt;/li&gt;
&lt;li&gt;RESTful APIs for communication.
&lt;/li&gt;
&lt;li&gt;Integration with Spring Cloud for service discovery, configuration management, and circuit breaking.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;19. How do you test a Spring Boot application?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Use Spring Boot Test features:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@SpringBootTest&lt;/code&gt;: Loads the entire application context.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@WebMvcTest&lt;/code&gt;: Tests only the web layer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MockMvc&lt;/code&gt;: Simulates HTTP requests for testing controllers.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;20. How do you externalize configuration in Spring Boot?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Answer:&lt;/strong&gt;
Store configurations in &lt;code&gt;application.properties&lt;/code&gt;, &lt;code&gt;application.yml&lt;/code&gt;, or external files. You can override them with environment variables or command-line arguments.&lt;/li&gt;
&lt;/ul&gt;




</description>
    </item>
    <item>
      <title>JavaScript Interview Questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Fri, 20 Dec 2024 11:22:15 +0000</pubDate>
      <link>https://dev.to/vivek1030/javascript-interview-questions-4af9</link>
      <guid>https://dev.to/vivek1030/javascript-interview-questions-4af9</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Basics&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What are the differences between &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Explain the difference between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt; in JavaScript.&lt;/li&gt;
&lt;li&gt;What is hoisting in JavaScript?&lt;/li&gt;
&lt;li&gt;Explain closures and give an example.&lt;/li&gt;
&lt;li&gt;What is the difference between function declaration and function expression?&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What are template literals, and how do you use them?&lt;/li&gt;
&lt;li&gt;Explain the difference between &lt;strong&gt;synchronous&lt;/strong&gt; and &lt;strong&gt;asynchronous&lt;/strong&gt; code.&lt;/li&gt;
&lt;li&gt;What are arrow functions, and how do they differ from regular functions?&lt;/li&gt;
&lt;li&gt;What is the difference between primitive and reference types in JavaScript?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Advanced Topics&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the event loop in JavaScript?&lt;/li&gt;
&lt;li&gt;Explain the concept of &lt;strong&gt;Promises&lt;/strong&gt; in JavaScript.&lt;/li&gt;
&lt;li&gt;What are async/await, and how do they work?&lt;/li&gt;
&lt;li&gt;Explain &lt;strong&gt;callback functions&lt;/strong&gt; with an example.&lt;/li&gt;
&lt;li&gt;What is the difference between shallow and deep copy in JavaScript?&lt;/li&gt;
&lt;li&gt;Explain the concept of &lt;code&gt;this&lt;/code&gt; in JavaScript.&lt;/li&gt;
&lt;li&gt;What are JavaScript Prototypes, and how do they work?&lt;/li&gt;
&lt;li&gt;Explain the difference between &lt;code&gt;call()&lt;/code&gt;, &lt;code&gt;apply()&lt;/code&gt;, and &lt;code&gt;bind()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;What is debouncing and throttling? Provide examples.&lt;/li&gt;
&lt;li&gt;What is the difference between &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;forEach()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;DOM &amp;amp; BOM&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;How do you select elements using JavaScript (e.g., &lt;code&gt;querySelector&lt;/code&gt; vs. &lt;code&gt;getElementById&lt;/code&gt;)?&lt;/li&gt;
&lt;li&gt;What is &lt;strong&gt;event delegation&lt;/strong&gt;, and why is it useful?&lt;/li&gt;
&lt;li&gt;How does event bubbling and capturing work in JavaScript?&lt;/li&gt;
&lt;li&gt;Explain localStorage, sessionStorage, and cookies.&lt;/li&gt;
&lt;li&gt;How do you prevent the default behavior of an event in JavaScript?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;ES6+ Features &amp;amp; Best Practices&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What are JavaScript modules, and how do you use &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;What is destructuring in JavaScript, and how is it used?&lt;/li&gt;
&lt;li&gt;What are rest and spread operators in JavaScript?&lt;/li&gt;
&lt;li&gt;What is optional chaining (&lt;code&gt;?.&lt;/code&gt;) in JavaScript?&lt;/li&gt;
&lt;li&gt;Explain the difference between &lt;strong&gt;deep equality&lt;/strong&gt; and &lt;strong&gt;shallow equality&lt;/strong&gt; in JavaScript.&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Core Java Interview Questions</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Tue, 17 Dec 2024 15:57:56 +0000</pubDate>
      <link>https://dev.to/vivek1030/java-interview-questions-1393</link>
      <guid>https://dev.to/vivek1030/java-interview-questions-1393</guid>
      <description>&lt;p&gt;Ultimate Guide to Java Interview Questions&lt;/p&gt;

&lt;p&gt;If you're preparing for a Java interview, mastering these questions will give you a strong foundation. This post covers all critical Java topics, from Core Java concepts to Advanced topics, including coding challenges. Let's dive in!&lt;/p&gt;

&lt;p&gt;Here’s a detailed explanation of the requested topics:&lt;/p&gt;




&lt;h3&gt;
  
  
  Core Java Basics
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Key Features of Java:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Platform Independent:&lt;/strong&gt; Java code runs on any platform using the JVM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object-Oriented:&lt;/strong&gt; Encourages encapsulation, inheritance, and polymorphism.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simple and Easy to Learn:&lt;/strong&gt; Syntax similar to C++ but without complexity like pointers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secure:&lt;/strong&gt; Provides runtime checking, bytecode verification, and a security manager.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Robust:&lt;/strong&gt; Exception handling and garbage collection help avoid errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multithreaded:&lt;/strong&gt; Supports concurrent programming with built-in thread management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High Performance:&lt;/strong&gt; Uses Just-In-Time (JIT) compiler.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributed and Networked:&lt;/strong&gt; Simplifies distributed system development using APIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic and Extensible:&lt;/strong&gt; Adapts to evolving requirements through dynamic linking.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Difference Between JDK, JRE, and JVM:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;JDK (Java Development Kit):&lt;/strong&gt; Tools for developing and debugging Java programs, including JRE and compilers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JRE (Java Runtime Environment):&lt;/strong&gt; Executes Java applications; includes JVM and libraries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JVM (Java Virtual Machine):&lt;/strong&gt; Runs Java bytecode; ensures platform independence.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Difference Between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;.equals()&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;==&lt;/code&gt;:&lt;/strong&gt; Compares references (memory locations) for objects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.equals()&lt;/code&gt;:&lt;/strong&gt; Compares content or state of objects. Can be overridden.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Class and Object in Java:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Class:&lt;/strong&gt; Blueprint defining the properties (fields) and behaviors (methods).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object:&lt;/strong&gt; Instance of a class, representing a real-world entity.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;&lt;code&gt;public static void main(String[] args)&lt;/code&gt; Explained:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;public&lt;/code&gt;:&lt;/strong&gt; Accessible from anywhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;static&lt;/code&gt;:&lt;/strong&gt; No need to instantiate the class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;void&lt;/code&gt;:&lt;/strong&gt; No return value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;main&lt;/code&gt;:&lt;/strong&gt; Entry point of the program.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;String[] args&lt;/code&gt;:&lt;/strong&gt; Command-line arguments.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Difference Between &lt;code&gt;String&lt;/code&gt;, &lt;code&gt;StringBuilder&lt;/code&gt;, and &lt;code&gt;StringBuffer&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;String&lt;/code&gt;:&lt;/strong&gt; Immutable; thread-safe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;StringBuilder&lt;/code&gt;:&lt;/strong&gt; Mutable; not thread-safe but faster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;StringBuffer&lt;/code&gt;:&lt;/strong&gt; Mutable; thread-safe with synchronized methods.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Access Modifiers:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Private:&lt;/strong&gt; Visible within the class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default:&lt;/strong&gt; Visible within the package.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protected:&lt;/strong&gt; Visible within the package and subclasses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public:&lt;/strong&gt; Visible everywhere.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Difference Between &lt;code&gt;final&lt;/code&gt;, &lt;code&gt;finally&lt;/code&gt;, and &lt;code&gt;finalize&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;final&lt;/code&gt;:&lt;/strong&gt; Used to declare constants, prevent inheritance, or override.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;finally&lt;/code&gt;:&lt;/strong&gt; Block to ensure cleanup after a &lt;code&gt;try&lt;/code&gt; block.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;finalize()&lt;/code&gt;:&lt;/strong&gt; Method invoked by the garbage collector before destroying an object.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Object-Oriented Programming (OOP)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Four Pillars of OOP:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulation:&lt;/strong&gt; Restricts access to internal details.
Example: Private fields with public getters/setters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abstraction:&lt;/strong&gt; Hides complexity using interfaces or abstract classes.
Example: &lt;code&gt;List&lt;/code&gt; interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inheritance:&lt;/strong&gt; Reuse code by extending parent classes.
Example: &lt;code&gt;class Dog extends Animal&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Polymorphism:&lt;/strong&gt; Behavior changes based on the object.
Example: Method overriding.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Difference Between Abstraction and Encapsulation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Abstraction:&lt;/strong&gt; Focuses on "what" an object does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulation:&lt;/strong&gt; Focuses on "how" the data is protected.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Method Overloading vs. Overriding:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overloading:&lt;/strong&gt; Same method name, different parameters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Overriding:&lt;/strong&gt; Subclass modifies a parent class method.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Interface vs. Abstract Class:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Interface:&lt;/strong&gt; 100% abstraction; methods are implicitly abstract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abstract Class:&lt;/strong&gt; Can have abstract and concrete methods.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Multiple Interfaces:&lt;/strong&gt; A class can implement multiple interfaces using the &lt;code&gt;implements&lt;/code&gt; keyword.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Constructor Overloading Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Example&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;Example&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;Example&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;&lt;code&gt;super&lt;/code&gt; and &lt;code&gt;this&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;this&lt;/code&gt;:&lt;/strong&gt; Refers to the current object.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;super&lt;/code&gt;:&lt;/strong&gt; Refers to the parent class object.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Collections and Data Structures
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ArrayList vs. LinkedList:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ArrayList:&lt;/strong&gt; Faster for random access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LinkedList:&lt;/strong&gt; Faster for insertions/deletions.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;HashMap, LinkedHashMap, TreeMap:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HashMap:&lt;/strong&gt; Unordered, fastest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LinkedHashMap:&lt;/strong&gt; Maintains insertion order.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TreeMap:&lt;/strong&gt; Sorted order.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Significance of &lt;code&gt;hashCode()&lt;/code&gt; and &lt;code&gt;equals()&lt;/code&gt; in HashMap:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensures proper key-value mapping by preventing duplicates.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Iterator vs. ListIterator:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Iterator:&lt;/strong&gt; Traverses in one direction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ListIterator:&lt;/strong&gt; Traverses in both directions.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Fail-Fast vs. Fail-Safe:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fail-Fast:&lt;/strong&gt; Concurrent modification triggers &lt;code&gt;ConcurrentModificationException&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail-Safe:&lt;/strong&gt; Works on a copy, no exception.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Internal Working of HashMap:&lt;/strong&gt; Uses buckets for storage, hashing for key-value mapping, and linked lists to resolve collisions.&lt;/p&gt;




&lt;h3&gt;
  
  
  Multithreading and Concurrency
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Creating Threads in Java:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Extending &lt;code&gt;Thread&lt;/code&gt;:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyThread&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Implementing &lt;code&gt;Runnable&lt;/code&gt;:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyRunnable&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;&lt;code&gt;synchronized&lt;/code&gt; Method vs. Block:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Method:&lt;/strong&gt; Locks entire method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block:&lt;/strong&gt; Locks a specific section.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;&lt;code&gt;wait()&lt;/code&gt;, &lt;code&gt;notify()&lt;/code&gt;, &lt;code&gt;notifyAll()&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used for inter-thread communication.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Volatile Keyword:&lt;/strong&gt; Ensures visibility of changes across threads.&lt;/p&gt;




&lt;h3&gt;
  
  
  Exception Handling
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Checked vs. Unchecked Exceptions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Checked:&lt;/strong&gt; Caught during compile-time (&lt;code&gt;IOException&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unchecked:&lt;/strong&gt; Occurs during runtime (&lt;code&gt;ArithmeticException&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Custom Exception Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyException&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;MyException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Java 8+ Features
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Lambda Expression:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;mapToInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Integer:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;intValue&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;sum&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Need a deeper dive into specific areas? Let me know!&lt;br&gt;
&lt;strong&gt;Common Coding Questions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write a program to check if a string is a palindrome.&lt;/li&gt;
&lt;li&gt;Write a program to find the second-largest element in an array.&lt;/li&gt;
&lt;li&gt;Write a program to reverse a linked list.&lt;/li&gt;
&lt;li&gt;Write a program to implement a thread-safe Singleton class.&lt;/li&gt;
&lt;li&gt;Write a program to find the frequency of characters in a string.&lt;/li&gt;
&lt;li&gt;Write a program to demonstrate deadlock and resolve it.&lt;/li&gt;
&lt;li&gt;Write a program to check if two strings are anagrams.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Mastering Competitive Coding: String</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Sat, 11 May 2024 18:55:51 +0000</pubDate>
      <link>https://dev.to/vivek1030/mastering-competitive-coding-string-4nic</link>
      <guid>https://dev.to/vivek1030/mastering-competitive-coding-string-4nic</guid>
      <description>&lt;p&gt;&lt;strong&gt;Easy level questions&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Word Break&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: s = "leetcode", wordDict = ["leet", "code"]&lt;/li&gt;
&lt;li&gt;Output: True&lt;/li&gt;
&lt;li&gt;Explanation: "leetcode" can be segmented into "leet" and "code".&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Longest Palindromic Substring&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: s = "babad"&lt;/li&gt;
&lt;li&gt;Output: "bab" or "aba"&lt;/li&gt;
&lt;li&gt;Explanation: Both "bab" and "aba" are valid longest palindromic substrings.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Regular Expression Matching&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: s = "aa", p = "a*"&lt;/li&gt;
&lt;li&gt;Output: True&lt;/li&gt;
&lt;li&gt;Explanation: Pattern "a*" matches zero or more occurrences of 'a'.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Letter Combinations of a Phone Number&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: digits = "23"&lt;/li&gt;
&lt;li&gt;Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]&lt;/li&gt;
&lt;li&gt;Explanation: Corresponding letters for digits 2 and 3 are "abc" and "def" respectively.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Valid Palindrome II&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: s = "abca"&lt;/li&gt;
&lt;li&gt;Output: True&lt;/li&gt;
&lt;li&gt;Explanation: By deleting 'b', the resulting string "aca" is a palindrome.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Group Anagrams&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: strs = ["eat", "tea", "tan", "ate", "nat", "bat"]&lt;/li&gt;
&lt;li&gt;Output: [["bat"], ["nat","tan"], ["ate","eat","tea"]]&lt;/li&gt;
&lt;li&gt;Explanation: Anagrams are grouped together.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Minimum Window Substring&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: s = "ADOBECODEBANC", t = "ABC"&lt;/li&gt;
&lt;li&gt;Output: "BANC"&lt;/li&gt;
&lt;li&gt;Explanation: The minimum window substring containing all characters from t is "BANC".&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Decode String&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: s = "3[a]2[bc]"&lt;/li&gt;
&lt;li&gt;Output: "aaabcbc"&lt;/li&gt;
&lt;li&gt;Explanation: Decode the string by repeating substrings inside brackets.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Permutations&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [1,2,3]&lt;/li&gt;
&lt;li&gt;Output: [[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]&lt;/li&gt;
&lt;li&gt;Explanation: All possible permutations of the input list.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add Binary&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: a = "11", b = "1"&lt;/li&gt;
&lt;li&gt;Output: "100"&lt;/li&gt;
&lt;li&gt;Explanation: Binary addition of "11" and "1" results in "100".&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Mastering Competitive Coding: Array</title>
      <dc:creator>Vivek Nishant</dc:creator>
      <pubDate>Sat, 11 May 2024 18:27:27 +0000</pubDate>
      <link>https://dev.to/vivek1030/mastering-competitive-coding-array-4cdm</link>
      <guid>https://dev.to/vivek1030/mastering-competitive-coding-array-4cdm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Easy level Questions :&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Array Easy level Questions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Rotate Array
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [1, 2, 3, 4, 5], k = 2&lt;/li&gt;
&lt;li&gt;Output: [4, 5, 1, 2, 3]&lt;/li&gt;
&lt;li&gt;Explanation: Rotating the array [1, 2, 3, 4, 5] by 2 steps to the right results in [4, 5, 1, 2, 3].&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Two Sum
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [2, 7, 11, 15], target = 9&lt;/li&gt;
&lt;li&gt;Output: [0, 1]&lt;/li&gt;
&lt;li&gt;Explanation: The elements at indices 0 and 1 (2 and 7) sum up to the target value 9.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Merge Intervals
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]&lt;/li&gt;
&lt;li&gt;Output: [[1, 6], [8, 10], [15, 18]]&lt;/li&gt;
&lt;li&gt;Explanation: Merging overlapping intervals results in [[1, 6], [8, 10], [15, 18]].&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Product of Array Except Self
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [1, 2, 3, 4]&lt;/li&gt;
&lt;li&gt;Output: [24, 12, 8, 6]&lt;/li&gt;
&lt;li&gt;Explanation: The product of all elements except self at index i is calculated for each index i.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5. Container With Most Water
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: height = [1, 8, 6, 2, 5, 4, 8, 3, 7]&lt;/li&gt;
&lt;li&gt;Output: 49&lt;/li&gt;
&lt;li&gt;Explanation: The maximum amount of water that can be trapped is between the bars at indices 1 and 8.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  6. Maximum Subarray
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]&lt;/li&gt;
&lt;li&gt;Output: 6&lt;/li&gt;
&lt;li&gt;Explanation: The contiguous subarray with the largest sum is [4, -1, 2, 1], which sums up to 6.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  7. Next Permutation
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [1, 2, 3]&lt;/li&gt;
&lt;li&gt;Output: [1, 3, 2]&lt;/li&gt;
&lt;li&gt;Explanation: The next lexicographically greater permutation of [1, 2, 3] is [1, 3, 2].&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  8. Search in Rotated Sorted Array
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [4, 5, 6, 7, 0, 1, 2], target = 0&lt;/li&gt;
&lt;li&gt;Output: 4&lt;/li&gt;
&lt;li&gt;Explanation: The target value 0 is found at index 4 after rotation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  9. Kth Largest Element in an Array
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: nums = [3, 2, 1, 5, 6, 4], k = 2&lt;/li&gt;
&lt;li&gt;Output: 5&lt;/li&gt;
&lt;li&gt;Explanation: The second largest element in the array is 5.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  10. Spiral Matrix
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]&lt;/li&gt;
&lt;li&gt;Output: [1, 2, 3, 6, 9, 8, 7, 4, 5]&lt;/li&gt;
&lt;li&gt;Explanation: Traversing the matrix in a spiral order results in the given output.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  11. Sliding Window Maximum
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: nums = [1,3,-1,-3,5,3,6,7], k = 3&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: [3,3,5,5,6,7]&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: The maximum value in each subarray of size 3 is [3,3,5,5,6,7].&lt;/p&gt;

&lt;h4&gt;
  
  
  12. Longest Substring Without Repeating Characters
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: s = "abcabcbb"&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: 3&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: The longest substring without repeating characters is "abc", which has a length of 3.&lt;/p&gt;

&lt;h4&gt;
  
  
  13. Three Sum
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: nums = [-1,0,1,2,-1,-4]&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: [[-1,-1,2],[-1,0,1]]&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: The unique triplets that sum up to zero are [-1,-1,2] and [-1,0,1].&lt;/p&gt;

&lt;h4&gt;
  
  
  14. Meeting Rooms II
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: intervals = [[0, 30],[5, 10],[15, 20]]&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: 2&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: Minimum two conference rooms are required: one for [0, 30] and another for [5, 10], [15, 20].&lt;/p&gt;

&lt;h4&gt;
  
  
  15. Valid Parentheses
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: s = "()[]{}"&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: true&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: The input string is valid as all parentheses are closed in the correct order.&lt;/p&gt;

&lt;h4&gt;
  
  
  16. Move Zeroes
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: nums = [0,1,0,3,12]&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: [1,3,12,0,0]&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: All zeroes are moved to the end of the array while maintaining the relative order of non-zero elements.&lt;/p&gt;

&lt;h4&gt;
  
  
  17. Majority Element
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: nums = [2,2,1,1,1,2,2]&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: 2&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: The majority element that appears more than ⌊ n/2 ⌋ times is 2.&lt;/p&gt;

&lt;h4&gt;
  
  
  18. Reverse Words in a String
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: s = "the sky is blue"&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: "blue is sky the"&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: The words in the string are reversed.&lt;/p&gt;

&lt;h4&gt;
  
  
  19. Trapping Rain Water
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: height = [0,1,0,2,1,0,1,3,2,1,2,1]&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: 6&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: The total trapped rainwater between the bars is 6 units.&lt;/p&gt;

&lt;h4&gt;
  
  
  20. Remove Duplicates from Sorted Array
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;: nums = [0,0,1,1,1,2,2,3,3,4]&lt;br&gt;
   &lt;strong&gt;Output&lt;/strong&gt;: 5&lt;br&gt;
   &lt;strong&gt;Explanation&lt;/strong&gt;: After removing duplicates, the new length of the array is 5, and the first five elements are [0,1,2,3,4].&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
