Please correct my English.
Manuel Petermann wrote:I was also told that you should stand up and run if ever asked such a question in an interview. ;)
Tim Moores wrote:
Manuel Petermann wrote:I was also told that you should stand up and run if ever asked such a question in an interview. ;)
I concur. There is no good reason for asking this as a test for prospective employment, only bad ones.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
surendra varma wrote:In this post we are going to discuss whether is it possible to write a Java program without main method. Many people thinks that it is possible via applets but I am talking about standalone Java program.
And the answer is Yes. It is possible to write a Java program with out main method. Here is the sampe code.
Actually the funda is in Java program execution starts from static block. So I has placed my code in the static block { …. }. After the execution of the static block JVM searches for the main method. If the main method is absent it will throw main method not found exception. Hence I has terminated my program by calling the exit method so that no error messages are displayed.
The above program will not work from Java SE 7 onwards. In Jdk1.7 the above program will compile fine. But when you try to run it will give the followiing error.
Error: Main method not found in class StaticDemo, please define main method as:
public static void main(String[] args)
It seems that Java 7 specifications does not allow to execute a Java program without main method.
So the answer you have to tell is upto Java SE 6 it is possible to execute a Java program without main method. But from Java SE 7 onwards it is not possib
Palak Mathur | What is JavaRanch? | List of All FAQs |
My LinkedIn Profile
Palak Mathur wrote:
For me it is not working even in JAVA 6.
Ivan Jozsef Balazs wrote:
Palak Mathur wrote:
For me it is not working even in JAVA 6.
Strange - for me it works like this:
C:\source\java\factor>java16 StaticDemo
this is static block
C:\source\java\factor>java17 StaticDemo
C:\source\java\factor>"C:\Program Files\Java\jdk1.7.0\bin\java.exe" StaticDemo
Error: Main method not found in class StaticDemo, please define the main method as:
public static void main(String[] args)
Palak Mathur | What is JavaRanch? | List of All FAQs |
My LinkedIn Profile
Martin Vajsar wrote:How exactly do you run it from Textpad? (There are several programs of that name, according to Google.) What output do you get when you try to run it from Textpad?
Palak Mathur | What is JavaRanch? | List of All FAQs |
My LinkedIn Profile
Tim Moores wrote:It's amazing how much effort you guys put into discussing such an obscure "feature". Do you put as much effort into learning the actual new features?
Palak Mathur | What is JavaRanch? | List of All FAQs |
My LinkedIn Profile
Palak Mathur wrote:I am referring to this http://www.textpad.com/. And Google, just mentions different downloads for the same Textpad only.
![]()
In Textpad, you can configure it to compile and run Java. I am doing the same.
Tim Moores wrote:Do you put as much effort into learning the actual new features?
Martin Vajsar wrote:
Tim Moores wrote:Do you put as much effort into learning the actual new features?
But seriously, I believe Palak is actually running Java 7 from his Textpad, and I'm just trying to disentangle that.
Palak Mathur | What is JavaRanch? | List of All FAQs |
My LinkedIn Profile
Palak Mathur wrote:I do not have Java7 on my machine ;)
Satyaprakash Joshii wrote:This can be done with static initilizer block...but what has JDK 7 to do with it.???..it was in previous versions too...
Consider Paul's rocket mass heater. |