An immutable class object's properties cannot be modified after initialization. The state of an immutable object remains constant throughout its lifetime. To achieve immutability, the class is designed such that its fields are initialized only once through a constructor, and no methods are provided to modify those fields. For example: String is an immutable class in Java. We can create an immutable class by following the given rules below − Make class final − class should be final so that it cannot be extended. ... Read More
In Java, the behaviour of any variable or method is defined by the keyword used in front of its declaration. One of the non-access modifiers is static, which can be used with both methods and variables. The static methods are defined at the class level and can be accessed without creating an instance of the class, while instance methods require an object of the class for accessibility. Static methods exist as a single copy for the entire class, whereas instance methods exist as multiple copies, depending on the number of instances created for that particular class. Static methods cannot directly ... Read More
We will discuss the Java Math subtractExact(long x, long y) method in Java and understand its functionalities and working. The subtractExact()is an inbuilt function in the Java Math library. The function returns the difference between the two parameters passed as arguments in the function. The function returns an exception when the returned value overflows the range of values of a particular data type. It is the most commonly used class for mathematical operations is the java.lang.Math class is a part of the Java Standard Library and is included in the java.lang package. Syntax Following is the syntax of the subtractExact() function ... Read More
The length of the longest consecutive 1s in the binary representation of a given integer involves converting the integer to its binary form and then identifying the longest run of contiguous 1s. Here, we can represent each integer in binary as a series of 0s and 1s. Bitwise operations allow efficient bit manipulation, making it easy to count and update the longest sequence of consecutive 1s. Consider special cases such as when the integer is 0 (binary representation 0) or when it contains only 1s (e.g., for the number 7, binary 111). To understand the concept clearly, Let's go through ... Read More
To compare two HTML elements we will use HTML and Javascript. HTML and JavaScript is a popular combination where there are instances whereby you need to compare two HTML elements. You may want to know if the two elements are absolutely similar in terms of structure, Class ID or §, etc. In this article, we will explore two common approaches to compare HTML elements in JavaScript: Manual Comparison and JSON-based Comparison. 1. Comparing HTML Elements Manually It simply means that, in manual comparison, you are fully in charge of the properties that you would want to compare. In this method, ... Read More
Introduction Web modals can be described as an important aspect of web user interfaces since they give the option to show data or for the user inputs without changing the page other than the modal. Using CSS to apply transitions aids the UI where opening and closing display modals to the user are smooth and more natural. In this tutorial, you will learn how you can use CSS transitions to have more engaging access to a page with a modal dialog box. Requirements To follow along with this tutorial, you will need − Knowledge and ... Read More
Introduction In this article, we will see the development of a form for feedback, surveys, and user data. The survey form should have an appealing outlook, as well as guarantee that the data collected is reliable and systematized. In this, we will see how to create a survey form in HTML and CSS that is fully functional as well as visually appealing. Overview Here, the goal of this article is to help you understand the process of making a survey form responsive and beautiful with the common data about the user that are name or nickname, e-mail, age, and position, ... Read More
To improve query efficiency, MySQL has a specific data type called ENUM that stores string values as numeric indexes. By limiting values to particular possibilities, ENUM, in contrast to standard string types, ensures data consistency and streamlines comparisons. The SHOW COLUMNS statement is used to fetch all the possible values of ENUM, under the type column this is a straightforward way to understand, and validate data and also to check the constraints in the database schema. Retrieving the possible values of ENUM In the below example let us see how to create an ENUM column, fetch the data, and ... Read More
Filtering data by date or datetime is a common requirement when working with SQL queries. Whether you're retrieving records for a specific date, a range of dates or precise timestamps SQL provides robust tools to handle such scenarios. Understanding Date and DateTime Data Types The SQL databases support various data types for storing the date and time information: DATE: Stores only the date (e.g. 2025-01-07). DATETIME: The Stores both date and time (e.g. 2025-01-07 14:30:00). TIMESTAMP: The Stores date and time with time zone information in some ... Read More
Converting rows into columns also known as pivoting is a common requirement in SQL. Pivoting transforms data to present it in a more organized, user-friendly format, especially for reporting or analytics purposes. In this article, we’ll explore the different methods available in MySQL to achieve this transformation. Let’s consider a sample table named sales: Year Region ... Read More