When working with JavaScript, especially in a Node.js or modern JavaScript environment, you often come across two popular module systems: use require which comes from the CommonJS and import and export keywords which came with ES6. They are both used with the same goal of modularizing your code but they differ as to how and what you use or do with them. Now let us discuss these differences in a greater detail. What is Node.js require? The require is the module-loading mechanism in CommonJS, the default module system for Node.js. It allows you to include modules, JSON files, or local ... Read More
Operators are special symbols in C that performs an operation on values and variables. These special symbols allow us to manipulate data and variables in different ways. Those Operators are classified into the following − Arithmetic operators. Relational operators. Logical operators. Assignment operators. Increment and decrement operators. Bitwise operators. Conditional operators. Special operators. Expressions in C is a combination of variables, operators, and values that generates ... Read More
We need to find a number of all the pairs that has the maximum sum, In a given array of integers. A pair consists of two numbers, and the sum is simply the result of adding them. We will see multiple solutions to this problem, starting with a naive (brute force) approach and moving to more optimized solutions. Below is the list of approaches we will cover in this article: Brute Force approach using two loops Max Sum Pairs with Sorting ... Read More
Node.js is one of the most vital tools in the hands of modern developers to create the necessary server applications. In this article, you will learn about how to create and run a Node.js project in one of the best, and most used, editors named Visual Studio Code (VS Code). What is Node.js? Node.js is an open-source cross-platform runtime environment for executing JavaScript code on the server side. It will be beneficial for creating web servers, APIs, and applications that run in real-time. Key Features of Node.js The following are the key features of Node.js − ... Read More
In Java, we can create a date object using the calendar class, which gives us more control on date and time. We will discuss the process in this article. What is the Calendar class? In order to understand the usage of we must know what is the calendar class. The Calendar class allows us to work with date and time more easily than Date class. like, we can set specific parts of the date, like month, year, and day. For using Calendar class, import the following package. import java.util.Calendar; Now, let us create an object of Calendar class. Calendar ... Read More
In programming, functions often require parameters to be passed to them to be called or invoked. There are 2 ways to call functions, the 1st being call by Reference and the 2nd being call by value. In this article, we are going to demonstrate call by value in Java. Call by value is a method in which the value of the argument is passed as a copy to the function, hence any change made to this argument inside the function will not affect the original value of the argument beyond the scope of this function. To help understand these concepts ... Read More
In this article, we will access a specific character from a string by using the charAt() method in Java. The program will demonstrate how to locate and display a character at a specified position within a string. Problem Statement We have a string, and we need to retrieve the character at a given position. For example, if we use the string "laptop", we want to display the character located at the 4th position (0-based index). Input "laptop" Output String: laptop Character at 4th position: t Steps to access character of a string The following an steps to access the ... Read More
The set covering is a well-known NP-hard problem in the combinational optimization technique. We call the set cover problem NP-Hard because there is no polynomial real-time solution available for this particular problem. An algorithm called greedy heuristic is a well-known process for the set cover problem. Here is an example − Let U be the universe of elements, {S1, S2, .....Sm} be collection of subsets of the set, U and Cost(S1), C(S2), ......Cost(Sm) be costs of subsets. 1)Let I is the set of elements included so far. Initialize the process I = {} 2) Do following ... Read More
In this article, we will learn how to generate a string representation of the contents of arrays in Java. Using Arrays.deepToString() transforms arrays into readable strings, making it easy to visualize their structure. This method is particularly useful for one-dimensional and multidimensional arrays. Problem StatementGiven arrays with varying structures, write a Java program that prints the elements of these arrays and their string representations using Arrays.deepToString().Input A one-dimensional array:Object[] ob = {"One", "Two", "Three", "Four"} A two-dimensional array:int[][] arr = {{10, 20, 30}, {40, 50, 75}, {100, 150, 200}}Output For the one-dimensional array:Array elements...Value = OneValue = TwoValue ... Read More
This Java article discusses the InputStream.close() function to close the input stream and free up system resources. The method java.io.InputStream.close() is used to close this input stream and release any system resources associated with the stream. This method requires no parameters and returns no value. Also, the IOException is thrown when an I/O error occurs. Problem StatementGiven an input stream, write a Java program to close this input stream and release any system resources associated with it. Ensure that the program handles any exceptions that may occur if the stream is already closed or an I/O error is ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP