
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

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 Demo { public static void main(String args[]) { // byte array byte[] arr = new byte[] {78, 79, 33}; String str = new String(arr); // string System.out.println("String = "+str); } }OutputString = NO!

13K+ Views
To convert hex string to byte array, you need to first get the length of the given string and include it while creating a new byte array.byte[] val = new byte[str.length() / 2];Now, take a for loop until the length of the byte array.for (int i = 0; i < val.length; i++) { int index = i * 2; int j = Integer.parseInt(str.substring(index, index + 2), 16); val[i] = (byte) j; }Let us see the complete example.Example Live Demopublic class Demo { public static void main(String args[]) { String str = "p"; ... Read More

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 see the complete example now to check for Uppercase in Java.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking for digit..."); char val = '5'; System.out.println("Value: "+val); if (Character.isDigit(val)) { ... Read More

11K+ Views
To check whether a character is in Lowercase or not in Java, use the Character.isLowerCase() method.We have a character to be checked.char val = 'q';Now let us use the Character.isLowerCase() method.if (Character.isLowerCase(val)) { System.out.println("Character is in Lowercase!"); }else { System.out.println("Character is in Uppercase!"); }Let us see the complete example now to check for Lowercase in Java.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking for Lowercase character..."); char val = 'q'; System.out.println("Character: "+val); if (Character.isLowerCase(val)) { System.out.println("Character is ... Read More

2K+ Views
In Java, Converting a byte array to a hex string means transforming each byte into its hexadecimal representation. byte array: A byte array is a collection of byte values. Each byte is an 8-bit unit of data. Hex String: A hexadecimal (hex) string represents a number in base-16, using digits 0-9 and letters A-F. We represent the A-F in numbers as 10 to 15. The following is our byte array as given below − byte[] b = new byte[]{'p', 'q', 'r'}; We have created a custom method "display" that ... Read More

950 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 is an example showing how to check for Integer overflow.Example Live Demopublic class Demo { public static void main(String[] args) { int val1 = 9898; int val2 = 6784; System.out.println("Value1: "+val1); System.out.println("Value2: "+val2); long mul ... Read More

868 Views
In this article, we will learn to convert a binary number into a decimal number in Java.Binary numbers are fundamental in computer science and digital electronics, where data is represented in a base-2 numeral system consisting of only 0s and 1s. Converting binary numbers to their decimal equivalents is a common task. Problem Statement The task is to convert a binary number into its decimal equivalent using Java. − Input 1110 Output 14 Different Approaches Following are the two different approaches to converting a binary number into a decimal number in Java − Using ... Read More

111 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 { public static void main(String []args) { // binary 100100110 int dec = 294; System.out.println("Count of one bits = " + Integer.bitCount(dec)); System.out.println("Lowest one bit: " + Integer.lowestOneBit(dec)); } }OutputCount of one bits = 4 Lowest one bit: 2

1K+ Views
To convert a byte to hexadecimal equivalent, use the toHexString() method in Java.Firstly, let us take a byte value.byte val1 = (byte)90;Before using the method, let us do some more manipulations. Mask the byte value now:int res = val1 & 0xFF;Let us now see the complete example and use the toHexString() method to convert a byte to hexadecimal equivalent.Example Live Demopublic class Demo { public static void main(String[] args) { byte val1 = (byte)90; System.out.println("Byte = "+val1); int res = val1 & 0xFF; System.out.println("Hexadecimal = "+Integer.toHexString(res)); } }OutputByte = 90 Hexadecimal = 5a

293 Views
Firstly, let us declare byte values.byte val1 = 127; byte val2 = -128;To convert the above given unsigned byte, you can use the following. Here, we are first implementing it for the variable “val1”.(int) val1 & 0xFFNow for the second variable “val2”.(int) val2 & 0xFFLet us see the complete example to convert an UNSIGNED bye to a JAVA type.Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { byte val1 = 127; byte val2 = -128; System.out.println(val1); System.out.println((int) val1 & 0xFF); System.out.println(val2); System.out.println((int) val2 & 0xFF); } }Output127 127 -128 128