The java.util.regex.Pattern.matches() method matches the regular expression and the given input. It has two parameters i.e. the regex and the input. It returns true if the regex and the input match and false otherwise.A program that demonstrates the method Pattern.matches() in Java regular expressions is given as follows:Example Live Demoimport java.util.regex.Pattern; public class Demo { public static void main(String args[]) { String regex = "a*b"; String input = "aaab"; System.out.println("Regex: " + regex); System.out.println("Input: " + input); boolean match = Pattern.matches(regex, input); ... Read More
When the full name is provided, the initials of the name are printed with the last name is printed in full. An example of this is given as follows −Full name = Amy Thomas Initials with surname is = A. ThomasA program that demonstrates this is given as follows −Example Live Demoimport java.util.*; public class Example { public static void main(String[] args) { String name = "John Matthew Adams"; System.out.println("The full name is: " + name); System.out.print("Initials with surname is: "); int len = name.length(); ... Read More
The dd format in Java Date is like 05, 06, 07, 08, 09, etc. i.e. with two-letter digit. Let us use it.// displaying day in dd format SimpleDateFormat simpleformat = new SimpleDateFormat("dd"); String strDay = simpleformat.format(new Date()); System.out.println("Day in dd format = "+strDay);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More
You can count multiple COUNT() for multiple conditions in a single query using GROUP BY.The syntax is as follows -SELECT yourColumnName, COUNT(*) from yourTableName group by yourColumnName;To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table MultipleCountDemo -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (2.17 sec)Insert records in the table using insert command. The query is as follows.mysql> insert into MultipleCountDemo values(1, 'Carol', 21); Query OK, 1 row affected (0.27 sec) mysql> insert into MultipleCountDemo values(2, ... Read More
Select non-empty column values using NOT IS NULL and TRIM() function. The syntax is as follows.SELECT * FROM yourTableName WHERE yourColumnName IS NOT NULL AND TRIM(yourColumnName) ' ';You can select non-empty value as well as whitespace from column using the same TRIM() function.To understand the syntax we discussed above, let us create a table. The query to create a table is as follows −mysql> create table SelectNonEmptyValues -> ( -> Id int not null auto_increment, -> Name varchar(30), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.62 sec)Insert records in the table ... Read More
Literary Devices are the peculiar structures used by writers in their works in order to convey their messages in a simple manner to the readers.The various literary devices used in English Literature areAlliteration, Analogy, Allegory, Anaphora, Metaphor, Simile, Aphorism, Oxymoron, Onomatopoeia, Eulogy, Elegy, and others.Alliteration: It is the device in which a number of words, having the same first consonant sound, occur close together in a series.Example- He had a haunting hat.Analogy: It is the comparison of an idea or a thing with another. Metaphors and similes are used to draw analogies. A metaphor is an implied comparison while a ... Read More
The Email address can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the E-mail and the given input Email and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo { static boolean isValid(String email) { String regex = "^[\w-_\.+]*[\w-_\.]\@([\w]+\.)+[\w]+[\w]$"; return email.matches(regex); } public static void main(String[] args) { String email = "john123@gmail.com"; System.out.println("The E-mail ID is: " + email); System.out.println("Is the above E-mail ID valid? " + ... Read More
You can sort the table_name property from INFORMATION_SCHEMA.TABLES with ORDER BY clause. Sort in ascending order or descending order with the help of ASC or DESC respectively. The syntax is as follows −SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema='yourDatabaseName' ORDER BY table_name DESC;Use the database with the name sample and have some tables. First, we will show all tables after that we will apply to sort on the table name. The query to display all tables is as follows −mysql> show tables;The following is the output −+--------------------------+ | Tables_in_sample | +--------------------------+ | ... Read More
To update data into a MySQL database table, use UPDATE command. The syntax is as follows −update yourTableName set yourColumnName1 = value1, ....N where condition;First, we need to create a table. The query is as follows −mysql> create table UpdateDemo -> ( -> id int, -> Name varchar(200) -> ); Query OK, 0 rows affected (0.67 sec)Let us insert records into the table. The following is the query −mysql> insert into UpdateDemo values(101, 'John'); Query OK, 1 row affected (0.19 sec) mysql> truncate table UpdateDemo; Query OK, 0 rows affected (0.86 sec) mysql> insert ... Read More
Water is a very important resource not only for us but also for our future generations. We should; therefore, save it in order to provide the maximum benefit to others. Water is necessary for our lives. So, if we save water, we save life.However, one must either not be aware of the ways to conserve it or may be reluctant thinking that such work will require a lot of toil. Let's talk about the ways in which water can be conserved.Turn off the Tap Post Use: While we brush our teeth, water keeps spilling out. It is necessary to close ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP