Aishwarya Naglot

Aishwarya Naglot

Writing clean code… when the bugs aren’t looking.

About

Developer by passion, debugger by instinct. Forever building, occasionally breaking, constantly evolving.

105 Articles Published

Articles by Aishwarya Naglot

105 articles

How to delete a string inside a file(.txt) in java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 8K+ Views

In this article, we will learn how to delete a string inside a file (.txt) in Java. The following are the ways to do so: Using FileOutputStream and replaceAll() method. Using replace() method. Using FileOutputStream The FileOutputStream is a class in the java.io package. It is mainly used for writing data to a file. It creates a file output stream to write data to the specified file. To delete a string inside a file using the FileOutputStream class, follow the steps below: Create a file ...

Read More

Java program to delete all the files in a directory recursively (only files)

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 3K+ Views

To delete all the files in a directory recursively (only files), we can use the class Files, which is part of the java.nio.file package. The Files class helps in performing file operations such as creating, deleting, and copying files. Suppose we have a directory named test with the following structure: file1.txt file2.txt file3.txt subdir1 file4.txt file5.txt subdir2 ...

Read More

Redirecting System.out.println() output to a file in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 10K+ Views

In Java, the System is a class that provides access to the resources called "System resources". It is a final class, which means it cannot be inherited by any other class. It is a part of the java.lang package. The System.out.println() method prints the data on the console. In this article, we will learn how to redirect the output of the System.out.println() method to a file. Following are few of the ways through we achieve this: Using System.setOut() with PrintStream Using FileOutputStream with PrintStream The filed named out of the System class represents a standard output Stream, an ...

Read More

How can we format a date using the Jackson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 3K+ Views

Jackson is a Java-based library, and it can be useful to convert Java objects to JSON and JSON to Java objects. A Jackson API is faster than other API, needs less memory, and is good for large objects. We can format a date using the setDateFormat() of ObjectMapper class. This method can be used for configuring the default DateFormat when serializing time values as Strings and deserializing from JSON Strings. Syntax of setDateFormat() public ObjectMapper setDateFormat(DateFormat df) Here, df is the DateFormat instance to be used for formatting dates. Steps to format a date using Jackson in Java Following ...

Read More

Convert POJO to XML using the Jackson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 7K+ Views

Jackson is a library that allows you to convert Java objects into XML and vice versa. In this example, we will demonstrate how to convert a POJO (Plain Old Java Object) into XML using the Jackson library. Well, if you are not familiar with POJO, it is a simple Java object that does not follow any specific framework or design pattern. It is just a regular Java class with fields and methods. We will use the method writeValueAsString() of the XmlMapper class to convert a POJO into XML. The XmlMapper class is part of the Jackson library and it ...

Read More

How can we ignore the fields during JSON serialization in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 14K+ Views

If there are fields in Java objects that do not wish to be serialized, we can use the @JsonIgnore annotation in the Jackson library. The @JsonIgnore can be used at the field level, for ignoring fields during the serialization and deserialization. In this article, we will learn how to ignore the fields during JSON serialization in Java using the Jackson library. Steps to ignore the fields during JSON serialization in Java: In order to use Jackson, you will need to add it to your project. If you use Maven, add the following dependency to your ...

Read More

Differences between Method Reference and Constructor Reference in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 3K+ Views

The Method Reference and Constructor Reference are part of Java 8's functional programming features, they used for refering to methods and constructors without executing them. They are often used in conjunction with functional interfaces, such as those defined in the java.util.function package. Method Reference A method reference is a shorthand representation of a lambda expression for calling a method. A method reference refers to a method without executing it. Method references can refer to static methods, instance methods, and constructors. Constructor Reference A constructor reference is a unique kind of method reference that is a reference to a constructor. ...

Read More

Constructor Chaining In Java programming

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 2K+ Views

The constructor chaining is a specific sequence of calling constructors when a user initializes an object in a certain way. This technique is used when multiple constructors are invoked one after another, based on the instance class. It is also closely related to inheritance, where the role of a subclass constructor is to call the constructor of its superclass. You can perform constructor chaining in two ways: Within the same class - where one constructor calls another constructor of the same class. Across different classes - where a subclass constructor calls ...

Read More

How do we check if a String contains a substring (ignoring case) in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 5K+ Views

Problem Statement The task is, given a string and a substring, you have to check if a substring is present in a string or not. Do not mind if the case of the string and substring is different, it should not matter. For example, if the string is "Hello World" and the substring is "hello", then the output should be true. Even if the substring is "HELLO" or "HeLLo", the output should be true. Solution To solve this problem, we will first convert the string and the substring to lowercase using the toLowerCase() method. The toLowerCase () method of the ...

Read More

Sorting contents of a string that holds integer values in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 4K+ Views

Problem Statement Here we have a string that contains integer values, our task is to sort those integer values in ascending order. For example, if the string is "31134", the sorted string should be "11334". Solution We can solve the above problem using multiple ways: Using char array Using Stream API Using Bubble Sort Using char array We will use the toCharArray() method of the String class to convert the string into a character array. Then we will sort the character array using the Arrays.sort() method. ...

Read More
Showing 1–10 of 105 articles
« Prev 1 2 3 4 5 11 Next »
Advertisements