have started learning Java recently and was looking into some easy algorithms.I found the Sieve Of Erastothenes algorithm hereI am trying to get better at writing good code for my solutions. Please give me your suggestions.import java.util.Scanner;public class SieveofErastothenes {    public static void main(String[] args) {        Scanner keyboard = new Scanner(System.in);        System.out.println(Enter the prime number ceiling);        int ceiling = keyboard.nextInt();        keyboard.close();        prime(ceiling);    }    private static void prime(int n) {        // create an array with 0 and 1 where 1= Prime and 0= Non Prime        int[] isPrime = new int[n + 1];        // set all values to 1        for (int i = 2; i <= n; i++) {            isPrime[i] = 1;        }        int upperbound = (int) Math.sqrt(n);        for (int i = 2; i <= upperbound; i++) {            if (isPrime[i] == 1) {                for (int j = 2; j * i <= n; j++) {                    isPrime[j * i] = 0;                }            }        }        printprime(isPrime, n);    }    private static void printprime(int[] isPrime, int n) {        for (int i = 0; i <= n; i++) {            if (isPrime[i] == 1) {                System.out.println(i);            }        }    }}A few online tutorials use a boolean array to set all the values as true or false whereas I am using an integer array and setting the values to 0 and 1 initially.Does this make any difference in the performance?
Sieve Of Erastothenes using Java
java;primes;sieve of eratosthenes
The short answer to your question, is yes. It does make a difference to performance. However, we're only talking about increased RAM usage (integer datatype is bigger than boolean) - and we're talking about a lot less than 1kb. So on a modern computer (even a Raspberry Pi),  you won't have a problem.Now, general advice & tips...Variable names should be appropriate to their use. When I see isPrime I assume that it's a boolean value (because it's either a prime or it isn't). Regardless of performance impact, boolean makes more sense because you only ever set 0 or 1.Loops - is there a specific requirement why you appear to be writing 1.3 compliant code? For loops could be done with the for( TYPE var : collection) form. Makes it more readable IMO - I don't need to worry about the control variable being tampered with during loop execution.Method names - should be descriptive, and use camel case. prime() and printprime are examples of how not to do it.Math.sqrt() takes a double and returns a double - why are you casting directly to int? If you really want an int datatype, you should be rounding as appropriate (up vs down). Get out of the habit of just casting primitives before you move on to their wrappers - eg, you cannot cast Double directly to int.Comments - opinions vary. Use sparingly and only when deliberately against accepted convention, or to explain why you have to do something a certain way even though you know it should be done differently. JavaDoc comments again, should be used sparingly. Get the class & method names right, and JavaDoc shouldn't be needed. There could be constraints that would push you to use JavaDoc, and if so, that's fine.Unit test. Unit test. Unit test. You don't appear to have any. Write the Unit Tests before you write your main code. Write as little main code as possible to make your unit tests pass (make sure your Unit Tests are appropriate for requirements first).