Node.js provides powerful tools for working with files, including reading and writing JSON files. JSON (JavaScript Object Notation) is widely used for storing and exchanging data in applications. This article walks you through reading and writing JSON files in Node.js with examples. Approaches to Read JSON file Using fs.readFileSync (Synchronous) Using fs.readFile (Asynchronous) JSON File data.json { "name": "PankajBind", "age": 21, "skills": ["JavaScript", "Node.js", "React"] } Using fs.readFileSync (Synchronous) The fs module in Node.js provides methods to interact with the file ... Read More
JavaScript has a class mechanism, primarily a blueprint for defining objects, including their properties and methods. Data must always be serialized to either store it, transmit it through a network or be used as part of the response to an API call. In this article, we will demonstrate how this can be done using JavaScript by providing examples and outputs as necessary. Approaches Convert JavaScript Class to JSON Using JSON.stringify() Method Adding a Custom toJSON() Method Using Object.assign() Method Using Custom Serializer ... Read More
When using an field, browsers automatically show up and down arrows to adjust the number. While these arrows can be helpful, they might not fit your design. Tailwind CSS doesn't have a built-in way to remove them, so you'll need to manually hide the arrows while still using Tailwind for the rest of your styling. Our goal is to remove the arrows without affecting the other Tailwind styles. Approaches We will cover two methods to remove the arrows from fields: Adding custom CSS for Webkit browsers Cross-browser solution (including ... Read More
In this article, we will learn to generate random number strings in Java. Random numbers are vital in programming for tasks like testing, cryptography, and simulations. A common need is generating random numeric strings, such as verification codes or randomized data. This article uses two Java methods Math.random() for simplicity and the Random class for flexibility and efficiency. Problem Statement Create a program to generate a random string consisting of numeric characters. The string's length should be customizable, and each character must be selected randomly. Input num[] = { '0', '1', '2', '3', '4', '5' }; Output 33241 A random ... Read More
In this article, we will learn about the getMaxBinaryLiteralLength() method of the DatabaseMetaData interface in JDBC. getMaxBinaryLiteralLength() method The getMaxBinaryLiteralLength() method of the DatabaseMetaData interface is used to find out the maximum number of characters (hex) that the underlying database allows for a binary literal. This method returns an integer value, representing the maximum length of a binary literal. If this value is 0 it indicates that there is no limit or, the limit is unknown. Steps to get the DatabaseMetaData object The following are the steps to get the DatabaseMetaData object − ... Read More
In this article, we will learn how to use the getDatabaseMinorVersion() method of the DatabaseMetaData interface in Java to retrieve the minor version of the underlying database. This method helps check the version details of the connected database. What is DatabaseMetaData?The DatabaseMetaData is an interface that provides methods to retrieve metadata about a database, such as the database product name, version, driver name, the total number of tables, views, and more. To get the DatabaseMetaData object, use the getMetaData() method of the Connection interface.Syntax: public DatabaseMetaData getMetaData() throws SQLException; ... Read More
In this article, we will learn how to display a frame after a few seconds in Java using the Timer class. This example shows how to delay the visibility of a frame by 2 seconds using Swing. Timer() class The Timer class is used to schedule tasks that execute after a specific time interval or repeatedly at regular intervals. It allows tasks to be run by a thread that handles the scheduling and execution. Each task can be set to execute either once or repeatedly at fixed intervals. The execution of all tasks is managed by a background thread associated ... Read More
In this article, we will learn the remove the last node of the circular linked list in Java. We set Null to the next pointer of the second-last node to remove the last node from the regular linked list, but in the circular linked list, we need to set the root node to the next pointer of the second-last node. Steps to delete a node from the ending of the circular linked list We will find the second-last node of the circular linked list. While traversing the linked list, we can check whether the next pointer of the current node ... Read More
In this article, we will learn how to set the extent of a JSlider using Java Swing. The extent defines the size of the range that the slider's knob can move within, restricting its movement past a certain point. JSlider JSlider is a component in Java Swing that provides a visual way to select a value by sliding a knob within a specified range. The setExtent() method in JSlider sets the size of the range that the knob covers, which controls how far it can move. setExtent() method The setExtent() method in Java is used to: ... Read More
In this article, we will explore the use of access modifiers in Java by demonstrating their functionality in different scenarios. Access Modifiers Access modifiers are used to set the feature of visibility of some particular classes, interfaces, variables, methods, constructors, data members, and the setter methods in Java programming language. In a Java environment, we have different types of access modifiers. Default - If we declare a function, it will be visible only within a particular package. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP