Skip to main content

Posts

java Interview Goal

Recent posts

How to parse JSON with date field in Java - Jackson @JsonDeserialize Annotation Example

How to Parse JSON with Date Field in Java - Jackson `@JsonDeserialize` Annotation Example Parsing JSON in Java is a common task, but dealing with date fields requires a little extra attention. JSON treats everything as a string, but Java has strong typing, meaning dates need to be handled differently. In this post, we will see how to parse a JSON with a date field using Jackson, focusing on the `@JsonDeserialize` annotation. Example Scenario Let’s assume we have a simple JSON that includes a date field: ``` {   "name": "John Doe",   "birthDate": "2024-09-05" } ``` In Java, we might want to map this to a class with a `LocalDate` for `birthDate`. This is where Jackson's `@JsonDeserialize` annotation comes into play. Step-by-Step Example Step 1: Add Jackson Dependency First, make sure you have the Jackson dependency in your `pom.xml` if you’re using Maven: ``` <dependency>     <groupId>com.fasterxml.jackson.core</groupId>     &

Dealing with Passwords in Java Applications: 5 Best Practices You Should Follow

 In modern Java applications—whether core Java applications or enterprise-level web applications—working with passwords is inevitable. Passwords are sensitive pieces of information, just like Social Security Numbers (SSNs), and if you’re handling real human data in systems such as online banking or healthcare portals, it’s critical to implement best practices for dealing with passwords securely. Below, I’ll share five essential best practices that I’ve learned and recommend for managing passwords, particularly when you are handling authentication and authorization. While these tips are a good starting point, be sure to tailor them to your application’s requirements and security policies. 1) Use SSL/TLS to Transfer Username and Password When users send passwords over the network, it is crucial to use SSL/TLS to encrypt the communication. This ensures that sensitive information is protected from eavesdroppers. Tools like LDAP and Active Directory are commonly used for storing usernames

How to Create Immutable Class and Object in Java

How to create Immutable Class and Object in Java - Tutorial Example Writing or creating immutable classes in Java is becoming popular day by day, because of the concurrency and multithreading advantages provided by immutable objects. Immutable objects offer several benefits over a conventional mutable object, especially while creating concurrent Java applications. An immutable object not only guarantees the safe publication of an object’s state but also can be shared among other threads without any external synchronization. In fact, JDK itself contains several immutable classes like String , Integer , and other wrapper classes. For those who don’t know, immutable objects are those whose state cannot be changed once created. A good example is java.lang.String — once created, a String object cannot be modified. Any operation that seems to modify a String object (like trim() , toUpperCase() , etc.) actually results in a new object. What is an Immutable Class in Java? An immutabl

TCS interview questions that candidates have encountered in 2024

  Technical Questions Java: Explain the difference between HashMap and Hashtable . How does Java handle memory management, and what is garbage collection? What are the features introduced in Java 17? Explain method overloading and method overriding with examples. What is the purpose of the final , finally , and finalize keywords in Java? Data Structures and Algorithms: How do you find the middle element of a linked list in a single pass? Explain different sorting algorithms and their time complexities. How would you implement a stack using queues? Discuss the difference between depth-first search (DFS) and breadth-first search (BFS). What are the advantages of using a binary search tree over a simple array? Database Management: What is normalization, and why is it important in databases? Explain the difference between JOIN , LEFT JOIN , and RIGHT JOIN . How would you optimize a slow-running query? What are indexes, and how do they improve query performance? Explain ACID properties in

The Future of Java Developers in the Age of AI and ChatGPT

  In today's rapidly evolving tech landscape, AI tools like ChatGPT are becoming more integrated into the software development process. As a Java developer, whether you're just starting out or have years of experience, you might wonder: How can I stay relevant and succeed in the age of AI? In this post, we'll explore practical strategies to ensure you not only survive but thrive as a Java developer in this AI-driven world. 1. Embrace AI as a Tool, Not a Threat AI isn't here to replace you—it's here to help you. Tools like ChatGPT can automate repetitive tasks, assist with coding challenges, and even generate code snippets, allowing you to focus on more complex and creative aspects of development. For Freshers: Use AI tools to learn and understand Java more quickly. Let them assist you in writing code, but make sure you're also learning the logic and concepts behind it. For Experienced Developers: Integrate AI tools into your workflow to enhance productivity. L

Clean Architecture with Spring Boot: A Good Idea?

Clean Architecture with Spring Boot: In the world of software development, architecture plays a crucial role in determining the maintainability, scalability, and testability of an application. One architecture style that has gained popularity is Clean Architecture . But what exactly is Clean Architecture, and is it a good idea to use it with Spring Boot? Let’s dive in! What is Clean Architecture? Clean Architecture is a software design philosophy introduced by Robert C. Martin, also known as "Uncle Bob." The main idea behind Clean Architecture is to separate the concerns of your application into distinct layers, making your codebase more modular, easier to maintain, and less dependent on external frameworks. The Layers of Clean Architecture Clean Architecture is typically divided into the following layers: 1. Entities : The core business logic of your application. This layer is independent of any external system or framework. It contains the business rules that are critical t

Mastering Java Streams: Best Practices and Common Pitfalls

  Introduction Java Streams, introduced in Java 8, have revolutionized the way developers handle collections and data processing in Java. However, mastering Streams requires understanding not just the syntax but also the best practices and common pitfalls that can arise. In this post, we'll explore advanced tips for working with Java Streams, helping you write more efficient, readable, and maintainable code. Table of Contents Introduction to Java Streams Best Practices for Using Streams Leverage Parallel Streams Wisely Avoid State Mutations in Stream Operations Use Method References for Cleaner Code Short-Circuiting Operations for Efficiency Common Pitfalls in Java Streams Overusing Parallel Streams Modifying Collections During Stream Operations Ignoring Lazy Evaluation Improper Use of Optional with Streams Advanced Stream Operations Grouping and Partitioning Collectors and Custom Collectors FlatMap for Complex Mappings Conclusion 1. Introduction to Java Streams Java Streams provid