Saravanan's Corner: Blackberry Dev

Saturday, 9 August 2025

Thread - tricky questions

 // Online Java Compiler

// Use this editor to write, compile and run your Java code online

import java.util.concurrent.*;


class Main {

    

    public static void main(String[] args) {

        

        CountDownLatch count = new CountDownLatch(3);

        

        new Thread(()->{

            System.out.println("Hi there...1");

            try{

               Thread.sleep(1000);

               count.countDown();

            } catch(InterruptedException e){

                

            }

            System.out.println("Complete...1");

        }).start();

        

        new Thread(()->{

            System.out.println("Hi there...2");

            try{

               Thread.sleep(1000);

               count.countDown();

            } catch(InterruptedException e){

                

            }

            System.out.println("Complete...2");

        }).start();

        

        new Thread(()->{

            System.out.println("Hi there...3");

            try{

               Thread.sleep(1000);

               count.await();

            } catch(InterruptedException e){

                

            }

            System.out.println("Complete...3");

        }).start();

        

        new Thread(()->{

            System.out.println("Hi there...4");

            try{

               Thread.sleep(1000);

               count.countDown();

            } catch(InterruptedException e){}

            System.out.println("Complete...4");

        }).start();

        

         System.out.println("........Using Completable future...");

         

         CompletableFuture<Void> task1 = CompletableFuture.runAsync(

         ()-> {

             System.out.println("task1 CompletableFuture started");

             try{

               Thread.sleep(1000);

               count.countDown();

            } catch(InterruptedException e){}

            System.out.println("CompletableFuture Complete...1");

         }

         

         );

             

        CompletableFuture<Void> task2 = CompletableFuture.runAsync(

         ()-> {

             System.out.println("task2 CompletableFuture started");

             try{

               Thread.sleep(1000);

               count.countDown();

            } catch(InterruptedException e){}

            System.out.println("CompletableFuture Complete...2");

         }

         );

        CompletableFuture<Void> task4 = CompletableFuture.runAsync(

         ()-> {

             System.out.println("task4 CompletableFuture started");

             try{

               Thread.sleep(1000);

               count.countDown();

            } catch(InterruptedException e){}

            System.out.println("CompletableFuture Complete...4");

         });

        CompletableFuture<Void> task3 = CompletableFuture.allOf(task1, task2, task4).thenRun(

             ()-> {

                 System.out.println("task3 CompletableFuture started");

                  try{

               Thread.sleep(1000);

               count.countDown();

            } catch(InterruptedException e){}

            System.out.println("CompletableFuture Complete...3");

                 

             }

        );

    }

}

Friday, 1 August 2025

The Spring Security JWT token authentication flow

 The Spring Security JWT token authentication flow involves several steps, typically illustrated through two main phases: Login/Token Generation and Resource Access/Token Validation.

1. Login/Token Generation Flow:
Client Sends Credentials:
The client (e.g., web browser, mobile app) sends user credentials (username and password) to the Spring Boot application's authentication endpoint.
Authentication Controller:
The application's authentication controller receives these credentials.
AuthenticationManager:
The controller delegates the authentication process to the AuthenticationManager.
AuthenticationProvider:
The AuthenticationManager uses an AuthenticationProvider (often integrated with UserDetailsService) to validate the credentials against a user store (e.g., database).
Successful Authentication:
If credentials are valid, the AuthenticationProvider returns an Authentication object.
JWT Generation:
A JWT utility class or service generates a new JWT containing user details (claims) and signs it using a secret key.
Token Sent to Client:
The generated JWT is returned to the client in the authentication response.
2. Resource Access/Token Validation Flow:
Client Sends JWT:
For subsequent requests to protected resources, the client includes the obtained JWT, typically in the Authorization header as a "Bearer" token.
Spring Security Filter Chain:
The request enters the Spring Security filter chain.
JwtAuthenticationFilter:
A custom JwtAuthenticationFilter (or similar filter) intercepts the request early in the chain.
Token Extraction and Validation:
This filter extracts the JWT from the header and validates it using the secret key (e.g., signature verification, expiration check, claim validation).
User Details Loading:
If the token is valid, the filter extracts user details (e.g., username) from the token's claims and loads the full UserDetails object, often via a UserDetailsService.
SecurityContextHolder:
An Authentication object is created with the loaded UserDetails and set in the SecurityContextHolder, making the user authenticated for the current request.
Authorization:
Subsequent filters or controllers in the chain can then perform authorization checks based on the authenticated user's roles or authorities.
Access Protected Resource:
If authorization is successful, the request proceeds to the intended protected resource.
Token Invalid/Missing:
If the token is invalid, missing, or expired, the JwtAuthenticationFilter or a subsequent filter will reject the request, typically returning an unauthorized (401) or forbidden (403) status.

Monday, 28 July 2025

Top 3 tricky Interview questions

 2025: In this Code Decode video, we break down the top 3 tricky senior developer interview questions and their answers.


Udemy Course Discounted coupon code

https://www.udemy.com/...



Interview questions 


✅ What is a Cold Start in Spring Boot?

Understand why your app’s startup time can cause autoscaling failures, serverless timeouts, and production delays — and learn how to fix it.


✅ Real Cold Start Optimization Techniques:


Use of /actuator/startup to find bottlenecks


Enable lazy initialization


Exclude unused auto-configurations


Tweak DB and Liquibase setup


Use Spring AOT + GraalVM Native Image to reduce startup to lest than 1 second


✅ REST vs gRPC vs Event-Driven: What’s Best in 2025?

We explain:


When to use REST for simplicity


When to choose gRPC for speed


Why event-driven architecture is the backbone of scalable, decoupled systems


Real-world hybrid strategies that work in production


✅ Handling Breaking API Changes in Microservices

Learn how to implement:


API versioning


Separate DTOs for v1/v2


Feature toggles


Contract testing (Spring Cloud Contract)


Safe rollout and deprecation strategies


✅ Dealing with Large File Uploads in Spring Boot


Avoid memory bloat with streaming


Secure your uploads with size limits, antivirus, and safe naming


Scale to 100MB+ using pre-signed URLs (e.g., S3)


Offload heavy processing to background queues (Kafka, RabbitMQ)


🚨 Plus:

We cover the top 10 real production issues in Spring Boot microservices — from memory leaks, thread pool exhaustion, and cascading failures to logging, observability, and retry nightmares — with proactive fixes you can apply today.


Mock Interview Playlist:

    • Mock Interviews (Face ...  


Most Asked Core Java Interview Questions and Answers:     • Core Java frequently a...  


Advance Java Interview Questions and Answers:     • Advance Java Interview...  


Java 8 Interview Questions and Answers:

     • Java 8 Interview Quest...  


Hibernate Interview Questions and Answers:

    • Hibernate Interview Qu...  


Spring Boot Interview Questions and Answers: 

    • Advance Java Interview...  


Angular Playlist: 

     • Angular Course Introdu...  

SQL Playlist:     • SQL Interview Question...  


GIT:     • GIT  


Subscriber and Follow Code Decode

Subscriber Code Decode: https://www.youtube.co...

LinkedIn :    / codedecodeyoutube   

Instagram:    / codedecode25  


#seniordev #codedecode #interviewquestions

Saturday, 19 July 2025

Java Interview - Kumaran

  1.  Core Java 8 and above 
  2.  JDK/JVM/JRE, 
  3. JVM Memory Meta Space, 
  4. Collection Framework – 
  5. Immutability, 
  6. Exception Handling - 
  7. Custom Exceptions, 
  8. Multithreading concepts - 
  9. Executor Frameworks, 
  10. Thread racing conditions, 
  11. Design Patterns, 
  12. synchronization, 
  13. object locks,
  14.  Concurrency Collections ( fail-fast - Fail Safe ), 
  15. Stream API, Lambda, Functional Interface, Coding Skill in Streams, 
  16. Date Time API 
  17. SOLID Principles,
  18. Candidate must have exposure to HTML, CSS, and JSP is an advantage and not a must.
  19. JDBC,
  20. Spring MVC, 
  21. Spring Boot (Version 2.7 or more is a MUST),
  22. JPA/Hibernate, 
  23. Restful Micro Services 
  24. Spring framework Fundamentals - 
  25. Dispatcher Servlet, 
  26. Spring Beans - Lifecycle, 
  27. Bean's Scope 
  28. Spring Configuration, 
  29. Spring JDBC, 
  30. ACID, 
  31. Spring ORM integration
  32. Spring AOP
  33. Logging Mechanism
  34. Exception Handling, 
  35. Spring Security
  36. Thread Local, 
  37. Transactions, 
  38. Spring Annotations, 
  39. Auto Configuration,
  40. Basic BOOT internals, 
  41. Spring Cloud – projects,
  42. JWT – Oath, 
  43. API Gateway, 
  44. Eureka Discovery Service, 
  45. Config Server, 
  46. Circuit Breakers, 
  47. Actuator, 
  48. Dev Tools, 
  49. Spring DATA JPA,
  50. Transaction Propagation,
  51. Pagination And Sorting, 
  52. Annotations,
  53. Exception Handling, 
  54. Rest Template, 
  55. Web Client, 
  56. Feign Client, 
  57. Load Balancing, 
  58. Response Error Handler, 
  59. Conditional Bean Creation, 
  60. Micro Service Communication: 
  61. Rest Template, 
  62. Web Client, 
  63. Kafka Streaming, 
  64. PUB/SUB
  65. Hibernate -
  66. Persistence Context, 
  67. Hibernate Core, 
  68. Second Level Cache Configuration, 
  69. Session Factory/Session, 
  70. Update vs Merge, 
  71. Get vs Load, 
  72. N+1 Problem, 
  73. Fetch Type - EAGER, LAZY
  74. @GeneratedValue – Strategy, 
  75. Connection Pool, 
  76. Composite Primary Key - 
  77. Embed, 
  78. Embeddable Concepts,
  79. One to many, 
  80. one to one 
  81. database: Oracle / SQL / PostgreSQL.
  82. Oops Concept – Multithreading and annotation are a Must.
  83. The candidate should be comfortable working in Git, and GitHub.Should be experienced in Maven/Gradle Build – Added Advantage.
  84. SQL - Data modelling,
  85. Aggregation, 
  86. Indexing, 
  87. Projection,
  88. Replication, 
  89. Query / Optimisation, 
  90. File systems
  91. Tomcat/WebLogic or any server exposure - 
  92. Tomcat configuration, 
  93. Application server – JBoss / WebLogic, 
  94. Bridge, 
  95. Queue, 
  96. connection pool configuration, 
  97. Load Balancing
  98. Build Process - Ant, Maven build process, CI/CD pipeline
  99. Unit Testing: JUnit/XUnit/NUnit – Added Advantage.
  100. SDLC - JIRA - Must have worked in Jira / Similar Agile tools and should be familiar with Epic, Story creation, grooming, task / sub-task creation, GIT Repository /  DevOps tools
  101. Methodologies: Agile/Waterfall
  102. Tech Design Skills - Analysis, Design and Documentation of HLD and supporting SRD, estimation techniques, etc
  103. DevOps Tools: Jenkins, CI/CD, Docker, Kubernetes- Added Advantage
  104. Familiarity with cloud platforms (AWS / Azure / GCP) – Added advantage, not a must.
  105. LLD Preparation, HLD Preparation and Sequence Diagram,
  106. Methodology in SDLC
  107. Understanding of front-end technologies like HTML/CSS/Bootstrap/ Angular/React (basic level)
  108. Deep understanding of Agile/Scrum, Kanban, and hybrid methodologies
  109. Experience in BFSI, or Finance domain – added advantage and not a must.p ll
  110. Experience with JIRA, Confluence, MS Project, or equivalent project management tools – Added Advantage and not a must.
  111. Experience with successful team handling experience delivering web-based software solutions
  112. SQL -Data modelling,  Aggregation, Indexing, Projection, Replication, Query / Optimisation, File systems, Joins, Index, Stored Procedures.

 andidate must have exposure to HTML, CSS, and JSP is an advantage and not a must.


Should have hands-on experience in JDBC, Spring MVC, Spring Boot (Version 2.7 or more is a MUST), JPA/Hibernate, and Restful Micro Services - Spring framework Fundamentals - Dispatcher Servlet, Spring Beans - Lifecycle, Bean's Scope Spring Configuration, Spring JDBC, ACID, Spring ORM integration, Spring AOP - Logging Mechanism- Exception Handling, Spring Security - Thread Local, Transactions, Spring Annotations, Auto Configuration, Basic BOOT internals, Spring Cloud – projects, JWT – Oath, API Gateway, Eureka Discovery Service, Config Server, Circuit Breakers, Actuator, Dev Tools, Spring DATA JPA, Transaction Propagation, Pagination And Sorting, Annotations, Exception Handling, Rest Template, Web Client, Feign Client, Load Balancing, Response Error Handler, Conditional Bean Creation, Micro Service Communication: Rest Template, Web Client, Kafka Streaming, PUB/SUB


Hibernate - Persistence Context, Hibernate Core, Second Level Cache Configuration, Session Factory/Session, Update vs Merge, Get vs Load, N+1 Problem, Fetch Type - EAGER, LAZY, @GeneratedValue – Strategy, Connection Pool, Composite Primary Key - Embed, Embeddable Concepts, One to many, one to one database: Oracle / SQL / PostgreSQL.


Oops Concept – Multithreading and annotation are a Must.


The candidate should be comfortable working in Git, and GitHub.Should be experienced in Maven/Gradle Build – Added Advantage. SQL - Data modelling,  Aggregation, Indexing, Projection, Replication, Query / Optimisation, File systems


Tomcat/WebLogic or any server exposure - Tomcat configuration, Application server – JBoss / WebLogic, Bridge, Queue, connection pool configuration, Load Balancing


Build Process - Ant, Maven build process, CI/CD pipeline


Unit Testing: JUnit/XUnit/NUnit – Added Advantage.


SDLC - JIRA - Must have worked in Jira / Similar Agile tools and should be familiar with Epic, Story creation, grooming, task / sub-task creation, GIT Repository /  DevOps tools


Methodologies: Agile/Waterfall


Tech Design Skills - Analysis, Design and Documentation of HLD and supporting SRD, estimation techniques, etc


DevOps Tools: Jenkins, CI/CD, Docker, Kubernetes- Added Advantage


Familiarity with cloud platforms (AWS / Azure / GCP) – Added advantage, not a must.


LLD Preparation, HLD Preparation and Sequence Diagram,


Methodology in SDLC


Understanding of front-end technologies like HTML/CSS/Bootstrap/ Angular/React (basic level)


Deep understanding of Agile/Scrum, Kanban, and hybrid methodologies


Experience in BFSI, or Finance domain – added advantage and not a must.


Experience with JIRA, Confluence, MS Project, or equivalent project management tools – Added Advantage and not a must.


Experience with successful team handling experience delivering web-based software solutions


SQL -Data modelling,  Aggregation, Indexing, Projection, Replication, Query / Optimisation, File systems, Joins, Index, Stored Procedures.


 


Brush up on all so that you can answer clearly.


All the best.


Do Well.

 andidate must have exposure to HTML, CSS, and JSP is an advantage and not a must.

Should have hands-on experience in JDBC, Spring MVC, Spring Boot (Version 2.7 or more is a MUST), JPA/Hibernate, and Restful Micro Services - Spring framework Fundamentals - Dispatcher Servlet, Spring Beans - Lifecycle, Bean's Scope Spring Configuration, Spring JDBC, ACID, Spring ORM integration, Spring AOP - Logging Mechanism- Exception Handling, Spring Security - Thread Local, Transactions, Spring Annotations, Auto Configuration, Basic BOOT internals, Spring Cloud – projects, JWT – Oath, API Gateway, Eureka Discovery Service, Config Server, Circuit Breakers, Actuator, Dev Tools, Spring DATA JPA, Transaction Propagation, Pagination And Sorting, Annotations, Exception Handling, Rest Template, Web Client, Feign Client, Load Balancing, Response Error Handler, Conditional Bean Creation, Micro Service Communication: Rest Template, Web Client, Kafka Streaming, PUB/SUB

Hibernate - Persistence Context, Hibernate Core, Second Level Cache Configuration, Session Factory/Session, Update vs Merge, Get vs Load, N+1 Problem, Fetch Type - EAGER, LAZY, @GeneratedValue – Strategy, Connection Pool, Composite Primary Key - Embed, Embeddable Concepts, One to many, one to one database: Oracle / SQL / PostgreSQL.

Oops Concept – Multithreading and annotation are a Must.

The candidate should be comfortable working in Git, and GitHub.Should be experienced in Maven/Gradle Build – Added Advantage. SQL - Data modelling,  Aggregation, Indexing, Projection, Replication, Query / Optimisation, File systems

Tomcat/WebLogic or any server exposure - Tomcat configuration, Application server – JBoss / WebLogic, Bridge, Queue, connection pool configuration, Load Balancing

Build Process - Ant, Maven build process, CI/CD pipeline

Unit Testing: JUnit/XUnit/NUnit – Added Advantage.

SDLC - JIRA - Must have worked in Jira / Similar Agile tools and should be familiar with Epic, Story creation, grooming, task / sub-task creation, GIT Repository /  DevOps tools

Methodologies: Agile/Waterfall

Tech Design Skills - Analysis, Design and Documentation of HLD and supporting SRD, estimation techniques, etc

DevOps Tools: Jenkins, CI/CD, Docker, Kubernetes- Added Advantage

Familiarity with cloud platforms (AWS / Azure / GCP) – Added advantage, not a must.

LLD Preparation, HLD Preparation and Sequence Diagram,

Methodology in SDLC

Understanding of front-end technologies like HTML/CSS/Bootstrap/ Angular/React (basic level)

Deep understanding of Agile/Scrum, Kanban, and hybrid methodologies

Experience in BFSI, or Finance domain – added advantage and not a must.

Experience with JIRA, Confluence, MS Project, or equivalent project management tools – Added Advantage and not a must.

Experience with successful team handling experience delivering web-based software solutions

SQL -Data modelling,  Aggregation, Indexing, Projection, Replication, Query / Optimisation, File systems, Joins, Index, Stored Procedures.

 

Brush up on all so that you can answer clearly.

All the best.

Do Well.

Friday, 18 July 2025

Key Microservices for a Simple Uber System:

Key Microservices for a Simple Uber System:
  1. 1. Customer Service:
    Handles customer-related functions like authentication, profile management, and ride history. 
  2. 2. Driver Service:
    Manages driver authentication, profile details, driver status (available, offline), and vehicle information. 
  3. 3. Ride Service:
    Responsible for ride matching, including finding nearby available drivers, estimating ETAs, and managing ride requests. This service might use technologies like quadtrees for efficient location-based queries. 
  4. 4. Trip Service:
    Manages the lifecycle of a ride, from initiation to completion, including fare calculation, payment processing, and ride status updates. 
Core Components and Considerations:
  • API Gateway:
    Acts as a single entry point for client applications, routing requests to the appropriate microservice. 
  • Service Discovery:
    Enables microservices to find and communicate with each other dynamically. 
  • Messaging Formats & Communication:
    Utilizing efficient messaging formats (e.g., REST, gRPC) for inter-service communication is crucial. 
  • Databases:
    Each microservice owns its dedicated database to ensure data isolation and independent scaling. 
  • Scalability & Performance:
    The microservice architecture inherently supports horizontal scaling, allowing individual services to scale based on demand. High availability and low latency are critical non-functional requirements for a ride-hailing system. 
  • Decoupling:
    Services should be loosely coupled, allowing for independent development, deployment, and updates without impacting other parts of the system.