JDK-4155575 : (launcher) main method should have to be public
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 1.0,1.1.7,1.2.0,1.2.1,1.2.2,1.3.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,solaris_2.4,solaris_7,windows_95,windows_98,windows_nt generic,solaris_2.4,solaris_7,windows_95,windows_98,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1998-07-08
  • Updated: 2001-05-25
  • Resolved: 2001-05-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
1.4.0 beta2Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
In 1.2Beta4 it is no longer required that the main method of an application
be public. This is true for both java and oldjava, and is an incompatible
change from 1.1.

Name: tb29552			Date: 09/06/99

  I had written a simple application with the main method as

public class psvm {
  private static void main(String[] args) {
    System.out.println("works ");

Can you tell me how the jvm can call the private method main.

I did it under 1.1.x and it reports an error:
  "In class psvm: main must be public and static"

but under 1.2.. it just executed and gave the output.

(Review ID: 94901)

Name: rmT116609			Date: 02/21/2001

output is fine...but how is private main() method is getting inherited

Could any one please explain that how private main() method is getting
inherited in DerivedClass from BaseClass, you can save the below mentioned
code as DerivedClass.java and run as java DerivedClass, the output is "This
is Base Class main. I am using jdk1.3.

// File: DerivedClass.java
class BaseClass {
    private static void main(String[] a){
        System.out.println("This is Base Class main");

public class DerivedClass extends BaseClass {
(Review ID: 117419)

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta2 FIXED IN: merlin-beta2 INTEGRATED IN: merlin-beta2

SUGGESTED FIX peter.allenbach@eng 2001-03-26 The problem is how to check if the main method is public. In java.c, after mainID has been found, I suggest adding the following: jobject obj = (*env)->ToReflectedMethod(env, mainClass, mainID, true); mid = (*env)->GetMethodID(env, obj, "getModifiers", "()I"); int mods = (*env)->CallIntMethod(env, obj, mid); /* now, can either call Modifier.isPublic(mods), or cheat and directly test the PUBLIC bit of mods */

PUBLIC COMMENTS The VM spec requires that the main method be public. We now enforce that requirement.

EVALUATION Yes, this is straightforward to fix in the launcher. neal.gafter@Eng 2001-05-03 Note that the constraint that main must be public appears in every manual page for "java", as well as in the VM specification. neal.gafter@Eng 2001-05-14