Category: javabasics

  • Type casting primitive data types in Java

    This tutorial focuses on the different type-casting operations that could be performed in Java (such as double to int and vise verca), using primitive data-types, and the consequences from performing such operations. What is Type Casting? In programming, type casting is the process of “casting” a value of a certain data type, into a storage…

  • Bitwise AND “&” operator on Integers in Java

    In this tutorial, we will discuss how to use the bitwise AND operator “&” on integers, and the side effects that this would have such as on signed and unsigned numbers. Before we start, I recommend that you check out our article about the best books and learning material that you could use to jump-start…

  • Java XOR (Exclusive or) operator on Booleans

    In this tutorial, will show how to use a the Java XOR (exclusive or) operator on booleans, and we will discuss how the operator behaves with various combinations of boolean values. In Java, booleans can hold only two values, true and false. The XOR operator in Java ‘ ^ ‘ can be used with booleans…

  • Java BigDecimal, Dealing with high precision calculations

    In this tutorial, we will discuss how to use the Java BigDecimal class to deal with calculations that require a high degree of precision, such as when dealing with currency conversion, taxes or even high accuracy mathematical calculations. Why do we need the BigDecimal class In Java a floating point or a fractional number can…

  • ArithmeticException in Java – Causes & Treatment

    In this tutorial, we will introduce a few examples that would highlight the causes of getting an ArithmeticException thrown within a Java program. We will discuss the common causes of the exception, and how these could be treated. What is an ArithmeticException? An arithmetic exception is an error that is thrown when an invalid arithmetic…

  • Java ArrayIndexOutOfBoundsException – Causes & Fixes

    In this tutorial, we will discuss what a Java ArrayIndexOutOfBoundsException is, what causes it and how to make sure that you avoid it. What is an ArrayIndexOutOfBoundsException An array-index out of bounds exception is a Java exception thrown due to the fact that the program is trying to access an element at a position that…

  • Java Switch Statements – Uses, Advantages and Restrictions

    In this tutorial, we will discuss what are Java switch statements, how to use them, the allowed data types that can be used in the switch statements and the advantages and restrictions that apply to them.   What is a “switch” statement   A “switch” statement in Java  is a conditional operator used to direct…

  • What is a BigInteger and how to use it in Java

    A BigInteger is a data structure in Java that is used to represent very large numerical values that would otherwise not fit within a primitive data type such as an int or long. In this post, we will discuss different ways to initialize a BigInteger and how to use it to perform mathematical operations. Why…

  • How to find prime numbers using Java

    In this post, we will discuss how to write a simple Java program to find prime numbers between 1 and 100. We will be using a simple algorithm implemented in nested loops. So let us get started! What is a prime number? A prime number is a number which can only be divided by 1…

  • Java – Convert a decimal number to and from a binary number

    In this tutorial, we will discuss how to convert a decimal number to binary and back to a decimal. This can easily be done by preexisting Java functionalities. But for the sake of curiosity, let us implement our own algorithm first, and then let us discuss how to do with existing Java functions.   Algorithm…