Integer numberOfLeadingZeros Method in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:28:42

146 Views

This Integer.numberOfLeadingZeros() method in Java returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value.We have the following decimal as an example.int dec = 294;Calculated binary using Integer.toBinaryString() as shown below −Integer.toBinaryString(dec);Now let us see the implementation of Integer.numberOfLeadingZeros() method.Example Live Demopublic class Demo {    public static void main(String []args) {       int dec = 294;       System.out.println("Decimal = " + dec);       System.out.println("Binary = " + Integer.toBinaryString(dec));       System.out.println("Count of one bits = " + Integer.bitCount(dec));       ... Read More

Integer numberOfTrailingZeros Method in Java

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

155 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 Demopublic class Demo {    public static void main(String []args) {       int dec = 199;       System.out.println("Binary = " + Integer.toBinaryString(dec));       System.out.println("Count of one bits = " + Integer.bitCount(dec));       System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(dec));    } ... Read More

Include Multiple Columns in MySQL Table

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

141 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)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ColumnDoesNotExists(UserId, UserName) values(100, 'Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into ColumnDoesNotExists(UserId, UserName) values(101, 'Sam'); Query OK, 1 row affected (0.22 sec) mysql> ... Read More

Display the Limits of DataTypes in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:27:50

695 Views

Every data type in Java has a minimum as well as maximum range, for example, for Integer.Minimum = -2147483648 Maximum = 2147483647Let’s say for Integer, if the value extends the maximum range display above, it leads to Overflow. However, if the value is less than the minimum range displayed above, it leads to Underflow.The following program displays the limits on datatypes in Java.Example Live Demopublic class Demo {    public static void main(String[] args) {       System.out.println("Limits of primitive DataTypes");       System.out.println("Byte Datatype values...");       System.out.println("Min = " + Byte.MIN_VALUE);       System.out.println("Max = ... Read More

Display Default Initial Values of DataTypes in Java

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;    long l;    float f;    double d;    void Display() {       System.out.println("boolean (Initial Value) = " + t);       System.out.println("byte (Initial Value) = " + b);       System.out.println("short (Initial Value) = " + s);       System.out.println("int (Initial Value) = " ... Read More

Check if Entered Value is a Digit in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:26:16

3K+ Views

To check whether the entered value is a digit or not in Java, use the Character.isDigit() method.We have a character to be checked.char val = '5';Now let us use the Character.isDigit() method.if (Character.isDigit(val)) {    System.out.println("Character is a digit!"); } else {    System.out.println("Character is not a digit!"); }Let us see the complete example now to check for Uppercase in Java.Example Live Demopublic class Demo {    public static void main(String []args) {       System.out.println("Checking for digit...");       char val = '5';       System.out.println("Value: "+val);       if (Character.isDigit(val)) {         ... Read More

Add a Column That Doesn't Exist in a Query

karthikeya Boyini
Updated on 26-Jun-2020 10:26:12

1K+ Views

Add a column that does not exist in a query, with the help of AS keyword. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ....N, yourValue AS yourColumnName, ....N' FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ColumnDoesNotExists     -> (     -> UserId int,     -> UserName varchar(20)     -> ); Query OK, 0 rows affected (0.67 sec)ExampleInsert some records in the table using insert command. The query is as follows −mysql> insert into ColumnDoesNotExists(UserId, UserName) values(100, 'Larry'); Query OK, ... Read More

Convert Hex String to Byte Array in Java

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 < val.length; i++) {    int index = i * 2;    int j = Integer.parseInt(str.substring(index, index + 2), 16);    val[i] = (byte) j; }Let us see the complete example.Example Live Demopublic class Demo {    public static void main(String args[]) {       String str = "p";     ... Read More

Convert Byte Array to String in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:25:04

1K+ Views

To convert byte[] to String, firstly let us declare and initialize a byte array.// byte array byte[] arr = new byte[] {78, 79, 33};Now take a String and include the array in it.String str = new String(arr);Let us see the complete example to convert byte array to String.Example Live Demopublic class Demo {    public static void main(String args[]) {       // byte array       byte[] arr = new byte[] {78, 79, 33};       String str = new String(arr);       // string       System.out.println("String = "+str);    } }OutputString = NO!

How a Refrigerator Keeps the Temperature Cool Inside

Shanmukh Pasumarthy
Updated on 26-Jun-2020 10:24:39

548 Views

In ancient times the food was preserved by conventional techniques like salting and pickling which were not helpful all the time. These days refrigerators are utilized to protect food for long periods by cooling it.This cooling procedure keeps bacteria away from attacking and ruining the food, which thus lessens food wastage. The refrigerator is one innovation that has positively changed the way we live. It has made it feasible for everybody to store or preserve food for long periods of time.A Refrigerator functions on 2 basic principles:As a fluid dissipates, it absorbs the warmth from the surrounding ranges.The inverse happens ... Read More

Advertisements