Java : How to Convert Integer to Binary

In Java, we can use Integer.toBinaryString(int) to convert an Integer to a binary string representative. This article will show you two methods to convert an Integer to a binary string representative. JDK Integer.toBinaryString. Old school bit masking technique. 1. Convert Int to Binary Integer.toBinaryString 1.1 This Java example tries to convert an int to a binary string […]

En Lire Plus

Java : How to Convert Character to ASCII

In Java, we can cast the char to int to get the ASCII value of the char. The explicit cast (int)char is optional, if we assign a char to an integer, Java will auto-cast the char to an int. 1. Convert Char to ASCII This Java example converts a char to an ASCII value, and […]

En Lire Plus

Java vs Python

…most people treat me like idiot for using my head instead of learning 3000 of them for each possible problem. And you’ve hit the nail on the head right there! I concur. The trouble is, almost all Java-related documentation, courses, guides, tutorials, and answers I see advocate certain design patterns, code snippets, and habits (a […]

En Lire Plus

Java : how to convert negative binary to Integer ?

Review the following Java example to convert a negative integer in binary string back to an integer type. The result is NumberFormatException ! The NumberFormatException is due to overflow, the string 11111111111111111111111111111111 (length of 32) are unable to fit into the 32 bits int type ? Note Note Integer has values from -2^31 to 2^31-1 […]

En Lire Plus

Java 15 in 2020

In 2020, Java 15 will be released with major features (some coming out of preview mode), both at language, API, and runtime levels. https://openjdk.java.net/projects/jdk/15/ Considering the changes that have already made through since Java 8 and the upcoming changes in Java 15, what are in your opinion the use cases that no longer make sense […]

En Lire Plus

“Auto increment” alphabet in Java ?

Auto increment alphabet in Java : There is two solution for auto increment alphabet using java : Solution 1 : Solution 2 : It is also possible with typecasting Read also : Java 7 – Java 8 – loop Map / List – forEach examples Read also : Twitter teste une façon de limiter les […]

En Lire Plus

Java : multi-line string, text blocks

Java multi-line string text blocks : This article will show you a few ways to declare and use a multi-line string in Java. String + String + String StringBuilder String.format StringWriter String.join (Java 8) Files.lines (Java 8) (“””) Java 13 and Java 14 text blocks (preview feature) Java multi-line string text blocks : Review an […]

En Lire Plus

Switch Expressions in Java 13

Switch Expressions in Java 13 : In Java 13, the JEP 354: Switch Expressions extends the previous Java 12 Switch Expressions by adding a new yield keyword to return a value from the switch expression. P.S Switch expressions are a preview feature and are disabled by default. 1. No more value breaks! 1.1 Java 12 value breaks syntax is no longer […]

En Lire Plus

Switch Expressions in JAVA 12

Java 12, JEP 325: Switch Expressions enhanced the traditional switch statement to support the following new features: • Multiple case labels • Switch expression returning value via break (replaced with yield in Java 13 switch expressions) • Switch expression returning value via label rules (arrow) P.S Switch expressions are a preview feature and are disabled […]

En Lire Plus

Solution for : How to join and split byte arrays, byte[] in JAVA

join and split byte arrays byte[] ? In this example, we will show you how to join and split byte arrays with ByteBuffer and System.arraycopy. ByteBuffer System.arraycopy 1. Join Byte Arrays This Java example uses ByteBuffer or System.arraycopy to join or concatenate two byte arrays. JoinByteArrayExample.java Output Terminal : 2. Split Byte Array In Java, […]

En Lire Plus

How to generate a random 12 bytes in Java ?

In Java, we can use SecureRandom.nextBytes(byte[] bytes) to generate a user-specified number of random bytes. This SecureRandom is a cryptographically secure random number generator (RNG). 1. Random 12 bytes (96 bits) 1.1 Generates a random 12 bytes (96 bits) nonce. HelloCryptoApp.java : Output : 1.2 Generates a random 20 bytes (160 bits) Output : 2. […]

En Lire Plus

Solution for : How to generate serialVersionUID using Intellij IDEA

generate serialVersionUID using Intellij IDEA : In IntelliJ IDEA, we need to enable this auto-generate serialVersionUID option manually. P.S Tested with IntelliJ IDEA 2019.3.4, it should work the same in other versions. Intellij IDEA Settings File -> Settings -> Editor -> Inspections -> Java -> Serialization issues: Find serialization class without serialVersionUID and check it. […]

En Lire Plus

How to avoid NullPointerException without != null statements

we always use object != null a lot to avoid NullPointerException on java. Is there a good alternative to this ? For example we often use : This checks for a NullPointerException for the obj object in the above snippet. Solution : This to me sounds like a reasonably common problem that junior to intermediate […]

En Lire Plus