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 19 of 23

Java Concurrency – yield() method

Alshifa Hasnain
Alshifa Hasnain
Updated on 17-Jan-2025 1K+ Views

In this article, we will learn that concurrency in Java allows multiple threads to execute simultaneously, sharing system resources efficiently. One of the methods provided in the Thread class for managing thread execution is the yield() method. What is the yield() Method? The yield() method is a static method of the Thread class that hints to the thread scheduler that the current thread is willing to pause its execution in favor of other threads of the same or higher priority. It is part of Java's concurrency toolbox and is primarily used for fine-tuning thread execution. Syntax of yield function − ...

Read More

Java Program to Initialize a List

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jan-2025 1K+ Views

In this article, we will learn to initialize a list in Java. A list is an ordered collection that allows us to store and access elements sequentially. It contains index-based methods to insert, update, delete, and search the elements. It can also have duplicate elements. Problem Statement Given a scenario where you need to create and initialize a list in Java, the goal is to understand and implement various approaches to initialize lists effectively.  Input   Initialize an empty list and add elements − "Apple", "Banana", "Cherry" Output  ["Apple", "Banana", "Cherry"] Different Approaches Following are the different approaches to Initialize ...

Read More

JavaScript: take every nth Element of Array and display a fixed number of values?

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jan-2025 980 Views

In this article, we will learn to extract every nth element from an array and display a fixed number of values in Javascript. The objective is to filter out every second element (or more generally every nth element) from an array and limit the result to a specified count of elements. We will explore different approaches in JavaScript for achieving this functionality, each offering a unique way to solve the problem. Problem Statement  Let's say you have an array that takes every nth element. Display a fixed number of values after extracting the elements. Input Let’s say the following is ...

Read More

JavaScript Narcissistic number

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Jan-2025 909 Views

In this article, we will learn to check if a number is Narcissistic in JavaScript. A Narcissistic number is a number that equals the sum of its digits, each raised to the power of the total number of digits. We will explore two approaches to solve this problem an iterative method and a concise string manipulation technique. Narcissistic number A narcissistic number(also known as an Armstrong number) in a given number base b is a number that is the sum of its digits each raised to the power of the number of digits. For example − 153 = 1^3 + ...

Read More

Java Program to enable cell selection in a JTable

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Jan-2025 925 Views

In this article, we will learn to enable cell selection in a JTable in Java Swing. By default, JTable allows row or column selection, but enabling cell selection gives users the ability to select individual cells. This feature is useful for tasks that require precise control over table data, such as editing or copying specific values. Approach for Enabling Cell Selection in JTableThe goal is to create a JTable where users can select individual cells, rather than just rows or columns. The approach focuses on: Creating the JTable: We define a table with data ...

Read More

JavaScript - array undefined element count

Alshifa Hasnain
Alshifa Hasnain
Updated on 14-Jan-2025 926 Views

In this article, we will learn to count the number of undefined elements in an array using JavaScript. When working with arrays in JavaScript, you may encounter situations where certain elements are either explicitly set as undefined or are missing altogether (often represented by empty slots in sparse arrays). Problem Statement Given an array that may contain undefined values, we need to count how many elements in the array are defined (i.e., not undefined).  Input const arr = [12, undefined, "blabla", , true, 44]; Output 44 elements are defined (12, "blabla", true, and 44). Thus, the expected output is ...

Read More

JavaScript equivalent of Python\'s zip function

Alshifa Hasnain
Alshifa Hasnain
Updated on 14-Jan-2025 1K+ Views

In this article, we will learn the JavaScript equivalent of Python's zip Function In Python, the zip() function is a convenient way to combine multiple tables into a single iterable of tuples. However, JavaScript does not have a built-in equivalent for this functionality Problem Statement Given two or more arrays of equal length, implement a function in JavaScript that combines these arrays into a single variety of arrays, where each inner array contains the elements from the input arrays at the corresponding positions. Input arr1 = [1, 2, 3], arr2 = ['a', 'b', 'c']Output [[1, 'a'], [2, 'b'], [3, 'c']] ...

Read More

JavaScript: How to loop through all DOM elements on a page and display result on console?

Alshifa Hasnain
Alshifa Hasnain
Updated on 14-Jan-2025 1K+ Views

In this article, we will learn how to iterate through all DOM elements on a webpage using JavaScript. By doing so, we can easily access and manipulate various elements of the page, whether for debugging, gathering information, or applying changes to the page's structure and content. We'll walk through a step-by-step process to loop through all elements and display the results in the console, helping you better understand how to interact with the DOM. What is the DOM? The Document Object Model (DOM) is a representation of the structure of a webpage. It treats each part of the webpage (HTML ...

Read More

Java Program to Print Upper Star Triangle Pattern

Alshifa Hasnain
Alshifa Hasnain
Updated on 07-Jan-2025 1K+ Views

In this article, we will learn to print the upper star triangle pattern in Java. Printing patterns is a common exercise to strengthen the understanding of loops in programming. One of the most popular patterns is the Upper Star Triangle, which visually resembles an inverted right-angled triangle of stars aligned from the top. Below is a demonstration of the same − Input Enter the number of rows : 8 Output The upper star triangle star pattern : * ...

Read More

Java Program to convert integer to String with Map

Alshifa Hasnain
Alshifa Hasnain
Updated on 07-Jan-2025 823 Views

In this article, we will learn to convert integers to String with Map in Java. The Stream API has become an essential tool for processing collections of data in a more declarative and readable way. Instead of using traditional loops, streams allow developers to filter, map, and perform other operations on data with minimal code Problem Statement Given an integer, we need to convert it to its string representation where the integer is treated as a character (e.g., 5 becomes "5", 10 becomes "10"). We'll use a Map to define the integer-to-string mappings and retrieve the string equivalent for a ...

Read More
Showing 181–190 of 221 articles
« Prev 1 17 18 19 20 21 23 Next »
Advertisements