Java Articles

Page 180 of 450

Java program to get number of elements with odd factors in given range

AmitDiwan
AmitDiwan
Updated on 18-Nov-2024 358 Views

In this article, we will learn how to count the number of elements with odd factors (i.e., perfect squares) in a given range using Java. Perfect squares have odd divisors, and we can calculate them by counting the perfect squares in the specified range. Problem StatementGiven a range defined by a lower and upper bound, write a Java program to calculate how many numbers in this range have odd factors (i.e., perfect squares).Input Lower Range: 55Upper Range: 1000Output The number of elements with odd factors between 55 and 1000 is: 24 Steps to calculate the number of elements with ...

Read More

Java program to set JTextArea to wrap by word

Smita Kapse
Smita Kapse
Updated on 15-Nov-2024 1K+ Views

In this article, we will learn to set a JTextArea in Java to wrap text by word, ensuring that the words in the text fit neatly within the display area rather than breaking in the middle. We will create a simple GUI application using JTextArea and configure it to wrap text by word, so the content is more readable within the bounds of the text area. Steps to set JTextArea to wrap by word Following are the steps to set JTextArea to wrap by word − Import the required classes from javax.swing and java.awt for GUI ...

Read More

Java program to convert HashMap to TreeMap

Samual Sam
Samual Sam
Updated on 15-Nov-2024 803 Views

In this article, we will convert a HashMap to a TreeMap in Java. A HashMap is used for storing data as key-value pairs, but it doesn’t keep the keys in any particular order. A TreeMap sorts the keys in ascending order. By converting a HashMap to a TreeMap, we can ensure that the keys are stored in a sorted way. Problem StatementGiven a HashMap filled with key-value pairs, we need to convert it into a TreeMap so that the entries are sorted by the keys.Input ("1", "A"), ("2", "B"), ("3", "C"), ("4", "D"), ("5", "E"), ("6", "F"), ("7", ...

Read More

Java DatabaseMetaData getCatalogs() method with example

Rishi Raj
Rishi Raj
Updated on 14-Nov-2024 963 Views

In this article, we’ll look at how to retrieve and display the list of available catalogs (databases) in a MySQL instance using Java’s JDBC (Java Database Connectivity) API. By running a Java program that connects to the MySQL server, we’ll use the DatabaseMetaData class to fetch catalog names with the getCatalogs() method, showing each catalog’s name on the console. This process demonstrates how to access and navigate metadata in MySQL using JDBC, offering insight into the structure of your database environment. Steps to retrieve database catalogs  The getCatalogs() method of the DatabaseMetaData interface returns the name of the underlying database ...

Read More

Java program to disable the first item on a JComboBox

Krantik Chavan
Krantik Chavan
Updated on 14-Nov-2024 1K+ Views

In this article, we will learn to disable the first item on a JComboBox using Java. This setup is useful for applications where you want to show a placeholder as the first item and prevent it from being chosen, so users must select a valid option. We will be using JComboBox. JComboBox class The JComboBox class in Java is a useful component that combines a dropdown list with a button or a text field. This lets users pick an option from the list or type their input if editing is allowed. It’s great for creating forms where users can choose ...

Read More

Java program to deselect a range of columns in a JTable

Chandu yadav
Chandu yadav
Updated on 14-Nov-2024 304 Views

In this article, we will learn how to deselect a range of columns in a JTable using Java. JTable is a part of the Swing framework in Java, which is used to display and edit tables. Sometimes, we may want to deselect a specific range of columns after selecting columns in a table. This can be done by using the removeColumnSelectionInterval() method. Problem Statement Given a JTable with columns selected, write a Java program to deselect a range of columns from the table. Input A JTable with columns selected.Output The specified range of columns will be deselected. Steps to ...

Read More

Difference between Java and JavaScript.

Aishwarya Naglot
Aishwarya Naglot
Updated on 14-Nov-2024 1K+ Views

As we know, both Java and JavaScript are programming languages and are used in application development. But there are significant differences between the languages, which we will discuss below. Java Java is a high-level language that is also a platform-independent language. It is mainly used in the development of web applications, mobile applications, games, etc. Java is a statically typed language, which means that the code must be checked for errors before it runs. JavaScript whereas JavaScript is a dynamically typed language, which means that the code is checked for errors while it runs. JavaScript is a client-server-side language, which ...

Read More

Java program to count the child of root node in a JTree

George John
George John
Updated on 13-Nov-2024 397 Views

In this article, we will go over a Java program that counts the number of child nodes of the root node in a JTree using Java. This program uses the getChildCount() method to retrieve and display the count of direct child nodes under the root. This is helpful for applications involving hierarchical structures, like directories or organizational charts. Steps to count the child of the root node in a JTree Following are the steps to count the child of the root node in a JTree −Import the necessary classes JFrame, JTree, and DefaultMutableTreeNode from java.swing package.Create a main class named SwingDemo.Define the ...

Read More

Java program to find the surface area and volume of cuboid

AmitDiwan
AmitDiwan
Updated on 13-Nov-2024 767 Views

In this article, we will learn how to compute a cuboid's surface area and volume using Java. A cuboid is a three-dimensional object with six faces in a rectangle shape, which means it has sides of different lengths and breadth. The difference between a cube and a cuboid is that a cube has equal length, height, and breadth, whereas these three are not the same in cuboids.  Problem Statement Write a program in Java to find a cuboid's surface area and volume. Below is a demonstration of the same − Input Length= 6; Width= 7; Height= 8; Output Volume Of the Cuboid is ...

Read More

Create a Date object using the Calendar class in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 11-Nov-2024 2K+ Views

In Java, we can create a date object using the calendar class, which gives us more control on date and time. We will discuss the process in this article. What is the Calendar class? In order to understand the usage of we must know what is the calendar class. The Calendar class allows us to work with date and time more easily than Date class. like, we can set specific parts of the date, like month, year, and day. For using Calendar class, import the following package. import java.util.Calendar; Now, let us create an object of Calendar class. Calendar ...

Read More
Showing 1791–1800 of 4,498 articles
« Prev 1 178 179 180 181 182 450 Next »
Advertisements