Submitted On 03-AUG-1999
yar
This must pose a bit of a quandary when people see it on the certificaiton
exam.
Submitted On 01-AUG-2000
tomwa
See also bug 4155575, and section 12.1.4 of the JLS 2. This *is* required by the specs, and so this *is* a
bug.
Funnily enough, i came across this due to a certification question ...
Submitted On 17-SEP-2000
santosh_raut
This violets the oop's concept, i.e. data encryption,
U can declare the method as private to restrict its access
from outside the class where it is declared. but in this
case u can declare main method as private and still jvm
can access the method. This is very contradictory !!!!!
Submitted On 18-JAN-2001
hawk777
absolute violation of OOP's concept. But it doesnt cause any
problem to the performance of a program.
Submitted On 22-MAY-2001
oleg
This is also a compatibility issue: with some JVM this
work, but other JVMs might be confused.
Submitted On 22-MAY-2001
suhas
Yes, it does violate the encapsulation but I am so used to public static main(args[]) that I did not
even realize if the private works up until now. Not really that important from my perspective, after all most
of the classes in a design won't have a main.
Submitted On 13-JUL-2001
mister_ravi
But- a funny word 'but'; usually the part of the sentence
after 'but' is more important- there is no visible harm if
the VM (and only the VM) can access the private main method.
After all any attempts by any class to access the private
main method results in compile time error. So it is perfect
enough. isn't it?
Submitted On 13-JUL-2001
mister_ravi
But- a funny word 'but'; usually the part of the sentence
after 'but' is more important- there is no visible harm if
the VM (and only the VM) can access the private main method.
After all any attempts by any class to access the private
main method results in compile time error. So it is perfect
enough. isn't it?
Submitted On 31-AUG-2001
fist2001
This completely violates the OO concepts and destroys the
concept of encapsulation. This is really a bug and should
be fixed. In SCJP exam, the answer to the question,
"How main method is written?" is:
public static void main(String args[]) {}
and writting 'private' instead of 'public' is considered a
wrong answer. This proves the complete contradiction in
JAVA. this is a big mistake SUN has made.
Submitted On 19-OCT-2001
blakis
Yes, this is definitely a bug and should be fixed.
Submitted On 25-OCT-2001
vgv8
I di not understand which exactly "latest specs"?
Submitted On 03-NOV-2001
GalB
The way I see it, this is not a bug "per se". The VM supports a broader range
of apps than the minimal required set, but it does not refect something the is
legal according to the spec.
However, after taking a look at the java launcher source, I can't see what the
big deal is with adding a check to make sure the method is public. I don't
know a way to do this directly with JNI portably, but a call to some verifier
static method (written in Java) would do. May take a few nano's more, maybe
that's what they're worried about :)
I don't think this makes that big a difference anyway.
Gal
Submitted On 09-NOV-2001
eduardo39
Hello!
I have the version 1.2.2 of java. Have done some tests with
the method main () and has found that already compiles and
runs with the modifiers: private, protected, final, or
synchronized. Can also be default (friendly).
Someone it is able to say if has changed the concept of
valid signature firm of the metodo main ()?
I need to know it because I am preparing myself for the
exam of certificacion
Thanks.
Submitted On 15-JAN-2002
JL_Marais
This is a pityful situation. Rules are rules. Private has to
be private. ALWAYS
Submitted On 16-FEB-2002
sharpgv
i dont think this is major issue. but good think is JVM
can only access the private main. But no other class can't
access private main method. This is not bug.
Submitted On 14-MAR-2002
spsreekanth
If this is here to stay we can use it for writing test code
in private main method and at the same restrict it from
being called from other classes.
Submitted On 25-MAR-2002
rodrigol
On JVM 1.3.1, under Windows 2000 Professional it also runs
Submitted On 07-MAY-2002
dasun
We identify java as a good OO language. So private has to
be private. This is really a bug but since only the runtime
can access this private method it cause no harm.
Submitted On 31-MAY-2002
marcos10
Well... let me go against the specs, since it could have
mistakes (and since I am not a "certifyed" one :-P ).
First of all, OOP encapsulation feature is a conceptual
one, wich relies on the fact that there exist a implied
side effect needed to carry on administrative tasks like
instance creation, memory management, and message-method
bindings from the JVM, wich HAVE TO be able to break the
encapsulation (the lack of side effectonly could happen,
for example, with "pure" functional languages where doesn´t
exist a shared pool of memory among funtions).
Second, I believe the main method should be able to be
private, and it is a desirable feature wich enable you to
write code for testing your objects AND forbide the final
client objects to do the same.
You may argue that having a private main violates the
concept of encapsulation, just AFTER supposing that you´re
sending a "main" message to your class from outside the JVM
(i.e., the command line), as if there were an implicit
interface making the class "executable". But that
supposition isn´t neccesarily valid, since the JVM is
OUTSIDE the boundaries of your model. The JVM would be God
here: it can see and inspect every and all objects and
methods, without matter of how private you pretend them to
be, so it is beyond the scope of this concept.
Somehow (magic!) an start point is needed to put your model
to work, and up to me it makes even more sense to avoid
considering this point as part of ANY class explicit
external behavior. Thus, main shouldn't be called a method,
but perhaps some sort of meta-constructor to implement such
a start point, and should'nt be able to be binded to any
message sent by any object.
Submitted On 05-JUN-2002
schweenS
Any one know how to fix an sytax error reading of your
running jdk1.2.2 is it the same thing???
Submitted On 24-JUN-2002
petit
Hello all!
AS the main() method is an important one, beeing the
startpoint for any Java program that is not an Applet,
every Java programmer should have an opinion :)
Here's mine.
There are a few different aspects on the allowed access
modifiers.
First the question on certification. If it is possible to
declare the main method private or protected, cotradictory (
or not ) to the JVM spec, it must also be allowed in the
certification exams ( anyone against? ).
Second. Some contributors to the discussion clames that the
possibility to give the main method private access violates
the OOP or OOD and that private should be private.
It may sound resonable, but I don't agree. As marcos10 put
it : "The JVM would be God here". Reflection is an important
facility in Java and the JVM can do anything it wants with
the objects.
Third, and the bottom line in my opinion, the main method
has nothing to do with OOP. It is merely the point where the
JVM transfers control to your program.
The main method could run without instatiating any object at
all, and I always tell my students that it is not Object
oriented and recommend them to write a start class where
main only instantiates another real object to run the show.
That way they immedeatly get rid of the static context and
the rest of the program is tryly object oriented with all
the dynamics of OOP.
The main method, in my opinion, is a not so nice heritage
from the C language ( thanks for using the C syntax though :).
It might have been better to let the JVM instantiate the
start class object via its constructor ( or any init method
) and then dynamicaly call its run() method, therby starting
the main thread.
Such a run method would be public but by compile time
restrictions not callable by other objects.
However I believe that the public static vod main() is here
ti stay, so in short:
1. The exams should reflect the way it works
2. The compilers should impose the JVM spec.
3. The main() should do nothing but instatiate a main object.
Mark my words if you will ;)
By the way - why just Object *Oriented* ?
Have an nice summer and a steaming hot cup
/Bertil
Submitted On 24-JUN-2002
issbyju
What about this
static void main(String[] args) {
}
Submitted On 24-JUN-2002
santosh811
Well I do agree that is is a bug and it violets the
encapsulation, one of the core concepts of Object Orient
design. But this is all in theory, It is not causing any
serious trouble as far as an applications are concerned.
Submitted On 31-JUL-2002
nrkonjeti
hi all, no one is giving right answer. but every one is giving
exact answer.
Submitted On 05-AUG-2002
sanpriya
dear friends
What i think is that this is not a bug. JVM should have
access to the main method irrespective of the access
modifier supplied. But the question appearing in the sun
certification exams asking the exact signature of main
method should be reviewed by SUN.
Submitted On 02-DEC-2002
msenthilkumaran
Anyway, this is definitely a bug and this should be fixed soon.
rule is 'rule' and everybody should follow that. It should not
violate OO concepts.
Submitted On 11-APR-2003
nrlz
Why would it violate OOP and encapulation if Java already
allows this facility through the Reflection API? It seems like
any class is able to access the private fields and methods of
another class as long as they have access to reflection.
Submitted On 30-MAR-2004
FreshPro
hi
i tried to find out which class or interface holds the
declaration of method main() in the documentation.I
want to know how main method is incorporated into a
java program.can u plz give me a lead.
Submitted On 04-FEB-2005
shyam123_sunder
I am new learner but i want to gain more knowledge about java.
Submitted On 10-AUG-2005
Sanjeev_Kumar_Sharma
I wrote following class
class testingMain
{
private static void main(String[] args)
{
System.out.println("Hello World!");
}
}
It does not gave me any compile time error. At running it gave me simple message "Main method not public.".
I think it now way allowing the Main method to access while executing.
Submitted On 17-NOV-2006
TO Sanjeev_Kumar_Sharma:
It does compile. But it cannot run with error message "Main method not public."
Submitted On 17-NOV-2006
TO Sanjeev_Kumar_Sharma:
It does compile. But it cannot run with error message "Main method not public."
Submitted On 26-FEB-2008
srinivasu_34
I am not getting correct answer
Submitted On 19-AUG-2009
private static void main(String[] args) {
}
I don't understand.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|