Samual Sam has Published 2310 Articles

Convert byte primitive type to Byte object in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:33:57

994 Views

To convert byte primitive type to Byte object, use the Byte constructor.Here is our byte primitive type.byte b = 100;Now let us convert it to Byte object.Byte res = new Byte(b);Let us see the complete example.Example Live Demopublic class Demo {    public static void main(String[] args) {       ... Read More

How to combine date and time from different MySQL columns to compare with the entire DateTime?

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:31:06

1K+ Views

You can combine date and time from different MySQL columns to compare with the entire date time with the help of CONCAT() function. The syntax is as follows −SELECT *FROM yourTableName WHERE CONCAT(yourDateColumnName, '', yourTimeColumnName) > 'yourDateTimeValue';To understand the above syntax, let us create a table. The query to create ... Read More

Fetch rows where a field value is less than 5 chars in MySQL?

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:29:35

730 Views

To fetch rows where a field value is less than 5 chars, you need to use LENGTH() function. The syntax is as follows −SELECT *FROM yourTableName WHERE LENGTH(yourColumnName) < 5;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create ... Read More

Integer.numberOfTrailingZeros() method in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:28:15

148 Views

The Integer.numberOfTrailingZeros() method returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified int value.We have the following decimal as an example.int dec = 199;Calculated binary using Integer.toBinaryString() as shown below −Integer.toBinaryString(dec);Now let us see the implementation of Integer.numberOfTrailingZeros() method.Example Live ... Read More

MySQL query to include more than one column in a table that doesn't already exist

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:28:03

138 Views

You can easily add more than one column that does not exist in a query using multiple AS keywords.Let us first create a table. The query to create a table is as follows −mysql> create table ColumnDoesNotExists    -> (    -> UserId int,    -> UserName varchar(20)    -> ... Read More

Display default initial values of DataTypes in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:27:05

2K+ Views

To display default initial values of a datatype, you need to just declare a variable of the same datatype and display it.The following is a Java program to display initial values of DataTypes.Example Live Demopublic class Demo {    boolean t;    byte b;    short s;    int i;   ... Read More

Convert Hex String to byte Array in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:25:38

13K+ Views

To convert hex string to byte array, you need to first get the length of the given string and include it while creating a new byte array.byte[] val = new byte[str.length() / 2];Now, take a for loop until the length of the byte array.for (int i = 0; i < ... Read More

Java Program to convert String to byte array

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:24:35

454 Views

Here is our string.String str = "Asia is a continent!";Now let us use a byte array and the getBytes() method to fulfill our purpose.byte[] byteVal = str.getBytes();Now, if we will get the length of the array, it would return the length as shown in the complete example below −Example Live Demopublic ... Read More

How to select first and last data row from a MySQL result?

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:23:45

2K+ Views

You can select the first and last data row using MIN() and MAX(). The syntax is as follows −SELECT * FROM yourTableName WHERE yourColumnName = (SELECT MIN(yourColumnName) FROM yourTableName) UNION SELECT * FROM yourTableName WHERE yourColumnName = (SELECT MAX(yourColumnName) FROM yourTableName) ;To understand the above syntax, let us create a ... Read More

Java Program to compare Two Java short Arrays

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:23:36

211 Views

To compare two Java short arrays, use the Arrays.equals() method.Let us first declare and initialize some short arrays.short[] arr1 = new short[] { 20, 15, 35, 55, 69 }; short[] arr2 = new short[] { 20, 15, 35, 55, 69 }; short[] arr3 = new short[] { 22, 19, 30, ... Read More

Advertisements