Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Interview Questions

 
jaiganesh javab
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Devesh H Rao
Ranch Hand
Posts: 687
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 687
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 687
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic