GeeCON Prague 2014*
The moose likes Jobs Discussion and the fly likes Java Interview Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Careers » Jobs Discussion
Bookmark "Java Interview Questions" Watch "Java Interview Questions" New topic
Author

Java Interview Questions

jaiganesh javab
Greenhorn

Joined: Jul 26, 2006
Posts: 3
Hi Friends,

Here is the link for Java Interview Questions. I hope it will be useful for all.
Visit the site:Java Interview Questions

http://metajai.googlepages.com/

Regards,
JaiJava Interview Questions
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by jaiganesh javab:
Hi Friends,

Here is the link for Java Interview Questions. I hope it will be useful for all.
Visit the site:Java Interview Questions

http://metajai.googlepages.com/

Regards,
JaiJava Interview Questions


Dear Jaiganesh,

You need to imporve the site a lot...

I have catched a point at

Question 5 Page

Q: Can I have multiple main methods in the same class?

A: No the program fails to compile. The compiler says that the main method is already defined in the class.


From where you get this logic.. Cann't we overload the main method.

Check out this example



Correct this information. So that nobody may mislead


The Best way to predict your future is to create it - Every great individual common man
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Originally posted by Ankur Sharma:


Correct this information. So that nobody may mislead


By multiple main's he meant PSVM's.

The main that you have defined is not a PSVM.... it is a method which belongs to class Sample.
geeta par
Greenhorn

Joined: Jul 31, 2006
Posts: 7
http://java-j2ee-interview-questions.blogspot.com
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Originally posted by Devesh H Rao:


By multiple main's he meant PSVM's.

The main that you have defined is not a PSVM.... it is a method which belongs to class Sample.


What do you mean by PSVM ?

The above method is also public , static , returns nothing ( void ) and it's name is 'main' !! Can't it be called as PSVM ?
[ August 28, 2006: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by Devesh H Rao:


By multiple main's he meant PSVM's.

The main that you have defined is not a PSVM.... it is a method which belongs to class Sample.


Dear Devesh,

what is the difference between





in concern of Class. Both are simple methods belongs to class sample.

Am I wrong??

And By pointing out the errors in the questions-answers. I am not intended to be critical, But I just want to correct the errors so that Other who may visit the site may not be misguided.

That's why I only pointed out the errors. Please don't be get hurted
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

My guess on what the person may have meant by asking

"Q: Can I have multiple main methods in the same class?"


is

PSVM is the short form for public static void main method which is always looked up by the JVM for the starting point to a program

when we run java someclass, jvm will search for a public static void main (String[] anyparam){} inside someclass as the starting point.

the difference between

public static void main (String[] anyparam){}
and
public static void main (int[] anyparam){}

is the int param method is not something the jvm going to reference when the class needs to be run.

so when we say, we cannot have overloaded main's, it means the JVM will not recognise any method other than
"public static void main (String[] anyparam){}" as the start for the program.

But I do agree the question is a bit misleading, it can be rephrased to convey what the intention is?
As I am not the author, I can just try to understand what may have been meant ......
[ August 28, 2006: Message edited by: Devesh H Rao ]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
PSVM is the short form for public static void main method which is always looked up by the JVM for the starting point to a program

I do agree that PSVM is public static void main but not public static void main with String args.

So going to the main discussion
Can I have multiple main methods in the same class
Yes can have, because it also a normal method & can be overriden with different args.

For your answer the question should be like this
Can JVM invoke a main method with an argument other than String[] ?
A big No !
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Originally posted by Srinivasa Raghavan:

I do agree that PSVM is public static void main but not public static void main with String args.

So going to the main discussion
Can I have multiple main methods in the same class
Yes can have, because it also a normal method & can be overriden with different args.

For your answer the question should be like this
Can JVM invoke a main method with an argument other than String[] ?
A big No !



I do not know when you started coding, but if you have ever worked on JDK 1.3 in some versions of JVM

private static void main(String[] args){} worked.

I have personally tried that when I started out coding and I remember, I had a query on the same in Javaranch itself on how it could possibly work.

Thread on the private SVM in 2003

How can a private method belonging to a class be called by the JVM, or does the PSVM belong to the class it is declared to in the first place...?

I do not have access to the internals of JVM but would love to know how a private static void main(String[] args){} worked in older jvm's.


Later versions of JDK took care of the issue but just because it existed, proves one thing that the main method with String args quite does not work the way any other main method with int args works.
[ August 29, 2006: Message edited by: Devesh H Rao ]
 
GeeCON Prague 2014
 
subject: Java Interview Questions