Wann muss ein Konstruktor initialisiert sein?

Hallo

Ich hab mir vor ein paar Tagen ein Programm mit Eclipse zusammengestellt, um Primzahlen zu überprüfen, aber da war mir was komisches aufgefallen, es spielte scheinbar keine Rolle, ob ich einen Standard-Konstruktor hinzufügte oder nicht, das Program lief immer, obwohl ich aber explizit ein Objekt erzeugen muss.
Könnte mir da jmd vielleicht etwas genauer erläutern, was da vor sich geht?

Im Voraus danke für hilfreiche Tipps

Der Quellcode:

public class Primzahl {

public String Tester(int P){
boolean b=true;
int N=2;
while (N

Eigentlich sollte das Verhalten in jeden Grundkurs Java gehören. Hier der entsprechende Abschnitt aus dem offiziellen Sun… eh, Oracle-Tutorial:

You don't have to provide any constructors for your class, but 
you must be careful when doing this. The compiler automatically provides
a no-argument, default constructor for any class without constructors.
This default constructor will call the no-argument constructor of the 
superclass. In this situation, the compiler will complain if the 
superclass doesn't have a no-argument constructor so you must verify 
that it does. If your class has no explicit superclass, then it has an 
implicit superclass of Object, which does have a no-argument 
constructor.

Heißt für Dich: Auch ohne Deinen Standardkonstruktor (Du nennst ihn sogar schon so :wink:) hat Deine Klasse einen impliziten Konstruktor. Im Zweifelsfall ist das erstmal der von java.lang.Object.

Der Quellcode:

public class Primzahl {

public String Tester(int P){
boolean b=true;
int N=2;
while (N

Ich habe mal die Hinweise der anderen aufgegriffen und mein „Senf“ dazu gegeben. Das Ergebnis ist:

public class Primzahl 
{
 public boolean isPrimzahl(int primZahl)
 {
 boolean isPrimZahl = true;
 int teiler=2;
 while (teiler

Ich habe das Ganze out-of-the-box getippt...aber der Code sollte richtig sein.

Kleiner Nachtrag, ich habe die WHILE-Schhleife geändert. Jetzt wird die Schleife abgebrochen beim ersten auftreffen einer Teilbarkeit im Bereich von:
Teiler > 2 und Teiler

public class PrimZahl
{
 public boolean isPrimzahl(int primZahl)
 {
 boolean isPrimZahl = true;
 int teiler=2;
 boolean loop = true;
 while (loop)
 {
 if(teiler \>= (primZahl-1))
 {
 loop = false;
 }
 if (primZahl % teiler == 0)
 {
 loop = false;
 isPrimZahl = false;
 } 
 teiler++; 
 }
 return isPrimzahl;
 }
}