What happens when main(String[] args)

Hi techies,
I am trying to understand, "how the JVM invokes public static void main(String[] args)".
I had gone through JVM tutorial, and found that there are 2 different types of classloaders 1. bootstrap loader 2. user defined class loader.
I had gone through java api for class loader class. i did not find the method main(String[] args).
I am having confusion whether bootstrap loader calls main(String[] args)(or) userdefined classloader calles main(String[] args).
Why do we have to give String[] args as argument to main??
can you guys guide to understand this .
regards,
Krishna

Hi techies,
I am trying to understand, "how the JVM
invokes public static void main(String[] args)".
I had gone through JVM tutorial, and
found that there are 2 different types of
classloaders 1. bootstrap loader 2. user defined
class loader.
I had gone through java api for class
loader class. i did not find the method
main(String[] args).
I am having confusion whether bootstrap
loader calls main(String[] args)(or) userdefined
classloader calles main(String[] args).
Why do we have to give String[] args as
argument to main??
can you guys guide to understand this
regards,
Krishnawell, you won't find main(String[] args) in the docs for ClassLoader, since it's not a method on ClassLoader!
the bootstrap loader loads, verifies, prepares and initializes the class for which you pass the fully.qualified.name into the JVM, and looks for the static method on that class called 'main' which has a single argument, an array of Strings, and no return type ( I'm not 100% sure of that last part actually - I'll try it ) and begins a thread of execution on that method. from there, your program is run
we have to give an array of Strings in order to pass arguments into the program
it can't be a user-defined classloader that does this, because most of the time there won't be a user-defined classloader!

Similar Messages

  • Can't find file when use the main(String[] args) method

    I put a file under the DefaultDomain directory of Weblogic 11.1.1.5 on my local machine. Below is how I look up this file
    FileInputStream fis = new FileInputStream("input.xml");
    I started up the IntegratedWeblogicServer instance and I tested using the below 2 approaches.
    1) When I test a web service program using the below approach, it CAN'T find the input.xml file
    public static void main(String[] args)
    2) When I package it into an EAR file and deploy it onto the server then log into the admin console and use the test client approach then it's able to find the file
    How do I make it so it can find the file using #1 approach?
    Thanks

    That's how relative paths work, and it's nothing particular to Java.
    When you type ls input.xml or dir input.xml does it list the file, or give an error? If it lists the file, then it's in your current directory, and it will work if you run Java from that directory. If it gives an error, then that file is not in your current working directory, and Java won't be able to find it either.

  • When does the Java main(String args[]) method exit?

    Hi all,
    I and my colleagues want to know, when does the main() method exit?
    we wrote a small code as follows:
    import java.awt.*;
    public class Test {
    public static void main(String[] args) {
    Frame f = new Frame("hi");
    f.show();
    System.out.println("after show");
    and ran the program, in which case I could see the printed message "after show", but although there is no code after the System.out.println(), the Java virtual machine does not exit and waits for the Frame to close.
    My question is has the main method exited in this case? since it clearly shows that it does not have any more code to execute. Does java create the main method as a thread or as a process?
    regards,
    Harshad

    To make your application terminate you need to add code to cause the AWT thread to handle the termination. In your code, before f.show(), try:
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        dispose();
      public void windowClosed(WindowEvent e) {
        System.exit(0);
    });Now, at least you can click on the little "X" on the upper right-hand corner of the Frame (at least in Win95/98/NT) environments) to cause your application to receive a window closing event. It is also possible to add a menu with an option to exit; in that case I'd use an EventQueue to cause a window closing event to be sent.

  • How to call java with public static void main(String[] args) throws by jsp?

    how do i call this from jsp? <%spServicelnd temp = new spServicelnd();%> does not work because the program has a main. can i make another 2nd.java to call this spServiceInd.java then call 2nd.java by jsp? if yes, how??? The code is found below...
    import java.net.MalformedURLException;
    import java.io.IOException;
    import com.openwave.wappush.*;
    public class spServiceInd
         private final static String ppgAddress = "http://devgate2.openwave.com:9002/pap";
         private final static String[] clientAddress = {"1089478279-49372_devgate2.openwave.com/[email protected]"};
    //     private final static String[] clientAddress = {"+639209063665/[email protected]"};
         private final static String SvcIndURI = "http://devgate2.openwave.com/cgi-bin/mailbox.cgi";
         private static void printResults(PushResponse pushResponse) throws WapPushException, MalformedURLException, IOException
              System.out.println("hello cze, I'm inside printResult");
              //Read the response to find out if the Push Submission succeded.
              //1001 = "Accepted for processing"
              if (pushResponse.getResultCode() == 1001)
                   try
                        String pushID = pushResponse.getPushID();
                        SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                        StatusQueryResponse queryResponse = sp.queryStatus(pushID, null);
                        StatusQueryResult queryResult = queryResponse.getResult(0);
                        System.out.println("Message status: " + queryResult.getMessageState());
                   catch (WapPushException exception)
                        System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
                   catch (MalformedURLException exception)
                        System.out.println("*** ERROR - MalformedURLException (" + exception.getMessage() + ")");
                   catch (IOException exception)
                        System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
              else
                   System.out.println("Message failed");
                   System.out.println(pushResponse.getResultCode());
         }//printResults
         public void SubmitMsg() throws WapPushException, IOException
              System.out.println("hello cze, I'm inside SubmitMsg");          
              try
                   System.out.println("hello cze, I'm inside SubmitMsg (inside Try)");                         
                   //Instantiate a SimplePush object passing in the PPG URL,
                   //product name, and PushID suffix, which ensures that the
                   //PushID is unique.
                   SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                   //Send the Service Indication.
                   PushResponse response = sp.pushServiceIndication(clientAddress, "You have a pending Report/Request. Please logIn to IRMS", SvcIndURI, ServiceIndicationAction.signalHigh);
                   //Print the response from the PPG.
                   printResults(response);
              }//try
              catch (WapPushException exception)
                   System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
              catch (IOException exception)
                   System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
         }//SubmitMsg()
         public static void main(String[] args) throws WapPushException, IOException
              System.out.println("hello cze, I'm inside main");
              spServiceInd spsi = new spServiceInd();
              spsi.SubmitMsg();
         }//main
    }//class spServiceInd

    In general, classes with main method should be called from command prompt (that's the reason for main method). Remove the main method, put the class in a package and import the apckage in your jsp (java classes should not be in the location as jsps).
    When you import the package in jsp, then you can instantiate the class and use any of it's methods or call the statis methods directly:
    <%
    spServiceInd spsi = new spServiceInd();
    spsi.SubmitMsg();
    %>

  • What happens when multiple users access the same servlet?

    Do the users share all the same resources? Or is a new process generated for each user? I have a servlet that builds a string to return to the user and I only have myself to test, so I can't really see what happens when many users access the servlet. Is there a possibility that the string will get screwed up, like when dealing with multiple threads, or do all the users get their own resources and I don't have to worry about that?

    huh? if you can point a test servlet at it, you can point a browser at it (even if the servlet does not serve html it will run)
    try pasting the servlet URL into a web browser
    refreshing multiple browsers repeatedly could provide a manual test

  • What happens when Time Machine starts to fill up a drive?

    Using Time Machine on a partitioned External HD has been an absolute snap! I love the app. My main disappointment with it is that it has no literature on HOW it works, and no real ways for me to set different controls for it other than on and off.
    My question is that what happens when a drive starts to get full? I have about 30 gigs left on the partition, and I am wondering what Time Machine is going to do. Does it just delete the oldest material, or does it simply fill up and tell me to look at everything on there and decide to clear it all off. I hate that I don't know what will happen.
    -Jon

    From what I've read (I've not gotten a drive full so I can't speak from experience), when the TM drive gets full, it will notify you that it's going to start deleting the oldest backups to make space for the new ones. This general behavior is mentioned in the Mac Help for Time Machine, though it makes no mention about notifying you before it deletes the old backups, so I'm not sure about that part.

  • What happen when an error occurs during Snapshot-Refresh?

    Hi,
    I would like to know what happens, when an error occurs
    during a refresh (COMPLETE-REFRESH) of a snapshot?
    Is there a possibility for exception-handling??
    During a complete refresh the data in the snapshot will be deleted an the requested new from the master-side. Now when
    an error occurs during the refresh what happens with the "old" data of the snapshot??? Will it be lost?
    Thanxx
    Schoeib

    Each thread has its own error state. To get the results for a thread (including error result), you need to have a wait step which waits for it. If a thread has an error and you wait for it, you will get the error at the wait step that waits for it.
    If your main thread has an error and you want some worker thread to exit, you should add code to the cleanup of your main thread's sequence which signals the worker thread to exit (you should already have some sort of mechanism for signaling the worker thread to exit (there are many ways to do this, for example, a boolean variable passed by reference to the new thread's sequence, or a TestStand notification).
    If your main thread is getting an error, but is stuck inside a step, that problem is probably specific to something your code is doing, that is not the normal behavior of TestStand. You will need to provide more details or an example sequence in order for us to better understand what is happening.
    Hope this helps,
    -Doug

  • Standard input - main(String[] args) -- how?

    In eclipse, how do I feed the main with values?
    public static void main(String[] args) {
           System.out.println("Enter value: ");
           args =
        if (args.length != 1) {
    ...Thanks,
    george

    You mean basically command line arguments?
    Look in the run menu. For every run event there's a form that specifies how to invoke the program. Somewhere in there you can specifiy the command line arguments. I can't recall right now but I can look it up if you can't find it.
    Standard input is a completely different thing from command line arguments. Standard input, from the java point of view, is what comes in on System.in.

  • Private static void main(String args[]) ... ?????

    even if the main method is declared
    private static void main(String args[])
    //Code Here
    it works fine..can somebody explain the reason behind?

    hi rkippen
    so u mean, since the JVM is calling the main it can
    break all kinds of access specifiers to any class..am
    i right?
    This could be the case.
    However, I tried using 1.4.1 with no development environment (just java.exe) and it gave the following error:
    C:\>java MainTest
    Main method not public.
    So, your development environment might be the cause (e.g. what you use to program your code (e.x. JBuilder)), or the Java version.
    Your development environment might be using reflection to get around Java accessibility checks. For debugging purposes, it is possible to use reflection to obtain refereneces to private methods/fields and invoke those methods and access those fields.
    E.g.
    Vector v = new Vector();
    Field f = v.getClass().getDeclaredField("elementCount");
    f.setAccessible(true); // this is the trick
    f.set(v, new Integer(100));In the presence of a security manager, the setAccessible method will fire a "suppressAccessChecks" permission check.

  • What happens when an iPod is synchronized with an iTunes library that is bigger than the available space on the iPod?

    What happens when an iPod is synchronized with an iTunes library that is bigger than the available space on the iPod? I did this some time ago. On screen was shown available space somewhat less than 120 GB, but maybe somewhere between 10 and 20 GB more in the library. I had to get the iPod updated anyway, so I did proceed. However, afterwards the total content of the library was only about 110 GB. Now I wonder what did actually happen. Was the first sign only corrected for double copies of the same files or lost files or where files deleted from iTunes? And if files where deleted from iTunes, were they also deleted from my computer?

    Same as you would if you bought a pc; copy everything from your old computer to your new one.  Then you can just sync everything from the new computer, as you did with the old one.

  • I want to change my Apple ID because I have a new email address, but what happens when someone tries to facetime me using my old Apple ID?

    I want to change my Apple ID because I have a new email address, but what happens when someone tries to facetime me using my old Apple ID? Will they still be able to contact me on facetime using my old Apple ID?

    Not if you change the ID.  You would need to give them the new address.

  • I recently downloaded Parallels 9 to my imac so I could install Windows 7 Home Premium and had no trouble everthing is working fine the only question I have is is there a benefit to migrating the 2 together and what happens when I do Thanks.  Ricco

    I recently downloaded Parallels 9 to my imack so I could install Windows 7 Home Premiumwith no problem and everthing is working fine, and I was thinking of Migrating the 2 2 and was wondering what benefits there would be and what happens when I do.

    Windows 7 will peer down through the VM and remember what hardware the VM is installed on. Migrate the VM to different Mac hardware, and on first boot, Windows 7 will advise you that you are not using genuine Microsoft Windows. It will then treat you as though it believes you misappropriated it.

  • Time Machine backup created on Mac with a large hard disk. What happens when restore to MacBook Air with small SSD drive?

    What if a Time Machine backup was created on a Mac with a large hard disk, e.g. 500GB iMac - and I buy a new MacBook Air with a small SSD hard disk e.g 128GB. What happens when I need to use the larger Time Machine file to set up the new MacBook Air? What happens to all those files that can't fit on the smaller SSD drive?

    It is not the HD size, but rather the size of the data it contains. If you right-click your 500GB drive and select "Get Info" you can see how much is actually being used.
    Naturally if you are using more space than the new drive has, then you have to make some choices about what you want to keep and what you want to keep archived.
    I don't know what options are available but you may simply have to do a manual restore of files you want, in groups.

  • What happens when I restore data to a non-factory set iPhone?

    Okay, another iCloud question. What I did was basically delete a game, start a new one, and now I want my old game back (saved to ICloud). What happens when I restore full data to a non-factory set iPhone? Will it overwrite current data? Will it delete everything? I just want to know, I'm such an iOS noob. :-/

    A restore is all or nothing.
    If a backup is restored to the device, ALL data currently on the device is wiped and replaced with the data from the backup.
    Restoring a backup to get one saved game back seems rather extreme and silly.

  • What happens when HTTPS communication fails during certificate check?

    Hello Experts,
    I have a scenario where a Bapi functionality(server proxy) is exposed as a webservice .
    So scenario will be SOAP -> XI -> Proxy (calls a BAPI)
    Here we are going to use HTTPS (SSL).
    I would like to know :
    What happens when a check for certificate validation fails in XI? It may be due to invalid certificate, expired certificate or a request from unauthorised user-
    - Will it be raised as a exception and we need to do some  configuration to inform it back to Sender?
    - Will the message fail in Moni with red flag ?
    - Alerts will be created ?
    Please share your experiences and expert sugestions.
    Thanks in Advance!!
    Regards,
    XI Queries.

    Hi Abhishek,
      Thanks for the reply. I will keep this in mind and design the scenario & error handling accordingly.
    Appropriate points awarded
    Kind regards,
    Xi Queries.

Maybe you are looking for