Why main() method has to be void in Java?

According to the C++ creator Bjarne Stroustrup,
The definition
        void main() { /* ... */ }
is not and never has been C++, nor has it even been C.
See the ISO C++ standard 3.6.1[2]
Then if Java is developed from C, why the main() method has
to be void like this:
Public class JavaClass{
    Public static void main(String[] args){
}

First search the forums, you will find a huge thread on this.
second, to be brief, in C and C++, you have primary thread and when main exits, the application terminates returning a value. e.g. when you do exit(0);
In java, you could have secondary user-threads (not daemon threads) which you have started in your main and these continue to run even after the main method has exited. So returning a value would not make sense because your application has not terminated as there are still threads running.

Similar Messages

  • Does main method have to be static? Is there a way to go around it?

    I am trying to write a class that will recursively walk through directory listing of a given ftp adress and store it in a text file in this format:
    <path> , DIR // if directory
    <path> , file // if file
    Since I am not yet experienced to do my own socket programming(tried and did not work out) I used Secure iNet Factory's library. And since I will be running multiple instances of this class I concluded that my fields and methods should not be static. Here is the class I wrote:
    import com.jscape.inet.ftp.Ftp;
    import com.jscape.inet.ftp.FtpException;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.net.URL;
    import java.util.Enumeration;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class test {
         private String path = "/";
         private String name;
         private String adres;
         // create new Ftp instance and connect.
         public test(String Name, String Adres) throws IOException {
              name = Name;
              adres = Adres;
              System.out.println("Test class: " + name);
              try {
                   Ftp ftp = new Ftp(adres,"anonymous","anonymous");
                   ftp.connect();
                   Enumeration e = ftp.getDirListing();
                   iterate(path, ftp);
                   ftp.disconnect();
              catch (FtpException ex) {
                   Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
         void iterate(String aStartingDir, Ftp ftp) throws FtpException, IOException {
              //Set the path.
              path = path + aStartingDir + "/";
              // Change directory.
              ftp.setDir(aStartingDir);
              // Iterate through directory list.
              Enumeration e = ftp.getDirListing();
              while(e.hasMoreElements()){
                   Object f = e.nextElement();
                   // Recursive call if item is directory.
                   if(f.toString().startsWith("drwxrwxrwx") &&
                        // Ignore "." and ".."
                        !f.toString().substring(55).trim().equalsIgnoreCase(".") &&
                        !f.toString().substring(55).trim().equalsIgnoreCase("..")) {
                        // Write to index file.
                        URL dirUrl = FtpCheck.class.getResource("./index/"); // get the directory.
                        URL fileUrl = new URL(dirUrl, name + ".txt"); // construct the file path.
                        String filePath = fileUrl.getPath().replaceAll("%20", " "); // fix spaces.
                        BufferedWriter file = new BufferedWriter(new FileWriter(filePath,true));
                        file.write((path + f.toString().substring(55).trim()).substring(3)
                             + ",DIR\n");
                        file.close();
                        iterate(f.toString().substring(55).trim(),ftp);
                   // Skip entries "." and ".."
                   else if (f.toString().substring(55).trim().equalsIgnoreCase(".") ||
                             f.toString().substring(55).trim().equalsIgnoreCase("..")) {
                             continue;
                   // Add files to the index.
                   else {
                        URL dirUrl = FtpCheck.class.getResource("./index/"); // get the directory.
                        URL fileUrl = new URL(dirUrl, "index.txt"); // construct the file path.
                        String filePath = fileUrl.getPath().replaceAll("%20", " "); // fix spaces.
                        BufferedWriter file = new BufferedWriter(new FileWriter(filePath,true));
                        file.write((path + f.toString().substring(55).trim()).substring(3)
                             + ",file\n");
                        file.close();
              // End of listing reached, go one directory up.
              ftp.setDirUp();
              // And remove the last directory name from path.
              path = path.substring(0,path.lastIndexOf("/"));
              path = path.substring(0,path.lastIndexOf("/")) + "/";
    }which compiles fine.
    Here is the class that invokes it:
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author Sentinel
    public class NewClass {
         public NewClass() {
         public static void main(String args[]) throws MalformedURLException, FileNotFoundException, IOException {
              index t = new index("El Naga","elnaga.sytes.net");
              t.start();
              index t1 = new index("Afacan","afacan.myftp.org");
              t1.start();
         public class index extends Thread {
              String name;
              String adres;
            public index(String Name,String Adres) {
                name = Name;
                adres = Adres;
            @Override
            public void run() {
                try {
                    test checker = new test(name,adres);
                catch (IOException ex) {
                     Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
    }when I hit run build fails:
    init:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\build\classes
    C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\src\NewClass.java:19: non-static variable this cannot be referenced from a static context
                    index t = new index("El Naga","elnaga.sytes.net");
                              ^
    C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\src\NewClass.java:20: non-static variable this cannot be referenced from a static context
                    index t1 = new index("Afacan","afacan.myftp.org");
                               ^
    2 errors
    BUILD FAILED (total time: 0 seconds)I (now)know that main method has to be static. I'm stuck and in need of help to overcome this obstacle. Is there a way to do this?

    a stab in the dark, but what if you make index a non-internal class. make it a stand-alone class in it's own file. Either that or make it a static inner class (almost the same thing).
    Your problem is that an inner class needs an instance of the outer class to start on, and you're not doing this. Another solution would be to do this kludge:
    index t = new NewClass().new index("El Naga","elnaga.sytes.net");  // I think this is how to call itBut again better is to make index a stand-alone class.
    Edited by: Encephalopathic on Oct 28, 2008 8:06 AM

  • How to run executable Java app from command line: No Main( ) method

    This is the opposite question from what most users ask. I have the Java source code and a running Java executable version of the program in a windows environment. I don't want to run it in the normal way by double-clicking on it or using the executable. I need to be able to run the same application from the command line. If I can do this, I can then compile and run the code on my Mac, too, which is what I am ultimately trying to accomplish.
    Normally, this would be easy. I would look for a Main method, normally public static void main (String[] args ) or some variation. I cannot find a main() anything, anywhere when searching the files. There must be some windows executable that links to the Java classes. It's very clever, no doubt, but that's not helping me.
    I am trying to run what I can determine as the Main class, with a standard command line call, but that is not working either.
    It is a Java graphics program, so mostly Swing container stuff.
    I am not finding a manifest.txt file, telling me where a main method is, nor anything about the Main Class. There is no readme file for the program.
    Any insight that would point me in the right direction? What should I be looking for?
    Thanks in advance, Bloozman

    It's possible there's a clever Windows executable that runs the class. But if it's a plain old Java class then there's a good chance there's a constructor. Look for that; it's possible you may be able to start by writing another Java class that creates an instance of your mystery class.
    When you have that done, try running it. It's possible that just creating an instance might be sufficient to run it. Swing programs are sometimes written like that. If not, then start looking for methods with names like "run" or "go" or "start" that your little controller program can call.

  • Private main method

    if i write private static void main(String s[]) then it also behave as normal as public static void main(String s[]) How it is possible while i m declaring main method as private and now how JVM interpreter can access this method from the class while it is private now..??

    Both the JLS and the JVM specs require that the main method to be public (note however that you are allowed to have a private, static, void method that takes a single String-array argument, but it should not be considered an application entry-point).
    This was a bug introduced into Sun's VMs with early 1.2 releases; Originally there was no intention to fix it, but eventually they decided to do so, and it was fixed for 1.4.
    If you do not declare your main methods public, static and void, you will find that your applications stop working one day when you switch Java versions, or when you roll the code out to clients using a different version to that which you developed and tested the apps on.

  • Main method in mulitple classes?

    I'm new to java as some of you might know, and I've been working on a single class. Now I'm trying to add another class. I've tried many ways to do this, and I think I almost have it, but I'm still a little stuck. Here are a few questions:
    1. I only can have one main method, which goes in the main class, right? Then the subclasses just have methods? So, how does the subclass know which methods to call first, and when? If there is a main method in the subclasses, t should be private and the main method in the main class should be public? So if I have multiple methods in a subclass, how do I tell my main method which to call? I've tried:
    new Timer.test();
    new Timer(test);Neither seem to work.
    So, organized in a tree it should be like so:
    Public class mainClass
         public main method
              new subClass
      Private class subClass
          (no main method?)
              private subClassMethod1
              private subClassMethod2I've tried searching, but maybe I'm not searching for the right terms. I can find things on creating classes and methods, but not really on the way multiple classes are set up. Can someone explain so I understand exactly what I'm doing with multiple classes, or give me a link to a good explanation? Thanks
    Also, the subclass ALWAYS extends mainClass right?
    Edited by: LIVE3A17 on Apr 28, 2009 3:13 PM

    LIVE3A17 wrote:
    Ok, so I can use main methods in the other classes, and java knows which is the main class by which one is opened when the program is run. Got it. Don't even put a main method in the other classes, unless you intend on one of them to be an entry point. Otherwise it's just code bloat.
    >
    Now, I have a main method in both classes. When I have the main method in the main class set to public, I get an error in the second class saying "Cannot reduce the visiblity of the inherited method". I gives me the option to change visibilty of my main class to private. However, when I do this, and try to run the main class, I get an error saying main method not public.I don't know what you're talking about. Sounds like you are subclassing something and for whatever reason trying to 'override' the main method. The normal static main method isn't even inherited, being static. So this error you're speaking of doesn't make much sense. Of course without seeing your code, we're left to mindreading exercises which usually don't go so well.

  • I am unable to register my debit card after creating my apple ID. Whenever i click enter after filling all the debit card details, it shows that, "your payement method has been declined". Please help me people, why is it so.?

    I am unable to register my debit card after creating my apple ID. Whenever i click "continue" after filling all the debit card details, it shows that, "Your payement method has been declined". Please help me people, why is it so.? Also, i would ike to tell that my bank is, Union Bank Of India and it facilitates the auto conversion, rupee to dollar.. I think there is a different problem. Please help me guys.!!

    The card must be issued in the same country as the store you are trying to use. If you're trying to sign up for the US Apple Store, it must be a US card with a US billing address. If you're trying to sign up in India, it must be an Indian card with an Indian billing address.
    Apple will run a small charge, which will be credited back, to make sure the card is valid. If it is a debit card and you do not have enough in the account to cover the authorization, it will be declined.
    It is possible the currency conversion you mentioned may be causing a problem. Contact the issuing bank if you are sure you have enough in the account and you are signing up for the correct store.

  • Why dont to put construcor in a main() method

    Hi,
    public class checkNumeric
         public static void main(String a[])
              public checkNumeric(){
                   System.out.println("I am in Constructor:::");
              checkNumeric ob=new checkNumeric();
    Can u plz tell y dont put cnstructor in main() method.

    Do you know what a constructor is? Can you put one method inside another method?

  • Adding a class to a project in sunone studio that already has a main method

    i have a frame class and it contains a main method, I can't figure out how to add a class that makes use of the JDialog and call it from the main class. When i try to add a JDialog, it creates its own main method.
    If abc.class is my main method class and dcf.class is my class that makes the dialog GUI, I want abc.class to be able to call it, i can't figure out how to do this in Sun One Studio 5

    Having a main() in the JDialog doesn't hurt. It lets you run the JDialog as a standalone - make sure that it looks good, etc. When you run your other class, the main() won't get called. (And you can delete it when you're all debugged.
    Alternatively, create a new class, then start it by saying
    class MyDialog extends JDialog {
    }S1S will be completely happy if you do it that way.

  • Bouncing Ball without Main Method

    Hi. I needed to reserch on the Internet sample code for a blue bouncing ball which I did below. However, I try coding a main class to start the GUI applet and it's not working. How can I create the appropriate class that would contain the main method to start this particular application which the author did not provide? The actual applet works great and matches the objective of my research (http://www.terrence.com/java/ball.html). The DefaultCloseOperation issues an error so that's why is shown as remarks // below. Then the code in the Ball.java class issues some warning about components being deprecated as shown below. Thank you for your comments and suggestions.
    Compiling 2 source files to C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\build\classes
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:32: warning: [deprecation] size() in java.awt.Component has been deprecated
        size = this.size();
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:93: warning: [deprecation] mouseDown(java.awt.Event,int,int) in java.awt.Component has been deprecated
      public boolean mouseDown(Event e, int x, int y) {
    2 warnings
    import javax.swing.*;
    public class BallMain {
    * @param args the command line arguments
    public static void main(String[] args) {
    Ball ball = new Ball();
    //ball.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    ball.setSize( 500, 175 ); // set frame size
    ball.setVisible( true ); // display frame
    import java.awt.*;*
    *import java.applet.*;
    import java.util.Vector;
    // Java Bouncing Ball
    // Terrence Ma
    // Modified from Java Examples in a Nutshell
    public class Ball extends Applet implements Runnable {
    int x = 150, y = 100, r=50; // Position and radius of the circle
    int dx = 8, dy = 5; // Trajectory of circle
    Dimension size; // The size of the applet
    Image buffer; // The off-screen image for double-buffering
    Graphics bufferGraphics; // A Graphics object for the buffer
    Thread animator; // Thread that performs the animation
    boolean please_stop; // A flag asking animation thread to stop
    /** Set up an off-screen Image for double-buffering */
    public void init() {
    size = this.size();
    buffer = this.createImage(size.width, size.height);
    bufferGraphics = buffer.getGraphics();
    /** Draw the circle at its current position, using double-buffering */
    public void paint(Graphics g) {
    // Draw into the off-screen buffer.
    // Note, we could do even better clipping by setting the clip rectangle
    // of bufferGraphics to be the same as that of g.
    // In Java 1.1: bufferGraphics.setClip(g.getClip());
    bufferGraphics.setColor(Color.white);
    bufferGraphics.fillRect(0, 0, size.width, size.height); // clear the buffer
    bufferGraphics.setColor(Color.blue);
    bufferGraphics.fillOval(x-r, y-r, r*2, r*2); // draw the circle
    // Then copy the off-screen buffer onto the screen
    g.drawImage(buffer, 0, 0, this);
    /** Don't clear the screen; just call paint() immediately
    * It is important to override this method like this for double-buffering */
    public void update(Graphics g) { paint(g); }
    /** The body of the animation thread */
    public void run() {
    while(!please_stop) {
    // Bounce the circle if we've hit an edge.
    if ((x - r + dx < 0) || (x + r + dx > size.width)) dx = -dx;
    if ((y - r + dy < 0) || (y + r + dy > size.height)) dy = -dy;
    // Move the circle.
    x += dx; y += dy;
    // Ask the browser to call our paint() method to redraw the circle
    // at its new position. Tell repaint what portion of the applet needs
    // be redrawn: the rectangle containing the old circle and the
    // the rectangle containing the new circle. These two redraw requests
    // will be merged into a single call to paint()
    repaint(x-r-dx, y-r-dy, 2*r, 2*r); // repaint old position of circle
    repaint(x-r, y-r, 2*r, 2*r); // repaint new position of circle
    // Now pause 50 milliseconds before drawing the circle again.
    try { Thread.sleep(50); } catch (InterruptedException e) { ; }
    animator = null;
    /** Start the animation thread */
    public void start() {
    if (animator == null) {
    please_stop = false;
    animator = new Thread(this);
    animator.start();
    /** Stop the animation thread */
    public void stop() { please_stop = true; }
    /** Allow the user to start and stop the animation by clicking */
    public boolean mouseDown(Event e, int x, int y) {
    if (animator != null) please_stop = true; // if running request a stop
    else start(); // otherwise start it.
    return true;
    }

    FRiveraJr wrote:
    I believe that I stated that this not my code and it was code that I researched.and why the hll should this matter at all? If you want help here from volunteers, your code or not, don't you think that you should take the effort to format it properly?

  • How to tell how many times a method has executed?

    Hi, all
    I've got a main class (Model.java) that repeatedly calls a step() method in a sub class (Ocean.java). I want Ocean.java to execute its step() method following one set of rules for the first time it is called by Model.java, and a different set of rules for all executions 2++. I was just going to use an if/else in Ocean.java's step() method to make it switch based on a boolean haveIExecutedThisStepOnce, or something like that. Is there some way to tell Ocean.java how many times it has executed the step() method? I'm using the RePast code libraries; Model.java uses a method called getTickCount(). It returns a double value of number of times Model.java's step() method has been executed, in which Model.java tells Ocean.java to execute its step() method. Should I pry that getTickCount() value out of Model.java and get it over to Ocean.java's step() method--and if so, how? Or, is there a better way to do this that I'm not aware of?

    Why do you think that this field has to be public?
    Arguably if there's some functionality that is tightly associated with this counted method, then it should be part of the same class.
    Alternatively, think about the counting variable. It should be with the thing that uses it.
    So if class A wants to invoke class B method c once, do something else, and then invoke c some more, then that counting is really more an aspect of A than of B, and in that case the state should be in A. In that case the field really counts the number of times that A has invoked B.c, not the number of times that B.c has been invoked overall. Maybe that's what you want.
    On the other hand if you really want to count the number of times that B.c has been invoked overall, then it's an aspect of B (or more likely an instance of B). In that case, rather than expose the counting state and the counted method, it would probably be better to create a new method d(). d() would invoke c(), doing something extra depending on the counting state. Make c() private. Like this:
    class B {
      private boolean c_has_been_called = false;
      public void d() {
        c();
        if (!c_has_been_called) {
          doWhateverYouNeedInThisCase();
          c_has_been_called = true;
      private void c() {
        // and c() does whatever it normally does
    }

  • Packages and Main method.

    What is the reason for the following. When you explicitly specify a package name for a class that contains the main method, why do you have to specify the fully qualified class name when you invoke the JVM?
    For example:
    package Exercises.Chp8.ExerciseTwo;
    import Exercises.Chp8.Interfaces.*;
    class Exercise2 implements myInterface {
         public void method1() {
              System.out.println("method 1 implemenmted");
         public void method2() {
                   System.out.println("method 2 implemenmted");
         public void method3() {
                   System.out.println("method 3 implemenmted");
    public class testExercise2 {
         public static void main(String[] args) {
              Exercise2 ex = new Exercise2();
              ex.method1();
              ex.method2();
              ex.method3();
    I would have to issue the following command:
    java Exercises.Chp8.ExerciseTwo.testExercise2
    for the java to run. If I specify java testExercise2, it displays a stack trace of the classLoader and an error messages reads regarding "wrong name". Can someone explain why this is?

    Hi,
    Please refer the following URL.
    It is very well documented in the java site.
    Please refer these URL's
    http://java.sun.com/docs/books/tutorial/java/interpack/packages.html
    http://java.sun.com/docs/books/tutorial/java/interpack/createpkgs.html
    http://java.sun.com/docs/books/tutorial/java/interpack/usepkgs.html
    http://java.sun.com/docs/books/tutorial/java/interpack/managingfiles.html
    Also please refer this URL, which has a discussion about packages.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=151016
    I hope this will help you.
    Thanks
    Bakrudeen

  • Should we use main method in JCO

    1/
    Should we use main method in JCO.. Connections does not seem to be simple java programes... so why should we use them??? just for the sake of running the programme?
    2/ And the below mentiond programme.. there is nothing called Connect1. Still the that class is created ..
    do not you thik it has to be <b>TutorialConnect1</b> object and constructor,
    import com.sap.mw.jco.*;
    public class TutorialConnect1 extends Object {
       JCO.Client mConnection;
       public Connect1() {
         try {
           // Change the logon information to your own system/user
           mConnection =
              JCO.createClient("001", // SAP client
                "<userid>", // userid
                "****", // password
                null, // language
                "<hostname>", // application server host name
                "00"); // system number
           mConnection.connect();
           System.out.println(mConnection.getAttributes());
           mConnection.disconnect();
        catch (Exception ex) {
          ex.printStackTrace();
          System.exit(1);
      public static void main (String args[]) {
        Connect1 app = new Connect1();

    Hi
    The main method is used in the learning stages to know how the program is executing.In real time scenarios we do not use the main method.If you use a main method it is just like a stand alone program to know the basics.
    In your program the class name and constructor name is different
    Make sure both are same or otherwise create an object with default constructor given by jvm and then call a method
    Thanks
    kalyan

  • Question of the day: In which Thread context does the main method run ?

    let's say, you create a JFrame in the main method:
    public static void main(String[] args)
    new MyJFrame();
    let's suppose, you construct the whole JFrame
    inside the constructor, which contains a lot
    of other Swing components, like JTree's and more.
    AND the JFrame calls setVisible(true) in its
    constructor.
    -> According to my knowledge, this won't work
    properly - it will function, BUT you will get one
    or two quite big exceptions (which usually start
    with a nullpointer exception, produced by the
    PLAF, but the whole stacktrace shows, that the
    the exception was thrown AND catched inside
    the Swing objects.
    Reason for this would be, that all operations
    after the "setVisible(true)" statement must be
    carried out in the eventdispatch thread, according
    to Swing rules.
    Now, as you can see by running the source below,
    the main() method always is processed in special thread,
    NOT the event dispatch thread - which produces the above behaviour.
    My Question:
    Wouldn't it have been easier to let the JVM
    process the main() methods right in the
    event dispatch thread ?
    Or:
    Why is the JVM designed to process the
    main() method in a special thread and not
    the Swing event dispatch thread ?
    opinions?
    Regards
    JPlaz / SnowRaver
    package Test1;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Frame1 extends JFrame
    public Frame1( final String title, int position )
    this.setSize(400,300);
    this.setLocation(position,position);
    this.setVisible(true);
    if( SwingUtilities.isEventDispatchThread() )
    System.out.println("Constructor of "+title+" is processed IN the event dispatch thread.");
    else
    System.out.println("Constructor of "+title+" is processed in ANOTHER than the event dispatch thread.");
    public static void main(String[] args)
    // First creation just from the startup thread context :
    new Frame1("first Frame", 60);
    // Now we let the second creation be done in the
    // eventdispatch thread context for sure :
    SwingUtilities.invokeLater( new Runnable()
    public void run()
    new Frame1("second Frame",120);

    Matt,
    it's been so long, I don't have the full answer in my head.
    This page on Adobe.com has an example that shows Flash 4
    mouse stuff (I'm Mr
    Vague today) when you scroll down. Your timelinme reference
    will be
    something like
    TellTarget(_Root, gotoAndPlay(50))
    Hopefully from that vagueness you can locate the right
    answer.
    Steve
    Adobe Community Expert: Authorware, Flash Mobile and Devices
    My blog -
    http://stevehoward.blogspot.com/
    Authorware tips -
    http://www.tomorrows-key.com

  • Main method in interfaces

    You can have static inner classes in interfaces,
    however main methods in such inner classes doesn't work.
    public interface V {
    int answer = 42;
    public static class testV {
    public static void main(String[] args) {
    System.out.println(answer + " V$testV.main");
    $ java V$testV
    Exception in thread "main" java.lang.NoSuchMethodError: main
    $ java -version
    java version "1.3.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
    Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
    Why is such a main method not useable when the inner class is within an interface, it works fine when an identical inner class is inside a class ?

    From
    http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java.h
    ml
    "A fully-qualified class name should be used."So, given that, and this, from section 6.7 of the Language Spec:
    "A member class or member interface M of another class C has a fully qualified name if and only if C has a fully qualified name. In that case, the fully qualified name of M consists of the fully qualified name of C, followed by ".", followed by the simple name of M"
    The java tool should locate nested classes (or member classes as stated here) through Enclosing.Nested.
    I still suggest two things:
    1 - This point is irrelevant since this is neither standard nor sanctioned (officially) behavior.
    2 - The java tool follows the VM model rather than the language model, and the VM model uses fully qualified to mean (from section 2.7.5 of the VM spec):
    "The fully qualified name of a class or interface that is declared in a named package consists of the fully qualified name of the package followed by "." followed by the simple name of the class or interface"
    There is no mention at all of nested classes, and the simple name is the classname without the package, which will be V$testV. That's why I contend that it uses a hybrid of VM naming and source naming - this is the only case where it is evident.
    Given that, I think that what the java tool does is correct (and consistent across platforms).

  • Multiple main methods

    Can we have more than one main method in a class/in various classes?if not why? and if yes then is that possible to call main() method with some other object nam,,,,say for eg...j.main()?
    As I'm new to java if anybody can explain me using an example as applicable it would be a better understanding for me over the concept

    It's not necessary to have main in a class and it's also ok to have main in multiple classes.
    You can also have multiple methods named 'main' in a class ( confusing, but legal ) as long as they follow the rules for overloading.
    The entry point for a Java program has to be a method with the signature
    public static void main ( String [] args )If you don't have this, you can't run that class. If you do, you can.
    The method has to be public because it will be called by the OS. It also has to be static since the object will not be instantiated till later; the runtime environment needs to be able to call the method without having to instantiate an object. The String array as parameter is to allow passing of command line arguments to the class.
    EDIT: A little slow there.
    Edited by: nogoodatcoding on Oct 16, 2007 5:48 PM

Maybe you are looking for