
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

11K+ 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.Example Live Demopublic 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

10K+ Views
The Equals() method compares this object to the specified object. The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.Let us first set Integer object.Integer val1 = new Integer(30); Integer val2 = new Integer(60); Integer val3 = new Integer(55); Integer val4 = new Integer(30);Now let us check their equality using the Equals() method.val1.equals(val2);In the same way, check it for different Integers.Let us see the complete example.Example Live Demoimport java.util.Random; public class Demo { public static void main( String args[] ) { ... Read More

3K+ Views
To generate random numbers in Java, use.import java.util.Random;Now, take Random class and create an object.Random num = new Random();Now, in a loop, use the nextInt() method since it is used to get the next random integer value. You can also set a range, like for 0 to 20, write it as.nextInt( 20 );Let us see the complete example wherein the range is 1 to 10.Example Live Demoimport java.util.Random; public class Demo { public static void main( String args[] ) { Random num = new Random(); int res; for ( int i = 1; i

20K+ Views
To read integers from console, use Scanner class.Scanner myInput = new Scanner( System.in );Allow a use to add an integer using the nextInt() method.System.out.print( "Enter first integer: " ); int a = myInput.nextInt();In the same way, take another input in a new variable.System.out.print( "Enter second integer: " ); Int b = myInput.nextInt();Let us see the complete example.Exampleimport java.util.Scanner; public class Demo { public static void main( String args[] ) { Scanner myInput = new Scanner( System.in ); int a; int b; int sum; System.out.print( ... Read More

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 you will display the values “str1” and “str2”, the output would be in String.Let us now see the complete example to convert Boolean to String.Example Live Demopublic class Demo { public static void main(String[] args) { boolean bool1 = false; boolean bool2 = true; ... Read More

16K+ Views
To convert String to Boolean, use the parseBoolean() method in Java. The parseBoolean() parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".Firstly, declare a string.String str = "false";Now, use the Boolean.parseBoolean() method to convert the above declared String to Boolean.boolean bool = Boolean.parseBoolean(str);Let us now see the complete example to learn how to convert String to Boolean.Example: Convert String to Boolean Live Demopublic class Demo { public static void main(String[] args) { // string ... Read More

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.Example Live Demopublic 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); ... Read More

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.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "true"; ... Read More

4K+ Views
To convert Boolean Primitive to Boolean object, use the valueOf() method in Java.Firstly, let us take a boolean primitive.boolean val = false;To convert it into an object, use the valueOf() method and set the argument as the boolean primitive.Boolean res = Boolean.valueOf(val);Let us see the complete example to learn how to convert Boolean Primitive to Boolean object.Example Live Demopublic class Demo { public static void main(String[] args) { boolean val = false; // converting to object Boolean res = Boolean.valueOf(val); System.out.println(res); } }OutputFalse

109 Views
The method returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value. Let us now see the syntax.int reverseBytes(int i)The following is the parameter.i − This is the int valueExample Live Demopublic class Demo { public static void main(String []args) { System.out.println(Integer.reverseBytes(0)); System.out.println(Integer.reverseBytes(-87)); System.out.println(Integer.reverseBytes(98)); } }Output0 -1442840577 1644167168