Karthikeya Boyini has Published 2383 Articles

Integer.lowestOneBit() method in Java

karthikeya Boyini

karthikeya Boyini

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

72 Views

The method Integer.lowestOneBit() returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value.Here we have a decimal value 294, whose binary is −100100110The lowest one bit is calculated using the lowestOneBit() method in Java.Example Live Demopublic class Demo ... Read More

Java Program to multiply integers and check for overflow

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:14:54

759 Views

To check for Integer overflow, we need to check the Integer.MAX_VALUE with the multiplied integers result, Here, Integer.MAX_VALUE is the maximum value of an integer in Java.Let us see an example wherein integers are multiplied and if the result is more than the Integer.MAX_VALUE, then an exception is thrown.The following ... Read More

Convert byte Array to Hex String in Java

karthikeya Boyini

karthikeya Boyini

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

925 Views

The following is our byte array.byte[] b = new byte[]{'p', 'q', 'r'};We have created a custom method “display” here and passed the byte array value. The same method converts byte array to hex string.public static String display(byte[] b1) {    StringBuilder strBuilder = new StringBuilder();    for(byte val : b1) ... Read More

Check if a table is empty or not in MySQL using EXISTS

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

The following is the syntax to check whether a table is empty or not using MySQL EXISTS −SELECT EXISTS(SELECT 1 FROM yourTableName);ExampleFirst, let us create a table. The query to create a table is as follows −mysql> create table ReturnDemo    -> (    -> Id int,    -> Name ... Read More

Java Program to convert integer to boolean

karthikeya Boyini

karthikeya Boyini

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

10K+ Views

To convert integer to boolean, firstly let us initialize an integer.int val = 100;Now we will declare a variable with primitive boolean. While declaration, we will initialize it with the val value comparing it with an integer using the == operator. If the value matches, the value “True” is returned, ... Read More

Java Program to perform an XOR on a set of Booleans

karthikeya Boyini

karthikeya Boyini

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

132 Views

To perform XOR on a set of Booleans, firstly let us consider the following Boolean array.boolean[] arr = { true, true, false };Let us now create a nested loop and within that perform XOR operation.for (boolean one : arr) {    for (boolean two: arr) {       // ... Read More

Java Program to check for Integer overflow

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:09:42

5K+ Views

To check for Integer overflow, we need to check the Integer.MAX_VALUE, which is the maximum value of an integer in Java.Let us see an example wherein integers are added and if the sum is more than the Integer.MAX_VALUE, then an exception is thrown.Example Live Demopublic class Demo {    public static ... Read More

Display the maximum of three integer values in Java

karthikeya Boyini

karthikeya Boyini

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

161 Views

The following is an example displaying the maximum of three integer values.Example Live Demopublic class Demo {    public static void main(String[] args) {       int val1 = 10;       int val2 = 20;       int val3 = 30;       System.out.println("Number 1 = ... Read More

Display the minimum and maximum value of primitive data types in Java

karthikeya Boyini

karthikeya Boyini

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

3K+ Views

Every data type in Java has a minimum as well as maximum range, for example, for Float.Min = 1.4E-45 Max = 3.4028235E38Let’s say for Float, if the value extends the maximum range displayed above, it leads to Overflow.However, if the value is less than the minimum range displayed above, it ... Read More

Boolean Type in Java

karthikeya Boyini

karthikeya Boyini

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

13K+ Views

To display Boolean type, firstly take two variables and declare them as boolean.boolean val1, val2;Then one by one assign values to both of them, one of them is shown below −val1 = true;Now, use if statement to check and display the Boolean true value.if(val1) System.out.println("This is true and will get ... Read More

Advertisements