Show Images with a Click in JavaScript using HTML

Kalyan Mishra
Updated on 11-Sep-2024 14:20:07

38K+ Views

To display images on click using JavaScript and HTML. This article covers creating hidden images, adding click events, and revealing images dynamically for an interactive user experience. Users want to create an interactive web page where images are initially hidden and can be revealed with a click, enhancing user engagement and page load times. The challenge is implementing this functionality using JavaScript and HTML simply and efficiently. Approaches to Show Images with a Click Using the Style Display Property Using the classList.toggle() Method Using Hidden ... Read More

Create a Vertical Line with CSS

AmitDiwan
Updated on 11-Sep-2024 13:51:37

3K+ Views

To create a vertical line with CSS, is a simple process that can be done using various approaches. In this article, we will learn and understand three different approaches for creating a vertical line with CSS We are using border and some block elements in this article, our task is to create a vertical line with CSS. Approaches to Create a Vertical Line Here is a list of approaches to create a vertical line with CSS which we will be discussing in this article with stepwise explaination and complete example codes. Creating Vertical Line using ... Read More

Calculate Sum of Squares of First N Natural Numbers in Java

AmitDiwan
Updated on 11-Sep-2024 12:25:33

972 Views

In this article, you will learn to write a program in Java to calculate the sum of squares of first n natural numbers. This program efficiently computes the sum using a mathematical formula − (val * (val + 1) / 2) * (2 * val + 1) / 3 Problem Statement Write a program in Java to calculate the sum of squares of first n natural numbers, where n is a user-defined value. Input val = 8 Output The sum of squares of first 8 natural numbers is204 Steps to calculate sum of squares of first n natural numbers Following are ... Read More

Set Title Position in Java

George John
Updated on 11-Sep-2024 12:25:16

1K+ Views

In this article, you'll learn how to position the title of a border in a Java Swing application using the setTitlePosition() method. We'll position the title above the border's top line by utilizing the TitledBorder.ABOVE_TOP constant. This technique is useful for customizing the appearance of your Swing components. To set title position, use the setTitlePosition() method in Java. Let’s say we have to position the title above the border's top line. For that, use the constant ABOVE_TOP for the border − setTitlePosition(TitledBorder.ABOVE_TOP); Steps to set title position Following are the steps to set title position in Java − ... Read More

Java SQL Time toString() Method with Example

Vikyath Ram
Updated on 11-Sep-2024 12:24:43

1K+ Views

In this article, you'll learn how to convert a Time object into a String using the toString() method from the java.sql.Time class. This method allows us to easily transform a Time object into its JDBC escape format, which can then be handled as a string. //Retrieving the Time object Time timeObj = rs.getTime("DeliveryTime"); //Converting the Time object to String format String time = timeObj.toString(); Steps for using Java sql.Time toString() Method Following are the steps for using Java sql.Time toString() Method − Create a MySQL table named dispatches. Insert some sample records into ... Read More

Write an Array of Strings to a File in Java

Samual Sam
Updated on 11-Sep-2024 12:24:20

2K+ Views

In this article, we will learn how to write an array of strings to a text file using Java. The program demonstrates how to use the FileWriter class to create and write a file. This method helps save data to a text file for future retrieval or processing. FileWriter class: This class extends the OutputStreamWriter class and is used to write streams of characters to a file. It provides methods to write text data easily and efficiently, making it a key tool for handling file output operations in Java. Problem Statement Write a program in Java that writes an array ... Read More

Implement Insertion Sort in Java

karthikeya Boyini
Updated on 11-Sep-2024 12:23:46

2K+ Views

In this article, we will learn to implement insertion sort in Java. The insertion sort is an in-place comparison-based sorting algorithm. Here, a sub-list is maintained which is always sorted. For example, the lower part of an array is maintained to be sorted. An element to be inserted in this sorted sub-list must find its appropriate place and then be inserted there. Hence the name, insertion sort. The array is searched sequentially and unsorted items are moved and inserted into the sorted sub-list (in the same array). Problem Statement For a given array write a program in Java to implement ... Read More

Count Set Bits in an Integer in Java

Shriansh Kumar
Updated on 11-Sep-2024 11:15:02

3K+ Views

In this article, we are given an integer value and the task is to count the total number of set bits of the given integer. For this task, we need to convert the given value into its corresponding binary representation. The binary number of an integer value is represented as the combination of 0's and 1's. Here, the digit 1 is known as the Set bit in the terms of the computer. Problem Statement Write a program in Java to count set bits in an integer − Input  int num = 10 Output binary representation = 1010 set bit ... Read More

Convert LocalDate to java.util.Date in Java

Shriansh Kumar
Updated on 11-Sep-2024 11:12:58

3K+ Views

Suppose a date is given in LocalDate format, our task is to write a Java program that converts it into java.util.Date. For this problem, we need to add time information to the LocalDate by combining it with a time, such as midnight, or a timezone. Both LocalDate and java.util.Date classes are used to represent a date in Java. But, the LocalDate class, introduced with the release of Java8, represents a date without timezone information, whereas, the Date class is mutable and used for representing date and time with timezone. Let's understand the problem statement with an example. Example Scenario: Input: ... Read More

Initialize HashMap with Lambda Expressions in Java

Shriansh Kumar
Updated on 11-Sep-2024 11:08:40

1K+ Views

Initialization of a Java HashMap means creating an instance of the HashMap class and adding elements to it. The standard way to initialize a HashMap is by using the new keyword. However, we will use the lambda expression in this article. Lambda expressions are methods without any names. It was introduced with the release of Java8. And, HashMap is a class of Java Collection Framework that implements Map Interface. It stores its element in key-value pairs. The Key is an object that is used to retrieve value associated with it. Example 1 The following Java program explains how to initialize ... Read More

Advertisements