Alshifa Hasnain

Alshifa Hasnain

Converting Code to Clarity

About

A professional technical content writer with Java programming skills. I have a desire to write informative and detailed Java articles for both beginner and professional developers. Having a strong background in HTML, CSS, JavaScript, Java, JDBC, JSP, Spring, and Hibernate.

221 Articles Published

Articles by Alshifa Hasnain

Page 14 of 23

What is decrement (--) operator in JavaScript?

Alshifa Hasnain
Alshifa Hasnain
Updated on 11-Mar-2025 726 Views

The decrement operator in Javascript decreases an integer value by one. This operator is often utilized in loops, counters, and mathematical computations where a value has to be decreased sequentially. Types of Decrement Operators The decrement operator (--) can be used in two ways − Post-decrement (x--):  It provides the current value of the variable prior to its decrement. Pre-decrement (--x): It first decreases the value and then returns the variable's new value. Syntax x--; // Post-decrement --x; // Pre-decrement Example Below is an example where the value of ...

Read More

Java Program for Cocktail Sort

Alshifa Hasnain
Alshifa Hasnain
Updated on 10-Mar-2025 462 Views

In this article, we will learn to perform cocktail sorting in Java. Cocktail Sort, also known as Bidirectional Bubble Sort, is a variation of the standard Bubble Sort algorithm. What is Cocktail Sort? Cocktail Sort works in contrast to bubble sort, wherein elements are iterated from left to right, and the largest element is first brought to its correct position, and so on. In cocktail sort, elements are iterated over in both directions (left and right) in an alternating fashion. Cocktail Sort Working Following are the steps to perform cocktail sort in Java − Traverse ...

Read More

JavaScript program to count triplets with sum smaller than a given value

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Mar-2025 534 Views

In this article, we will learn to count triplets with a sum smaller than a given value in JavaScript. Triplets in an array whose sum is less than a provided number is a popular problem in competitive coding and algorithm design. Problem Statement Given an array of integers and a target sum, we need to find the number of triplets (a, b, c). For exampleInput const arr = [5, 1, 3, 4, 7]; const sum = 12;Output 4 Explanation: The valid triplets are :(1, 3, 5)(1, 3, 4)(1, 4, 5)(1, 3, 7), all having a sum of less than 12. ...

Read More

JavaScript checking if all the elements are same in an array

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Mar-2025 589 Views

In this article, we will learn to check if all the elements are the same in an array in JavaScript. Finding all elements of an array to be the same is a frequent problem in JavaScript, usually needed for data validation, game logic, and algorithm building. Problem Statement We are required to write a JavaScript function that takes in an array of literals. The function should find whether or not all the values in the array are the same. If they are the same, the function should return true, or false otherwise. For Example Input const arr2 = [1, 1, ...

Read More

Java DatabaseMetaData getURL() method with example

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Mar-2025 561 Views

In this article, we will learn about the DatabaseMetaData getURL() method in Java. The DatabaseMetaData interface provides useful methods to obtain details about the database and the JDBC driver. One such method is getURL(), which returns the URL of the JDBC driver being used. What is the getURL() Method? The getURL() method in Java's DatabaseMetaData interface is used to retrieve the URL of the database to which the current connection is established. Syntax String dbUrl = metaData.getURL(); This method retrieves the URL of the underlying Database Management System and returns it in the form of a String variable. ...

Read More

JavaScript focus a particular element with div class, not div id declaration?

Alshifa Hasnain
Alshifa Hasnain
Updated on 04-Mar-2025 2K+ Views

In this article, we will learn to focus on a particular element with a div class in JavaScript. In JavaScript setting focus on an element is commonly done using the focus() method. What is the focus() method? The focus() method in JavaScript is used to bring a specific element into focus. This means the element becomes active, allowing the user to interact with it, such as typing in an input field or highlighting a section of the webpage. Syntax element.focus(); Here, the element is the DOM element that will receive the focus. Using JavaScript to Focus on a Class Element ...

Read More

Java program to subtract 40 days from the calendar

Alshifa Hasnain
Alshifa Hasnain
Updated on 04-Mar-2025 487 Views

In this article, we will learn to subtract 40 days from the calendar in Java. Working with dates is a frequent need in programming, and there are multiple methods of doing it in Java. One of the simplest approaches is to use the Calendar class to remove days from a date. Different Approaches The following are the two to subtract 40 days from the calendar in Java − Using the Calendar Class Using the LocalDate Class Using the Calendar Class The first approach utilizes the Calendar class, which is part ...

Read More

JavaScript program to generate all rotations of a number

Alshifa Hasnain
Alshifa Hasnain
Updated on 03-Mar-2025 687 Views

In this article, we will learn to generate all rotations of a number in JavaScript. Producing a primary common problem such as all its rotations comprises the creation of all possible permutations of the digits by rotating its digits. Problem Statement The goal is that if we have given a number, we need to generate all possible rotations of its digits. A rotation is defined as moving the first digit to the end of the number. For exampleInput  123 Explanation  123 (original number) 231 (first rotation: move 1 to the ...

Read More

Java program to map string list to lowercase and sort

Alshifa Hasnain
Alshifa Hasnain
Updated on 03-Mar-2025 834 Views

In this article, we will learn to map a String list to lowercase and sort in Java. We need to manipulate the elements of a list, such as converting all strings to lowercase and sorting them. This is particularly useful when dealing with user input, file processing, or data normalization. Problem Statement Given a list of strings, we want to convert all strings to lowercase and sort the list in reverse alphabetical order.For Example: Input ["Apple", "banana", "Cherry", "date"] Output ["date", "cherry", "banana", "apple"] Using Streams API The Streams API provides a useful and functional approach to processing ...

Read More

Java program to display date and time information in uppercase

Alshifa Hasnain
Alshifa Hasnain
Updated on 03-Mar-2025 727 Views

In this article, we will learn to display the date and time in uppercase using Java. Working with date and time in Java is a common requirement in various applications, logging, scheduling, or data processing. Different Approaches The following are the two different approaches to display the date and time in uppercase using Java − Using Formatter and Calendar Using DateTimeFormatter Using Formatter and Calendar The Formatter class in Java allows us to format date and time using the %Tc specifier. We can then convert the output to uppercase using ...

Read More
Showing 131–140 of 221 articles
« Prev 1 12 13 14 15 16 23 Next »
Advertisements