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

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

  • Cant call simple method from main method

    hi guys, this maybe a stupid question, im a newbie to java programming. Im trying to call the method calculateArea in main method and its not working.
    Any ideas?
    Thanks.
    package project1;
    public class makePurchase {
        public int calculateArea(int width, int height){
                int myArea = width * height;
                return myArea;
        public static void main(String[] args){
            int vTestResult = calculateArea(1,3);
            System.out.println("The total is:" +vTestResult);
    }

    jverd wrote:
    mishmash wrote:
    Is there a easy way of determining if the method should be static? maybe only if your using a math class and not using the method in any other class?Static means associated with the class as a whole, not with any particular instance. If your method doesn't use or set any state that is part of individual instances, it may be a candidate to be static. Another difference is that static methods cannot be overridden. That is, you can't defer until runtime which class' implementation of a static method to call.
    public class Person {
    private static int numPersonsCreated;
    private String name;
    private Date birthdate;
    public int calculateAgeInYears () {
    // use birthdate to calculate age
    public static int getNumPersonsCreated() {
    return numPersonsCreated;
    }Here, the calc method cannot be static, since it uses the birthdate field that is particular to each Person object created. The number of Person objects created by your program, however, is not associated with any particular Person object, but with the Person class as a whole, so it can be static.Perhaps to expand a bit more...
    Highly reusable methods are candidates for static such as utility methods that may be used multiple times.This is true if this methods API remains consistent and does not care a bout the surrounding class. Usually such a method would require all its fields to be provided by parameters or as static members as any instance variables would not make this methods reusable.
    in jverd's example you can see that many related classes may be interested in finding out how many people have been created and they may wish to know so at the same time. It certainly makes sense to provide such a method as static as it does not change and most likely never will. More importantly all interested classes now are assured of seeing the exact same method because that is what static is: It exposes the same to all interested parties.
    Edited by: Yucca on Oct 19, 2009 6:35 AM

  • Access Specififer for main Method

    Dear all,
    In JDK1.2.2 if I give private access modifier to the main method,its working.
    But in JDK 1.3,it displays "Main method not public".
    what could be the reason?

    Please don't post the same question multiple times. It's annoying.
    Please don't post the same question multiple times. It's annoying.
    Please don't post the same question multiple times. It's annoying.
    Please don't post the same question multiple times. It's annoying.
    http://forum.java.sun.com/thread.jsp?thread=341247&forum=33&message=1404079
    http://forum.java.sun.com/thread.jsp?thread=341187&forum=33&message=1403858
    http://forum.java.sun.com/thread.jsp?thread=341186&forum=33&message=1403857
    Especially within the same Forum.

  • 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.

  • Multiple Main Classes

    Hello all,
    I have created a program that has reached testing phase.
    My method of deployment of the application is jar files.
    If you have multiple main classes in the application,
    how can you access all of them?
    EX. 1)settings file
    2)Save file
    These are just random access points.
    Im using the current NetBeans.
    When I create a jar through this it only allows me to specify one main class at a time
    Thanks alot!

    iwinstont wrote: If you have multiple main classes in the application,
    how can you access all of them?
    One way might be to have the first main() be a floating toolbar that launches the other applications. This might work well for an 'office' style suite with buttons on the toolbar for spreadsheet, word processor, database etc.
    Perhaps a better (and more common) way to go would be to put each main() in its own jar, add all the common classes to an 'our-api.jar', then add that jar to the Class-Path attribute in the manifest of each of the main() jars.
    Java webstart is also a way to select particular main()s out of one jar, but even then, it sound as if the single jar should be divided into a number of jars.

  • Com.sun.tools.javac.Main: method compile errors

    I had a working web project the other day, and something happened that caused every page to start throwing this error:
    # javax.servlet.ServletException: com.sun.tools.javac.Main: method compile([Ljava/lang/String;Ljava/io/PrintWriter;)I not found
    # at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:779)
    # at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    # at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
    # at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
    # at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
    # at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
    # at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:978)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
    # at com.mayco.mvc.MVCServlet.processRequest(MVCServlet.java:426)
    # at com.mayco.ldap.MayServlet.service(MayServlet.java:415)
    # at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
    # at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
    # at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
    # at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
    # at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    # at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
    # at com.mayco.cy.filter.AuthenticateFilter.doFilter(AuthenticateFilter.java:167)
    # at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    # at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
    # at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
    # at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
    # at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
    # at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
    # at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
    # at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
    # at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
    # at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
    # at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
    I tried setting up a clean environment (server, EAR, web project), but haven't been able to re-solve the problem I had with the original project yet.  If I could get a starting point to look for how to solve this type of error it would be greatly appreciated!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I checked my JDK compliance (1.4) and the installed JREs (Standard VM; WebSphere v5.1 EE JRE; C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51_stub\java\jre)
    I did notice that it was using the JRE System LIbrary [WebSphere v5.1 JRE] and I changed it to the WebSphere v5.1 EE JRE like I think it should have been...
    and the web server startup begins with:
    *** Starting the server ***
    ************ Start Display Current Environment ************
    WebSphere Platform 5.1 [BASE 5.1.0.3 cf30412.02] [JDK 1.4.1 b0344.02] running with process name localhost\localhost\server1 and process id 2692
    Host Operating System is Windows XP, version 5.1
    Java version = J2RE 1.4.1 IBM Windows 32 build cn1411-20031011 (JIT enabled: jitc), Java Compiler = jitc, Java VM name = Classic VM
    was.install.root = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51
    user.install.root = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51
    Java Home = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51\java\jre
    ws.ext.dirs = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/java/lib;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/classes;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/classes;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/ext;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/web/help;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime;C:/Program Files/IBM/SQLLIB/java/db2java.zip;C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1.2/wstools/eclipse/plugins/com.ibm.etools.webservice_5.1.2/runtime/worf.jar
    Classpath = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/properties;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/properties;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/bootstrap.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/j2ee.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/lmproxy.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/urlprotocols.jar;C:\WebSphere\properties;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\bcprov-jdk14-139.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\config.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\spi4jStub_2.5.4.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES100J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES110J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES120J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES200J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XTCP211.jar;C:\spi4j2.5.4_J2ee1.4\Demo\log4j-1.2.8.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\spi4jCore_2.5.4.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\axis-1.1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\xmlParserAPIs-2_2_1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\jaxrpc.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\wsdl4j.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\fsgWsif1.1.jar;C:\spi4j2.5.4_J2ee1.4\Demo\commons-logging.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\tools.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-pool-1.2.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\saaj.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-beanutils-core.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-collections-3.1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-discovery.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-lang-2.1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\connector.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\FEDRWSCHECKSTATUSAxisInfo.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\fscontext.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\IFSClassLoader1.2.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\j2ee1.4.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\jca.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\jta.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\mail.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\providerutil.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\qname.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\soaprmi-1_1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\xalan.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\xercesImpl-2_2_1.jar;C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1.2/wstools/eclipse/plugins/com.ibm.etools.websphere.tools.common_5.1.1.1/runtime/wteServers.jar;C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1.2/wstools/eclipse/plugins/com.ibm.etools.websphere.tools.common_5.1.1.1/runtime/wasToolsCommon.jar
    Java Library path = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/bin;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/java/bin;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/java/jre/bin;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\eclipse\jre\bin;.;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\eclipse\jre\bin;C:\oracle\product\10.2.0\client_2\bin;C:\oracle\product\10.2.0\client_1\bin;Y:\oracle\ora92\BIN;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\CA\SHARED~1\SCANEN~1;C:\PROGRA~1\CA\ETRUST~1;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Rational\common;C:\Program Files\Rational\ClearCase\bin;C:\Program Files\IBM\SDP70\jdk\bin
    ************* End Display Current Environment *************

  • 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?

  • Multiple Main Table Question

    I am new to MDM 7.1 & Multiple Main Tables. I have a very basic questionu2019
    My Requirement is that I have to keep Two Main Tables,
    1.      Manufacturer Parts Master Table and the key is Manufacturer Name + Manufacturer Part No (Two fields)
    2.      I  have another Main Table  called Manufacturer Parts Table and key will be Manufacturer Name + Manufacturer Part No (Two fields)
    My requirement is  that when I load data in to the 2nd Main table (Manufacturer parts Table) I have to validate against the Master table (Manufacturer Parts  Master Table) with the key combination of Manufacturer Name + Manufacturer Part No  and that this key combination must exists in the 1st table.( Manufacturer Parts Master Table.). If  not then it is an error.
    I know we can use the 1st table as lookup main table for the 2nd table but do we need to combine the key fields Manufacturer Name + Manufacturer Part No for both the tables to validate against the Manufacturer Parts Master table with the same key combination?.
    Anyone explains how I can do this?
    Also, Qualified tables still exits in MDM 7.1? OR we have to use  Tuples?

    Hi,
    1. Manufacturer Parts Master Table and the key is Manufacturer Name + Manufacturer Part No (Two fields)
    In Console: Say your 1st main table has Manufacturer Name + Manufacturer Part. No two fields which are Display fields. For this 1st Main table you should have your Edit Key mapping = Yes.
    In Import Manager: Your Remote Key in your MDM import Manager should be mapped with combination of these two fields using Partition Concept with some delimiter say ,
    e.g. for 1 record in your 1st main table when you right click on your Edit key mapping using MDM data Manager it has values as:
    RemoteSystem Key
    ABC MANF1,123
    So here Key is combination of Manufacturer Name + Manufacturer Part No (MANF1,123) which has delimiter ,
    2. I have another Main Table called Manufacturer Parts Table.
    In Console: For this 2nd Main table first of all, you will create a Field of type Lookup Main which is lookup to 1st main table say X. You will have some other field too in 2nd main table which is Display field and using it you can import data.
    In Import Manager: For 2nd Main table, your source fields again should be combination of Manufacturer Name + Manufacturer Part No using partition field concept with delimiter say , and map this Partition field here with field X which is lookup to main table. when you will do this you will see all your source values for this partition field gets mapped automatically for the records which are present in 1st main table and if there is any value which is not mapped it means that that manufacturer name + manufacturer Part no does not exist in 1st main table.
    You must set this property in Import Map, if you are importing data through Import server by right clicking on target mapped field X Set MDIS Unmapped Value handling = Fail which will take care if record exists in 1st main table then only record imported in 2nd main table else give error. As if record exists in 1st main table then while importing data through 2nd main table his value automatically gets mapped.
    Also, Qualified tables still exits in MDM 7.1? OR we have to use Tuples?
    For most of standard Master's e.g. Material SAP Note 1355137, Customer SAP Note 1412742: Tuple has been replaced using  Qualified table. But if you want, you can model data as per your requirement. You can still use Qualified table if business demands.
    Regards,
    Mandeep Saini

  • Object life in main method after frame created

    hi
    i'm having a slight problem with the life of an object i'm creating in the main method of my application.
    i have a JDesktopPane that is initialised in the main class's main method and constructor. within the main method i also add the first internal frame to the desktop.
    after the user completes the details of the first frame, another is called (from this first frame) and the first frame is disposed.
    the problem is that although all subsequent internal frames added to the desktop outside the main class, they are garbage collected with no problems (i'm using a profiler), however the first frame and the frame created from that first frame are never collected due to the reference maintained in the main class. i've tried adding the creation of these frames outside the main class but given that these methods are called from main the reference is still maintained.
    is there any way to create those first 2 frames without the reference being maintained in the main class such that they become elegible for garbage collection? do i have it all wrong perhaps and my approach is bad?? any help would be greatly appreciated.
    thanks heaps.
    Takis

    hi
    thanks for your reply.
    i tried that and it didn't work. the instance of that first internal frame is still there.
    i really am at a loss with this one.
    any other suggestions would be greatly appreciated.
    Takis

  • Need help - how to run this particular method in the main method?

    Hi all,
    I have a problem with methods that involves objects such as:
    public static Animal get(String choice) { ... } How do we return the "Animal" type object? I understand codes that return an int or a String but when it comes to objects, I'm totally lost.
    For example this code:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            TestAnimal ta = new TestAnimal();
            ta.get(); // error
            // doing Animal a = new Animal() is horrible... :(                   
        public static Animal get(String choice) {
            Scanner myScanner = new Scanner(System.in);
            choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }Out of desperation, I tried "Animal a = new Animal() ", and it was disastrous because an interface cannot be instantiated. :-S And I have no idea what else to put in my main method to get the code running. Need some help please.
    Thank you.

    Hi paulcw,
    Thank you. I've modified my code but it still doesn't print "roar" or "trumpet". When it returns a Lion or an Elephant, wouldn't the soundOff() method get printed too?
    refactored:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            Animal a = get();
        public static Animal get() {
            Scanner myScanner = new Scanner(System.in);
            System.out.println("Meat eater or not?");
            String choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }The soundOff() method should override the soundOff(); method in the interface, right? So I'm thinking, it should print either "roar" or "trumpet" but it doesn't. hmm..

  • How can i call a main method  from a different class???

    Plzz help...
    i have 2 classes.., T1 and T2.. Tt2 is a class with a main method....i want to call the main method in T2......fromT1..is it possibl..plz help

    T2.main(args);

  • How to add a code TestIfElse(10) to the Main method of the Program.cs class?

    How to add a code  TestIfElse(10) to the Main method of the Program.cs class?
    Here is my code and I have copied from the Wiley book for Microsoft certification page 14,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ifelse_Statement
        class Program
            static void Main(string[] args);
            TestIfElse(10);
            public static void TestIfElse(int n);
            if(n < 10)
                     Console.WriteLine("n is less than 10");
             else if(n < 20)
                    Console.WriteLine("n is less than 20");
             else if(n < 30)
                Console. WriteLine("n is greater than or equal to 30");
    Here is the error list I am getting,
    Error 1      Method must have a return type        C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 13
    switch_Statement
    Error 2
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 24
    switch_Statement
    Error 3
    Method must have a return type C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 9
    ifelse_Statement
    Error 4
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 20
    ifelse_Statement
    Error 5
    Invalid token 'if' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 9
    ifelse_Statement
    Error 6
    Invalid token '10' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 7
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 8
    Invalid token '(' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    18 35
    ifelse_Statement
    Error 9
    A namespace cannot directly contain members such as fields or methods
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    20 10
    ifelse_Statement
    Error 10
    Type or namespace definition, or end-of-file expected
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    30 1
    ifelse_Statement
    Error 11
    The type or namespace name 'n' could not be found (are you missing a using directive or an assembly reference?)
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    16 12
    ifelse_Statement
    Error 12
    'System.Console.WriteLine(string, params object[])' is a 'method' but is used like a 'type'
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    18 26
    ifelse_Statement

    static void Main(string[] args){
    TestIfElse(10);
    public static void TestIfElse(int n)
    if (n < 10)
    Console.WriteLine("n is less than 10");
    else if (n < 20)
    Console.WriteLine("n is less than 20");
    else if (n < 30)
    Console.WriteLine("n is greater than or equal to 30");
    Fouad Roumieh

  • Class extending a Frame with main method in it - how do I use the methods?

    Howdy.
    Having a problem.. I want my "main" class, ie. the class with the main method in it to extend a Frame class.. because the main method is static, I can't use Frame's methods.
    What's a trick to get around this ? I am making a deliberate design decision to extend the Frame class, because I thought it was.. well.. better. I could always just create a Frame object and utilise it.. but from little things I've read and seen it's better to extend it.
    When I use Forte to make a Frame program it sets up a constructor/etc. for the main class and then it does something akin to this (the class is called MazeGenerator) :
    public static void main(String args[]) {
    new MazeGenerator().show();
    What does "new MazeGenerator().show();" do when it's not being associated to an object handle ??
    Ta.
    - Scutt.

    Create an instance of the frame in main then the constructor can control it. Or you could add an init method or something:
    class MyFrame extends Frame {
    public static void main (String [] args) {
    MyFrame frame = new MyFrame();
    frame.init();
    You don't necessarily have to have a reference to an Object in order to create one. All the work can be done in the constructor (something I'm not really fond of however)

  • Calling main method in another class using command line arguements

    Hi
    My program need to use 4 strings command line arguments
    entered in Project properties/Run/Application Parameters
    java programming for beginners // arguments
    The program needs to call main in the second class 4 times using argument 1 the first call, argument 2 the second call on so on.
    So the output wil be
    java
    programming
    for
    beginners
    import java.lang.*;
    public class First extends Second{
      public static void main(String[] args) {
        for(int i = 0; i < args.length; i++){
           Second.main(args); // Error I think
    import java.lang.*;
    public class Second {
    public static void main(String[] args){
    System.out.println(args[0]);
    "First.java": Error #: 300 : method main(java.lang.String) not found in class Second at line 6, column 15
    I am only a beginner with little knowledge of java so can the code be as basic as possible

    Your style looks quite bad for starters..... Hows
    this://import java.lang.*; /* NOT NEEDED */
    public class First extends Second{
    public First(String s) {
    super(s);
    public static void main(String[] args) {
    for(int i = 0; i < args.length; i++){
    new First(s);
    public class Second {
    public Second(String s)
    System.out.println(s);
    NOT NEEDED:
    public static void main(String[] args){
    System.out.println(args[0]);
    }My question to you: Do you understand why my code
    works? (does it do what you want?)I think since this is some kind of lesson, the OP have to implement some way to use the main method of the Second class as it is, that is, with String[] args. I think this lesson is interesting exactly because of this requirenment. But, anyway, I don�t know, that is just my assumption...

Maybe you are looking for

  • Copy and replace sequences

    Hi! I have a running sequence containing a main loop. Depending on input from user, a given subsequence (in separate file) is called and when it has executed we go back to the main file. From the main loop I have made it possible to run a batch file

  • Genuine SQL sent to database

    Hi, I'm new with ODI and I'm using a lot of variables, when I run the interface or a package the Operator tool only show me the "logic" SQL (with all the variable names), It's possible to see the exactly SQL sent to database, with all the content of

  • Can I use addAuditTrailEntry(String message, Object detail) in a jar file?

    I have a lot of jar libraries that I need to import into my BPEL process. It's not practical for me to copy all the code flatly into an embedded java / bpelx. How can I call the addAuditTrailEntry method inside the classes in my jar file? e.g. I impo

  • PDF Maker

    Is Acrobat 8.1.0 compatible with Windows 7?  I cannot get the PDF Maker to work nor can I print to Adobe.

  • When I install Flash Professional CC 2014, I got the Error: DW039: Failed to load deployment File

    When I install Flash Professional CC 2014, I got the Error: Exit Code: 16 Please see specific errors below for troubleshooting. For example,  ERROR: DW039 ...  -------------------------------------- Summary -------------------------------------- - 0