Object Oriented Programming Articles

Page 264 of 589

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 496 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 372 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

Java Program to convert decimal integer to hexadecimal number

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

Use the toHexString() method to convert decimal to hexadecimal. The method returns a string representation of the integer argument as an unsigned integer in base 16. The following characters are used as hexadecimal digits:0123456789abcdef.The following is the syntax.String toHexString(int i)It has only single parameter.i − This is an integer to be converted to a string.Examplepublic class Demo {    public static void main( String args[] ) {       int dec = 45;       System.out.println("Decimal = "+dec);       // converting to hex       System.out.println(Integer.toHexString(dec));    } }OutputDecimal = 45 2d

Read More

How to convert Decimal to Hexadecimal in Java

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

To convert decimal to hexadecimal, use any of the two methods i.e.Integer.toHexString() − It returns a string representation of the integer argument as an unsigned integer in base 16.Integer.parseInt() − It allows you to set the radix as well, for example, for hexadecimal set it as 16.Let us see an example now to convert decimal to hexadecimal using Integer.toHexString() method.Examplepublic class Demo {    public static void main( String args[] ) {       int dec = 158;       System.out.println(Integer.toHexString(dec));    } }Output9eLet us see an example now to convert decimal to hexadecimal using Integer.parseInt() method.Examplepublic class ...

Read More

Parse and format a number to decimal in Java

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

To parse and format a number to decimal, try the following code.Examplepublic class Demo {    public static void main( String args[] ) {       int val = Integer.parseInt("5");       String str = Integer.toString(val);       System.out.println(str);    } }Output5In the above program, we have used the Integer.parseInt() and Integer.toString() method to convert a number to decimal.int val = Integer.parseInt("5"); String str = Integer.toString(val);The toString() method above represents a value in string and formats.

Read More

Parse and format to hexadecimal in Java

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

To parse and format to hexadecimal in Java, we have used the BigInteger class. The java.math.BigInteger class provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math.In the below example, we have taken BigInteger and created an object. With that, some values have been set by us in the arguments as the hexadecimal and the radix i.e. 16 for hexadecimal.BigInteger bi = new BigInteger("2ef", 16);Let us see an example.Exampleimport java.math.*; public class Demo {    public static void main( String args[] ) {       BigInteger bi = new BigInteger("2ef", 16);   ...

Read More

Pass an integer by reference in Java

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

To pass an integer by reference in Java, try the following code −Examplepublic class Demo {    public static void display(int[] arr) {       arr[0] = arr[0] + 50;;    }    public static void main(String[] args) {       int val = 50;       int[] myArr = { val };       display(myArr);       System.out.println(myArr[0]);    } }Output100In the above program, a custom method is created, which pass an int array.int val = 50; int[] myArr = { val }; display(myArr);In the method, we have performed mathematical operation on the value of array.public static void display(int[] arr) {    arr[0] = arr[0] + 50;; }The updated value is then displayed in the main.System.out.println(myArr[0]);

Read More

Reverse an Integer in Java

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

To reverse an integer in Java, try the following code −Exampleimport java.lang.*; public class Demo {    public static void main(String[] args) {       int i = 239, rev = 0;       System.out.println("Original: " + i);       while(i != 0) {          int digit = i % 10;          rev = rev * 10 + digit;          i /= 10;       }       System.out.println("Reversed: " + rev);    } }OutputOriginal: 239 Reversed: 932In the above program, we have the following int value, which we will reverse.int i = 239;Now, loop through until the value is 0. Find the remainder and perform the following operations to get the reverse of the given integer 239.while(i != 0) {    int digit = i % 10;    rev = rev * 10 + digit;    i /= 10; }

Read More
Showing 2631–2640 of 5,881 articles
« Prev 1 262 263 264 265 266 589 Next »
Advertisements