Java Articles

Page 190 of 450

Java Connection getClientInfo() method with example

Arushi
Arushi
Updated on 19-Sep-2024 2K+ Views

In this article, we will learn how to retrieve and set client information properties in a MySQL database connection using the getClientInfo() method from the Connection interface in JDBC. The program demonstrates how to establish a connection to a database, set custom user credentials as client information properties, and then retrieve and display those values. Steps to use the Java Connection getClientInfo() method Following are the steps to use the Java Connection getClientInfo() method − Register the MySQL driver using the DriverManager.registerDriver() method. Establish a connection to the MySQL database using DriverManager.getConnection(). ...

Read More

Java program to place component in bottom-right corner with BorderLayout

Smita Kapse
Smita Kapse
Updated on 19-Sep-2024 2K+ Views

In this article, we will learn how to place a component, specifically a button, in the bottom-right corner of a Java Swing application using the BorderLayout manager. The BorderLayout is one of the most commonly used layout managers in Java, and it allows you to place components in five different regions: North, South, East, West, and Center. We will demonstrate how to use BorderLayout to ensure the component is placed precisely in the bottom-right corner of the window. Steps to place the component in the bottom-right corner Following are the steps to place the component in the bottom-right corner with ...

Read More

Java program to print distinct permutations of a string

AmitDiwan
AmitDiwan
Updated on 19-Sep-2024 1K+ Views

In this article, we will learn how to generate and print all distinct permutations of a given string using Java. Permutations are rearrangements of characters in a string, and this program will ensure that no duplicate permutations are printed. The method works by checking each rearrangement and avoiding any repeats. Problem Statement Write a program in Java to print distinct permutations of a given string − Input my_str = "mnqm" Output The distinct permutations of the string are[mnqm, nmqm, nqmm, mqnm, qmnm, qnmm, mqmn, qmmn, mnmq, nmmq, mmnq, mmqn] Steps to print distinct permutations of a string Following are the ...

Read More

Java program to convert properties list into a Map

Samual Sam
Samual Sam
Updated on 19-Sep-2024 1K+ Views

In this article, we will learn how to convert a Properties list into a Map in Java. The Properties class is commonly used to store key-value pairs, but sometimes you may need to work with these pairs in a Map structure. We will demonstrate how to take the properties and convert them into a HashMap. Problem Statement Write a program in Java to convert the properties list into a Map structure − Output Key and Value of the Map... P: 1 Q: 2 R: 3 S: 4 T: 5 U: 6 V: 7 Steps to convert the properties list into ...

Read More

Java program to display printable characters

Samual Sam
Samual Sam
Updated on 18-Sep-2024 1K+ Views

In this article, we will learn to display printable characters in Java. The program uses ASCII code from 32 to 126, which correspond to printable symbols, numbers, and letters. Instead of using System.out.println(), we will use System.out.write() to print each character. Problem Statement Write a Java program that displays all printable characters by iterating through their ASCII values − Output Printable characters... ! " # $ % & '( ) * + , - . /0 1 2 3 4 5 6 78 9 : ; < = > ?@ A B C D E F GH I J K L M N OP Q R S T U V WX Y Z [ \ ] ^ _` a b c d e f gh i j k l m n op q r s t u v wx y z { | } ~ Steps to display printable characters Following are the steps to display printable characters − Start by printing the message "Printable characters...". Use a for loop to iterate over ASCII ...

Read More

Java program to delete all even nodes from a singly linked list

John Wick
John Wick
Updated on 18-Sep-2024 530 Views

In this article, we will learn to delete all even nodes from a singly linked list in Java. This Java program demonstrates how to create and manage a singly linked list, including adding nodes, deleting nodes with even values, and printing the list. You will see how to insert nodes, remove nodes with even values, and display the remaining nodes. A singly linked list consists of nodes where each node has two parts: one part stores the data, and the other part holds the address of the next node. This setup allows traversal in only one direction, as each node ...

Read More

Java Program to Sort 2D Array Across Left Diagonal

Shriansh Kumar
Shriansh Kumar
Updated on 18-Sep-2024 978 Views

For a given 2D array, our task is to write a Java program to sort its element present across the left diagonal. For this problem, we need to arrange the elements of the array in such a way that the values are sorted when read from the top left to the bottom right, which is the left diagonal of the array. Example Scenario: Input: matrix = {3, 8, 2}, {6, 5, 4}, {3, 2, 1}; Output: new_matrix = {1, 4, 2}, {2, 3, 8}, {3, 6, 5} Use the below sorting tool to understand the problem: Sorting Tool ...

Read More

Java program to get the difference between two time zones by seconds

Samual Sam
Samual Sam
Updated on 16-Sep-2024 1K+ Views

In this article, we will learn to get the difference between two time zones by seconds using Java. We'll use LocalDateTime, ZoneId, and ZonedDateTime classes from java.time package to achieve this.Problem Statement Write a program in Java to get the difference between two time zones by seconds − Output Difference between two time zones in seconds = 28800 Steps to get the difference between two time zones by seconds Following are the steps to get the difference between two time zones by seconds − First, we will import the necessary classes LocalDateTime, ZoneId, and ZonedDateTime from ...

Read More

Java program to add 3 months to the calendar

Samual Sam
Samual Sam
Updated on 16-Sep-2024 1K+ Views

In this article, we will learn to add 3 months to the calendar. We will take the current date and add 3 months to it using Calendar class in Java. You’ll see how to handle date manipulation and update the date accordingly. Problem Statement Write a program in Java to add 3 months to the calendar. Below is the demonstration of the same − Input Current Date = Fri Nov 23 06:38:56 UTC 2018 Output Updated Date = Sat Feb 23 06:38:56 UTC 2019 Different approaches Below are the different approaches to add 3 months to the calendar − ...

Read More

Java program to change JLabel text after creation

Samual Sam
Samual Sam
Updated on 16-Sep-2024 3K+ Views

In this article, we will learn to change JLabel text after creation in Java. We'll cover two scenarios: changing the label text immediately after creation and updating it in response to a button click. Different approaches to change JLabel text after creation Below are the different approaches to change JLabel text after the creation − Using setText() Method Using a button click Update JLabel text using setText() method Following are the steps to update JLabel text immediately after creation − First we will import JFrame, JLabel, and ...

Read More
Showing 1891–1900 of 4,498 articles
« Prev 1 188 189 190 191 192 450 Next »
Advertisements