Samual Sam has Published 2492 Articles

Integer.numberOfTrailingZeros() method in Java

Samual Sam

Samual Sam

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

93 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

67 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

11K+ 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

314 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

125 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

Convert Short into String in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:22:46

144 Views

Using toString() method to convert Short to string. Firstly, let us take a short primitive datatype and initialize a short value.short myShort = 55;Now let us include this value to the following Short object.Short s = new Short(myShort);Convert the above given Short to string using the toString() method as shown ... Read More

Java Program to convert String to short primitive

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:21:58

225 Views

Use the parseShort() method to convert String to short primitive. It parses the string argument as a signed short.Firstly, we have set a string.String str = "99";Now, we have taken a short primitive and included the string value.short val = Short.parseShort(str);The following is an example to convert String to short ... Read More

Java Program to compare two Byte Arrays

Samual Sam

Samual Sam

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

229 Views

To compare two Byte Arrays, use the Arrays.equals() method. Here we have declared and initialized a total of 4 arrays.byte[] arr1 = new byte[] { 11, 13, 30, 45, 77, 89 }; byte[] arr2 = new byte[] { 12, 13, 34, 87, 99, 33}; byte[] arr3 = new byte[] { ... Read More

Advertisements