Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Object Oriented Programming Articles
Page 358 of 589
Java program to check if two given matrices are identical
Problem Statement Two matrices are identical if their number of rows and columns are equal and the corresponding elements are also equal. An example of this is given as follows. Input Matrix A = 1 2 3 4 5 6 7 8 9 Matrix B = 1 2 3 4 5 6 7 8 9 The matrices A and B are identical Output Both the matrices are identical Steps to check if two given matrices are identical Following are the steps to check if two given matrices are identical − Initialize two matrices by defining two ...
Read MoreJava DatabaseMetaData getPrimaryKeys() method with example
DatabaseMetaData DatabaseMetaData is an interface that provides methods to access metadata about the database itself. getPrimaryKeys() method The getPrimaryKeys() method of the DatabaseMetaData interface in Java is used to retrieve information about the primary keys of a table in a database. A primary key is a unique identifier for each record in a table. It accepts 3 parameters − catalog - A string parameter representing the name of the catalog (database in general) in which the table exists, pass "" to get the description of the ...
Read MoreJava program to set an icon for JOptionPane
In this program, we will learn how to set a custom icon in a JOptionPane using Java's Swing framework. A JOptionPane allows displaying dialog boxes for different purposes such as messages, inputs, or confirmations. In this example, we will create a dialog box with a custom image icon displayed alongside some text. This can be particularly useful for creating visually appealing user interfaces. Problem Statement Write a Java program to set an icon for JOptionPane. Below is the demonstration of the same − Output Steps to set an icon for JOptionPane Following are the steps to set an ...
Read MoreJava program to remove the leading and trailing quotes from a string
In Java, handling strings with quotes can be managed by checking and manipulating the string’s start and end. This example demonstrates how to remove double quotes from both the beginning and end of a string. Problem Statement Given a string enclosed in double quotes, write a Java program to remove these enclosing quotes. The result must be the original string without the enclosing double quotes. Input String with double quotes= "Demo Text" Output String after removing double quotes = Demo Text Steps to remove the leading and trailing quotes from a string Below are the steps to remove the leading ...
Read MoreJava Connection getClientInfo() method with example
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 MoreJava program to place component in bottom-right corner with BorderLayout
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 MoreJava program to convert properties list into a Map
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 MoreJava program to display printable characters
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 MoreJava Program to Sort 2D Array Across Left Diagonal
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 MoreJava program to get the difference between two time zones by seconds
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