Karthikeya Boyini has Published 2193 Articles

Create a Boolean object from Boolean value in Java

karthikeya Boyini

karthikeya Boyini

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

3K+ Views

To create a Boolean object from Boolean value is quite easy. Create an object with Boolean and set the Boolean value “true” or “false”, which are the Boolean literals.Let us now see how “true” value is added.Boolean bool = new Boolean("true");In the same way, “False” value is added.Boolean bool = ... Read More

Java Program to convert Boolean to String

karthikeya Boyini

karthikeya Boyini

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

11K+ Views

To convert Boolean to String in Java, use the toString() method. For this, firstly, we have declared two booleans.boolean bool1 = false; boolean bool2 = true;Now, convert Boolean to String using the toString() method in Java as shown below −String str1 = new Boolean(bool1).toString(); String str2 = new Boolean(bool2).toString();Now, when ... Read More

Convert Short to numeric primitive data types in Java

karthikeya Boyini

karthikeya Boyini

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

343 Views

To convert Short to numeric primitive data types, use the following methods −byteValue() shortValue() intValue() longValue() floatValue()Firstly, let us declare a Short.Short shortObj = new Short("40");Now, let us see how to convert it to long type, for a simple example.long val5 = shortObj.longValue(); System.out.println("Long: "+val5);In the same way, you can ... Read More

Java Program to display Bit manipulation in Integer

karthikeya Boyini

karthikeya Boyini

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

238 Views

Let’s say we have the following decimal number, which is binary 100100110.int dec = 294;To perform bit manipulation, let us count the number of 1 bits in it. We have used bitCount() method for this purpose.Integer.bitCount(dec);The following is an example to display bit manipulation in given Integer.Example Live Demopublic class Demo ... Read More

Integer.numberOfLeadingZeros() method in Java

karthikeya Boyini

karthikeya Boyini

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

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

Display the limits of DataTypes in Java

karthikeya Boyini

karthikeya Boyini

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

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

Check whether the entered value is a digit or not in Java

karthikeya Boyini

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

Adding a column that doesn't exist in a query?

karthikeya Boyini

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

Java Program to convert byte[] array to String

karthikeya Boyini

karthikeya Boyini

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

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

Convert Byte to numeric primitive data types in Java

karthikeya Boyini

karthikeya Boyini

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

420 Views

To convert Byte to numeric primitive data types, use the following methods −byteValue() shortValue() intValue() longValue() floatValue()Firstly, let us declare a Byte.Byte byteVal = new Byte("35");Now, let us see how to convert it to long type, for a simple example.long longVal = byteVal.longValue(); System.out.println(longVal);In the same way, you can convert ... Read More

Advertisements