Samual Sam has Published 2492 Articles

Java Program to Parse and Format a Number into Binary

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

266 Views

To parse a number to binary, use the Integer.parseInt() method with binary as the first parameter and radix as 2 passed as a 2nd parameter.Let’s say the following is our integer −int val = 566;Now, use the Integer.parseInt() method −val = Integer.parseInt("11111111", 2);Using the Integer.toString() method will format the above ... Read More

Empty string in not-null column in MySQL?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

3K+ Views

In PHP, the empty string equals to a NULL value, but in MySQL, the case is the different i.e. empty string is not equal to NULL value. To understand the above syntax, let us create a column with NOT NULL constraint while you can insert an empty string.Let us create ... Read More

Format date with DateFormat.LONG in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

1K+ Views

DateFormat.LONG is a constant for long style pattern.Firstly, we will create date object −Date dt = new Date(); DateFormat dateFormat;Let us format date for different locale with DateFormat.LONG −// ITALY dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.ITALY); // CANADA dateFormat = DateFormat.getDateInstance(DateFormat. LONG, Locale.CANADA);The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; ... Read More

Formatting day of week in EEEE format in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

2K+ Views

EEEEE format is used in Java Date to format day of week like Monday, Tuesday, Wednesday, etc. Let us use it −// displaying day of week SimpleDateFormat simpleformat = new SimpleDateFormat("EEEE"); String strDayofWeek = simpleformat.format(new Date()); System.out.println("Day of Week = "+strDayofWeek);Above, we have used the SimpleDateFormat class, therefore the following ... Read More

Search for text between delimiters in MySQL?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

412 Views

You need to use LOCATE() along with SUBSTR(). The below syntax will find the word after delimiter. Here, delimiter is colon(:), you can use another i.e. it is up to you. The syntax is as follows −SELECT SUBSTR(yourColumnName, LOCATE(':', yourColumnName)+1, ... Read More

Apply modulus operator to floating-point values in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

555 Views

To apply modulus (%) operator to floating-point values in an effortless task. Let us see how.We have the following two values −double one = 9.7; double two = 1.2;Let us now apply the modulus operator −one % twoThe following is the complete example that displays the output as well −Example Live ... Read More

Java program to print the initials of a name with last name in full

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

8K+ Views

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 ... Read More

Formatting day in dd format in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

406 Views

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 ... Read More

Display hour in hh (01-12 in AM/PM) format in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

263 Views

The “hh” format in Java Date is like 01 – 12 hour in AM/ PM. Use SimpleDateFormat("hh") to get the same format;// displaying hour in hh format SimpleDateFormat simpleformat = new SimpleDateFormat("hh"); String strHour2 = simpleformat.format(new Date()); System.out.println("Hour in hh format = "+strHour2);Above, we have used the SimpleDateFormat class, therefore ... Read More

MySQL Query to get count of unique values?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

382 Views

To count the unique values on a column, you need to use keyword DISTINCT. To understand how it is done, let us create a table. The query to create a table is as follows −mysql> create table UniqueCountByIPAddress    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> ... Read More

Advertisements