May 2017

Binary Numbers in Java

  • Satish 

1. Introduction The binary number system uses 0s and 1s to represent numbers. Computers use binary numbers to store and perform operations on any data. In this tutorial, we’ll learn how to convert binary to decimal and vice versa. Also, we’ll perform addition and subtraction on them. 2. Binary Literal Java 7 introduced the binary literal. It simplified binary number usage. To use it, we need to prefix the number with 0B or 0b: @Test public void given_binaryLiteral_thenReturnDecimalValue() { byte… Read More »Binary Numbers in Java

Using the Not Operator in If Conditions in Java

  • Satish 

1. Introduction In Java’s if-else statements we can take a certain action when an expression is true, and an alternative when it is false. In this tutorial, we’ll learn about how to reverse the logic using the not operator. 2. The if-else Statement Let’s start with a simple if-else statement: boolean isValid = true; if (isValid) { System.out.println(“Valid”); } else { System.out.println(“Invalid”); } What if our program only needs to handle the negative case? How would we re-write the above example? One option is to simply remove the code… Read More »Using the Not Operator in If Conditions in Java