Check if a String is Empty or Null in Java

AmitDiwan
Updated on 08-Nov-2024 22:31:26

1K+ Views

In this article, we will understand how to check if a string is empty or null in Java. The string is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). We’ll start by learning to detect these cases directly within the main method, and then we’ll see how to achieve the same result using encapsulation for better code organization and reusability. Problem Statement Write a program in Java to check if a string is empty or null. Below is a demonstration of the same − Input Input string: null Output The string is a null ... Read More

Read a Large Text File Line by Line in Java

Saba Hilal
Updated on 08-Nov-2024 22:30:45

765 Views

This article includes the way to read text files line by line in Java. Here, the three different methods are explained with examples. Storing a file in text format is important especially when data from one structured /unstructured form is transferred to another form. Therefore, basic file transfer systems integrate the txt file reading and writing process as their application components. Therefore, how to use text file reading and writing methods is also important for making the parsers. Multiple Approaches The given problem statement is solved in three different approaches − By using the BufferedReader ... Read More

Print Unique Values from a List in Java

AmitDiwan
Updated on 08-Nov-2024 22:30:18

2K+ Views

In this article, we will learn to print unique values from a List in Java. This program will use a loop-based approach to identify and display only the values that appear once, skipping any duplicates. This approach is helpful when working with datasets where you want to remove repeated items and focus on distinct entries. Problem Statement Write a program in Java to print unique values from a list. Below is a demostration of the same − Input 55, 67, 99, 11, 54, 55, 88, 99, 1, 13, 45 Output The distinct elements in the array are 55 67 99 11 ... Read More

Add Period to LocalDate in Java

Nancy Den
Updated on 08-Nov-2024 22:29:57

717 Views

In this program, we will learn to add a specific period to a date using Java’s LocalDate class. By using Java's Period class, we can specify an amount of time (such as months and days) and then add this period to a LocalDate. The program demonstrates how to set a period and apply it to a given date to get a new, updated date. Steps to add Period to LocalDate  Following are the steps to add Period to LocalDate − Import LocalDate and Period from java.time package to work with dates and periods. ... Read More

Java MySQL Connection with IP Address

AmitDiwan
Updated on 08-Nov-2024 22:29:37

996 Views

In this article, we will learn how to connect a Java application to a MySQL database hosted on a specific IP address. By specifying the IP address in the connection URL, we can directly connect to the database even if it’s on a different machine. We’ll use the DriverManager.getConnection() method to initiate the connection. Steps to connect a MySQL database via IP Address Following are the steps to connect a MySQL database via IP Address − Import Connection and DriverManager classes from the java.sql package to enable database connectivity. Create a String ... Read More

DatabaseMetaData supportsGroupBy Method with Example

Rishi Raj
Updated on 08-Nov-2024 22:27:02

162 Views

In this article, we will learn how to check whether a database supports the SQL GROUP BY clause using JDBC in Java. The GROUP BY clause is used to organize identical data into groups in SQL queries, typically following the WHERE clause and preceding the ORDER BY clause. With JDBC, we can determine whether the underlying database supports this clause using the supportsGroupBy() method of the DatabaseMetaData interface. Problem StatementGiven a MySQL database, write a Java program that connects to the database and checks if the database supports the SQL GROUP BY clause.Input Database connection URL, username, and ... Read More

Get Maximum Table Name Length in Java DatabaseMetaData

Smita Kapse
Updated on 08-Nov-2024 22:26:39

153 Views

In this article, we will learn how to use the getMaxTableNameLength() method of the DatabaseMetaData interface in Java. The getMaxTableNameLength() method is used to find the maximum number of characters allowed for a table name in the underlying database. It returns an integer value. If the result is 0, it means there is no limit or the limit is unknown. Problem StatementGiven a database, write a Java program to find out the maximum number of characters allowed for table names in the database using the getMaxTableNameLength() method of the DatabaseMetaData interface.Input A connection to a running database (for example, ... Read More

Java DatabaseMetadata getMaxStatements Method with Example

Smita Kapse
Updated on 08-Nov-2024 22:26:10

173 Views

In this article, we will learn how to retrieve the maximum number of open statements allowed by a database using the DatabaseMetaData interface in Java. The getMaxStatements() method of the DatabaseMetaData interface is used to find out the maximum number of open statements (objects) that the underlying database allows at one time. This method returns an integer value, representing the maximum number of statements that are allowed to be open at a time. If this value is 0 it indicates that there is no limit or, the limit is unknown. Problem StatementGiven a connection to a database, write a ... Read More

Dereferencing a Pointer in C/C++

Samual Sam
Updated on 08-Nov-2024 16:56:54

22K+ Views

Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being pointed, so this is called dereferencing of pointers. int main() {  int a = 7, b ;  int *p; // Un-initialized Pointer  p = &a; // Stores address of a in ptr  b = *p; // Put Value at ptr in b }Here, address in p is basically address of a variable.Complete tutorial on dereferencing: C++ Dereferencing

Align Labels Next to Inputs

Pankaj Kumar Bind
Updated on 08-Nov-2024 13:55:56

4K+ Views

When designing web forms, aligning labels next to input fields can significantly improve readability and usability. This alignment enhances the form's visual structure, making it easier for users to fill out information. In this article, we’ll cover CSS techniques for aligning labels both to the right and left of their respective input fields. Aligning Labels with CSS Properties By using CSS properties like text-align, display, and margin, we can control the position and alignment of labels relative to input fields. In the examples below, we’ll show how to right-align and left-align elements next to input fields within a form. ... Read More

Advertisements