Java Articles

Page 80 of 450

Convert short primitive type to Short object in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 660 Views

Let us first create a short primitive type and assign a value.short val = 30;Now, create a Short object and set the above short type to it.Short myShort = new Short(val);The following is the complete example to convert short primitive type to Short object using Short constructor.Examplepublic class Demo {    public static void main(String []args) {       short val = 30;       Short myShort = new Short(val);       System.out.println(myShort);    } }Output30

Read More

Convert byte primitive type to Byte object in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 1K+ 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.Examplepublic class Demo {    public static void main(String[] args) {       byte b = 100;       Byte res = new Byte(b);       System.out.println(res);    } }Output100

Read More

Java Program to display Bit manipulation in Integer

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 283 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.Examplepublic class Demo {    public static void main(String []args) {       // binary 100100110       int dec = 294;       System.out.println("Count of one bits = " + Integer.bitCount(dec));    } }OutputCount of one bits = 4

Read More

Display default initial values of DataTypes in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 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.Examplepublic 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

Boolean Literals in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 891 Views

The Boolean literals have two values i.e. True and False.The following is an example to display Boolean Literals.Examplepublic class Demo {    public static void main(String[] args) {       System.out.println("Boolean Literals");       boolean one = true;       System.out.println(one);       one = false;       System.out.println(one);    } }OutputBoolean Literals true falseIn the above program, we have declared a boolean value and assigned the boolean literal “true”.boolean one = true;In the same way, we have added another boolean literal “false”.one = false;Both of the above values are displayed, which are the boolean literals.

Read More

Convert Java String Object to Boolean Object

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

A string object can be created in Java using the string literal.String myStr = “Amit”;Another way to create a string object is using the new keyword.String myStr = new String("Hello!");We have used the first method to create a string object.String str = "true";Now, use the valueOf() method to convert String Object to Boolean Object. We have used this method on Boolean object.Boolean bool = Boolean.valueOf(str);Let us now see the complete example to show how to convert String Object to Boolean Object.Examplepublic class Demo {    public static void main(String[] args) {       String str = "true";     ...

Read More

Create a Boolean object from Boolean value in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 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 = new Boolean("false");The following is an example displaying how to create a Boolean object from Boolean value.Examplepublic class Demo {    public static void main(String[] args) {       Boolean bool = new Boolean("true");       System.out.println(bool);       bool = new Boolean("false");       System.out.println(bool);    } }OutputTrue False

Read More

Check two numbers for equality in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 12K+ Views

To check two numbers for equality in Java, we can use the Equals() method as well as the == operator.Firstly, let us set Integers.Integer val1 = new Integer(5); Integer val2 = new Integer(5);Now, to check whether they are equal or not, let us use the == operator.(val1 == val2)Let us now see the complete example.Examplepublic class Demo {    public static void main( String args[] ) {       Integer val1 = new Integer(5);       Integer val2 = new Integer(5);       Integer val3 = new Integer(10);       System.out.println("Integer 1 = "+val1);     ...

Read More

Java Program to convert hexadecimal number to decimal number

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 517 Views

Use the parseInt() method with the second parameter as 16 since it is the radix value. The parseInt() method has the following two forms.static int parseInt(String s) static int parseInt(String s, int radix)To convert hex string to decimal, use the 2nd syntax and add radix as 16, since hexadecimal radix is 16.Integer.parseInt("12", 16)Examplepublic class Demo {    public static void main( String args[] ) {       // converting to decimal       System.out.println(Integer.parseInt("444", 16));    } }Output1092

Read More

Java Program to convert octal number to decimal number

Samual Sam
Samual Sam
Updated on 11-Mar-2026 389 Views

Use the parseInt() method with the second parameter as 8 since it is the radix value. The parseInt() method has the following two forms.static int parseInt(String s) static int parseInt(String s, int radix)To convert octal to decimal, use the 2nd syntax and add radix as 8, since octal radix is 8.Integer.parseInt("25", 8)The following is an example.Examplepublic class Demo {    public static void main( String args[] ) {       // converting to decimal       System.out.println(Integer.parseInt("25", 8));    } }Output21

Read More
Showing 791–800 of 4,498 articles
« Prev 1 78 79 80 81 82 450 Next »
Advertisements