Skip to main content

Posts

Showing posts from September, 2024

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