- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 4338 Articles for Java 8
569 Views
To convert octal to decimal number, use the Integer.parseInt() method with radix 8. Here, the radix is for Octal i.e. 8.Let’s say we have the following octal string.String myOctal = "25";To convert it to decimal, use the Integer.parseInt() method.int val = Integer.parseInt(myOctal, 8);The following is the complete example.Example Live Demopublic class Demo { public static void main(String []args) { String myOctal = "25"; System.out.println("Octal = "+myOctal); int val = Integer.parseInt(myOctal, 8); System.out.println("Decimal = "+val); } }OutputOctal = 25 Decimal = 21
399 Views
The method Integer.decode() decodes a string to an integer. It returns an Integer object holding the int value represented by the passed string value.Note − It accepts decimal, hexadecimal, and octal number.Let’s say the following is our string.String val = "2";The following is how you can decode the string to integer.Integer myInt = Integer.decode(val);Example Live Demopublic class Demo { public static void main(String []args) { String val = "2"; Integer myInt = Integer.decode(val); System.out.println("Integer = " + myInt); } }OutputInteger = 2
201 Views
To convert String to long, the following are the two methods.Method 1The following is an example wherein we use parseLong() method.Example Live Demopublic class Demo { public static void main(String[] args) { String myStr = "5"; Long myLong = Long.parseLong(myStr); System.out.println("Long: "+myLong); } }OutputLong: 5Method 2The following is an example wherein we have used valueOf() and longValue() method to convert String to long.Example Live Demopublic class Demo { public static void main(String[] args) { String myStr = "20"; long res = Long.valueOf(myStr).longValue(); System.out.println("Long: "+res); } }OutputLong: 20
1K+ Views
To check for Long overflow, we need to check the Long.MAX_VALUE with the multiplied long result, Here, Long.MAX_VALUE is the maximum value of Long type in Java.Let us see an example wherein long values are multiplied and if the result is more than the Long.MAX_VALUE, then an exception is thrown.The following is an example showing how to check for Long overflow.Example Live Demopublic class Demo { public static void main(String[] args) { long val1 = 6999; long val2 = 67849; System.out.println("Value1: "+val1); System.out.println("Value2: "+val2); long ... Read More
581 Views
To check for Long overflow, we need to check the Long.MAX_VALUE with the added long result. Here, Long.MAX_VALUE is the maximum value of Long type in Java.Let us see an example wherein long integers are added and if the result is more than the Long.MAX_VALUE, then an exception is thrown.The following is an example showing how to check for Long overflow.Example Live Demopublic class Demo { public static void main(String[] args) { long val1 = 80989; long val2 = 87567; System.out.println("Value1: "+val1); System.out.println("Value2: "+val2); long ... Read More
302 Views
To check whether the character is ASCII 7 bit or not, check whether given value’s ASCII value is less than 128 or not.Here, we have a character.char one = '-';Now, we have checked a condition with if-else for ASCII 7-bit character.if (c < 128) { System.out.println("Given value is ASCII 7 bit!"); } else { System.out.println("Given value is not an ASCII 7 bit!"); }The following is an example wherein we check a character for ASCII 7-bit.Example Live Demopublic class Demo { public static void main(String []args) { char c = '-'; System.out.println("Given value = ... Read More
219 Views
To check whether the entered value is ASCII 7-bit control character, check the characters ASCII value before 32 and 127. These are the control characters.Here, we have a character.char one = ' n ';Now, we have checked a condition with if-else to check for character less than 32 (ASCII) and equal to 127.if (one < 32 || one == 127) { System.out.println("Given value is a control character!"); } else { System.out.println("Given value is not a control character!"); }Example Live Demopublic class Demo { public static void main(String []args) { char one = ''; ... Read More
93 Views
To check whether the entered value is ASCII 7-bit alphabetic, check the character from ‘a’ to ‘z’ or ‘A’ to ‘Z’.Here, we have a character.char one = 'r';Now, we have checked a condition with if-else to check for character from ‘a’ to ‘z’ or ‘A’ to ‘Z’.if ((one >= 'A' && one = 'a' && one = 'A' && one = 'a' && one = 'A' && one = 'a' && one
55 Views
To check whether the entered value is ASCII 7-bit alphabetic uppercase, check the character from ‘A’ to ‘Z’.Here, we have a character.char one = 'T';Now, we have checked a condition with if-else to check for uppercase character from ‘A’ to ‘Z’if (one >= 'A' && one = 'A' && one = 'A' && one
119 Views
To check whether the entered value is ASCII 7-bit alphabetic lowercase, check the character from ‘a’ to ‘z’.Here, we have a character.char one = 'm';Now, we have checked a condition with if-else to check for lowercase character from ‘a’ to ‘z’if (one >= 'a' && one = 'a' && one = 'a' && one