Java Articles

Page 170 of 450

Java ResultSetMetaData getPercision() method with example

Rishi Raj
Rishi Raj
Updated on 10-Feb-2025 517 Views

In this article, we will learn how to retrieve the size of a specified column in a ResultSet object using the getPrecision() method of the ResultSetMetaData interface in JDBC. What does getPrecision() in ResultSetMetaData do? The getPercision() method of the ResultSetMetaData (interface) retrieves the size of the specified column in the current ResultSet object. This method accepts an integer value representing the index of a column and, returns an integer value representing the size of the given column. Steps to get the ResultSetMetaData object To get the ResultSetMetaData object, you need to − Step 1. Register ...

Read More

Java Program to Find the Volume of Cylinder

AYUSH MISHRA
AYUSH MISHRA
Updated on 04-Feb-2025 17K+ Views

A cylinder is a three-dimensional geometric shape with two parallel circular bases connected by a curved surface. The volume of a cylinder can be calculated using a mathematical formula that considers its radius and height. Problem Description In this tutorial, we are going to discuss how to find the volume of a given cylinder in Java using different approaches. Formula for Volume of Cylinder The formula for the volume of a cylinder is as follows: Volume of Cylinder = π × r² × h where: r: The radius of the circular base. h: The height of the cylindrical body. ...

Read More

Java Program to Illustrate Use of Binary Literals

Sakshi Ghosh
Sakshi Ghosh
Updated on 28-Jan-2025 650 Views

In this article, we will learn to illustrate the use of binary literals in Java. This feature is particularly useful when working with low-level data manipulation, such as in embedded systems or when dealing with bitwise operations. What is Binary Literal? A binary literal is a number that is denoted using binary digits that are 0s and 1s. The values written in data types – byte, int, long, and short can be easily expressed in a binary number system. The prefix 0b or 0B is added to the integer to declare a binary literal. For example − ...

Read More

Java ResultSetMetaData getColumnDisplaySize() Method with Example

Alshifa Hasnain
Alshifa Hasnain
Updated on 28-Jan-2025 714 Views

In this article, we will learn the ResultSetMetaData getColumnDisplaySize() method with an example in Java. This is useful when you need to understand the display requirements of a column in a result set. Method Signature The getColumnDisplaySize(int column) method of the ResultSetMetaData class in Java retrieves the maximum width of the specified column, measured in characters. int getColumnDisplaySize(int column) Parameters: The 1-based index of the column for which you want the display size. Returns: The maximum number of characters that can be displayed for the specified column. ...

Read More

Java NumberFormat.getPercentageInstance() Method

Samual Sam
Samual Sam
Updated on 28-Jan-2025 750 Views

In this article, we will learn the NumberFormat.getPercentageInstance() method. Java provides powerful tools for formatting numbers, currencies, and percentages through the java.text.NumberFormatclass. One of the most useful methods in this class is the getPercentageInstance() method. NumberFormat.getPercentageInstance() method The NumberFormat.getPercentageInstance() method is a static method that returns a NumberFormat instance configured to format numbers as percentages. This method can be used with or without a Locale parameter.  Syntax − public static NumberFormat getPercentageInstance()public static NumberFormat getPercentageInstance(Locale locale) Without Locale: If no locale is specified, the method uses the default locale of the JVM. ...

Read More

Java ResultSet getType() Method with Example

Arushi
Arushi
Updated on 28-Jan-2025 1K+ Views

In JDBC (Java Database Connectivity), the ResultSet interface represents the result set of a database query in Java. One of the important methods provided by ResultSet is getType(), which returns the type of the ResultSet object. Result getType() method The getType() method is used to determine the type of cursor and its behavior when scrolling through the result set.Syntax of getType() int resultSet_Type = rs.getType(); This method returns an integer value that corresponds to one of the ResultSet type constants. These constants indicate the type of cursor used by the ResultSet: ResultSet.TYPE_FORWARD_ONLY (value: 1003): This ...

Read More

Get the union of two sets in Java

karthikeya Boyini
karthikeya Boyini
Updated on 28-Jan-2025 7K+ Views

The union of two sets combines all the unique elements from both sets into one. In Java we can achieve this using the HashSet class, which ensures no duplicate elements. This article will demonstrate two approaches to finding the union of two sets.  Different Approaches  Following are the two different approaches to getting the union of two sets in Java − Using the addAll() Method Using Streams Using the addAll() Method The simplest way to find the union of two sets is by using the addAll() method of the HashSet class. This ...

Read More

How to create immutable class in Java?

Rishi Raj
Rishi Raj
Updated on 28-Jan-2025 1K+ Views

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

Static methods vs Instance methods in Java

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 28-Jan-2025 3K+ Views

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

Java program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 28-Jan-2025 537 Views

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
Showing 1691–1700 of 4,498 articles
« Prev 1 168 169 170 171 172 450 Next »
Advertisements