Abstract. This article describes the calculation of prime numbers with the sieve of Eratosthenes in Java

## 1. Prime Factorization

A prime is an integer greater than one whole only positive divisors are one and itself.

The prime counting function for a number N (also known as pie(N)) is the number of primes less or equal to N. The following algorithm determines all prime numbers until a certain value.

## 2. Implementation in Java

Create the following program.

``````package de.vogella.algorithms.primenumbers;

import java.util.ArrayList;
import java.util.List;

// Using the sieve of Eratosthenes
public static List<Integer> calcPrimeNumbers(int n) {
boolean[] isPrimeNumber = new boolean[n + 1]; // boolean defaults to
// false
List<Integer> primes = new ArrayList<Integer>();
for (int i = 2; i < n; i++) {
}
for (int i = 2; i < n; i++) {
// now mark the multiple of i as non-prime number
for (int j = i; j * i <= n; j++) {
}
}

}

return primes;
}

public static void main(String[] args) {
for (Integer integer : calcPrimeNumbers) {
System.out.println(integer);
}
System.out.println("Prime counting function (Pie(N)) : " 