Static private void main(String[]) works (?!)

Did anyone knew that?
try yourself!!
public class Foo {
static private void main (String[] bla) {
   //anything
}there's even a bug!! And Sun choose not fix it:
http://developer.java.sun.com/developer/bugParade/bugs/4252539.html
I'd like to hear what you folks think about this...
IMO: fuc* encapsulation!

No, I haven't done the certification exam and I have no plans to. But the answer to that question isstatic public void main (String[] bla)and the fact that other versions happen to work doesn't matter either theoretically or practically. Bugs that appear in certain implementations of Java shouldn't matter.

Similar Messages

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

  • 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();
    %>

  • Why can't created an object in the "public static void main(String args[])"

    Example:
    public Class Exp {
    public static void main(String args[])
    new Exp2();-------------> To Occur Error
    Class Exp2 {
    public Exp2()

    You can't create an inner class within main, because
    it is a static method. Inner classes can only be
    created by true class methods.This is not correct. You can create an inner class object in a static method. You just have to specify an outer class object that the inner class object should be created within:
    Exp2 exp2 = new Exp().new Exp2();

  • Standard/common handling void main(String argv[])

    i would like to have a parent class to handle the void main(String argv[]), but I can't instantiate my child class because I dun know it's name.
    any way to get that? or any alternative way to handle the void main(String argv[]) in common? million thanks.
    eg:
    public abstract class parent {
    public static void main(String argv[]){
    // i need to know which child is been run by java childclass
    // so that I can instantiate a new object and call the run method
    public abstract void run();
    public class child1 extends parent{
    public void run(){}
    public class child2 extends parent{
    public void run(){}
    }

    Class.forName(name).newInstance();
    provided I know name=what, right?
    how do I know ppl calling using
    java child1?
    or
    java child2?
    both will go use same
    public static void main(String argv[])
    in parent class.

  • Public static void main

    Hi all
    whether public static void main(String[] a) will execute

    Clem1986 wrote:
    it's an incomplete sentence, it's just a clause; possible endings:
    whether public static void main(String[] a) will execute remains a mystery.*
    whether public static void main(String[] a) will execute is determinable.*
    whether public static void main(String[] a) will execute is propesterous to ponder.*
    whether public static void main(String[] a) will execute is heretical in nature.*
    whether public static void main(String[] a) will execute is not a sentence.*
    Or start clauses,
    _'Tis idiotic to wonder_ whether public static void main(String[] a) will execute.whether public static void main(String[] a) will execute or not, I'm still getting out of my skull tonight

  • Default access specifiers for void main()

    I m having one problem that if i make void main(String a[])
    syntax like private static void main(String args[]) and run using jdk1.4 it will run. So my question is that why this is possible still i making main() private. If i run it in jdk1.5.0 then it give error main is not public so what was the problem with the jdk1.4?

    Congratulations on your first post after almost 2
    years. ?The most impressive thing is that he remembered his
    password ...I posted by first message in 2004, I only used this account to read the bugdatabase and vote on bugs prior to that. So I don't see anything strange in having an account, and not using the forums.
    Kaj
    Ps. But I'm also impressed by the fact that he remembered the password, I had an account which I created in -97, but I forgot the password to that account :(

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

  • 2 errors: static context & java.lang.String

    I get the following 2 errors when I try and compile my code. What do I need to do in order to fix this problem?
    Any help appreciated.
    C:\>javac DraftD.java
    DraftD.java:54: non-static variable MAXIMUM cannot be referenced from a static context
    if(temp <= MAXIMUM)
    ^
    DraftD.java:54: operator <= cannot be applied to java.lang.String,int
    if(temp <= MAXIMUM)
    ^
    2 errors
    import java.io.*;
    import java.util.*;
    public class DraftD
    final int MAXIMUM = 20;
    public static void main(String[] args) throws IOException
    try
    Runtime program = Runtime.getRuntime();
    Process proc = program.exec("cmd.exe /c C:/ntpq.exe -p >C:/answer.txt");
    try{
    proc.waitFor();
    catch (InterruptedException e){}
    catch(IOException e1)
    int i = 0;
    BufferedReader br = new BufferedReader(new FileReader("C:/answer.txt"));
    String line = "";
    while ((line = br.readLine()) != null)
    i++;
    if(i==3) break;
    br.close();
    if(i==3)
    StringTokenizer st = new StringTokenizer(line," ");
         int k=1;
    while(st.hasMoreTokens())
         String temp = st.nextToken();
    if(k==2){
              String secondToken = temp;
    if(temp <= MAXIMUM)
              {System.out.println("less than Max");}
         k++;
    else System.out.println("less than 3 lines in file");
    System.exit(0);
    }

    You should use Integer.parseInt(temp); to convert temp to an int
    Because MAXIMUM is not static, every DraftD object will have one, that's the way properties work.
    main() however is static, and so there is only one between all the DraftD objects.
    It is a bit harder to explain with main(), but suppose we did this:public class ABC
      public int x;
      public static int getX()
        return x;
    ABC a = new ABC();
    ABC b = new ABC();
    a.x = 1;
    b.x = 2;
    int result = ABC.getX();should result be 1 or 2? it doesn't know which x to get, so the compiler complains.
    if MAXIMUM is a constant, you should make it public static final

  • Void mains

    Please help, I have just about had enough of this code for my lifetime.
    I am trying to get a timer running in the background that fires an event every minute.
    I had the code:
    public class Apl
        public static void main(String argv[])
            boolean gui = true;
            int portNum = 110;
            //server object
         POP3Server server;
            //user mailset
            Set mailSet = new HashSet();
            .  //does some stuff
    }So i try and modify it to do this
    e.g
    public class Apl
        public static void main(String argv[])
            boolean gui = true;
            int portNum = 110;
            //server object
         POP3Server server;
            //user mailset
            Set mailSet = new HashSet();
            .  //does some stuff
            TimerTask fetchMail  = new FetchMail();
            Timer timer = new Timer();
            timer.scheduleAtFixedRate(fetchMail, 1, 10000);
        public class FetchMail()
            System.out.println("HI");
    }In the hope it would print HI every 10 seconds. But no.
    Any ideas? Thanks

    Still having problems with this timer. I have had a rethink about what I want to do with it and am still having problems.
    private String makeMailDrop()
            String users = "";
            String thisLine;
            //DOES SOME STUFF HEREThen from another class
    public POP3Server(int port, POP3ServerFrame frame, Set mailSet)
             //vars
              this.port = port;
              this.frame = frame;
              this.mailSet = mailSet;
              gui=true;
                    uidlArr = new String[100];
                    counter = 1;
              //timer
              //makeTimer();
              output("Initializing..this may take a while..\n");
                    output("Welcome To Highway42 POP3 Server. \n\n");
                    makeMailDrop();
                    TimerTask loopMD = makeMailDrop();
                    Timer timer = new Timer();
                    timer.scheduleAtFixedRate(loopMD, 1, 10000);The problem being that the types are different, loopMD is a TimerTask and I am trying to assign it to a methiod that returns a string.
    so I tried TimerTask loopMD = makeMailDrop();and then it says it cant find makeMailDrop().
    How would I implement this so on the timer it runs makeMailDrop()
    Thanks

  • Void main

    Hi,
    Could you please let me know what is wrong with this line please:
    Employee test= new Emp_FT(getId,getFirstName,getLastName,getEmployeeAge,getFullTime);
              public static void main(String args[])  
                         Employee test= new Emp_FT(getId,getFirstName,getLastName,getEmployeeAge,getFullTime);                 
         class Emp_FT extends Employee{
             private String fulltime;
            public Emp_FT( int id, String firstName, String lastName, int employee_age, String address, String ft )
                      super( id, firstName, lastName, employee_age, address);
                        this.fulltime = ft;
                    }Thanks
    Andonny

        public ArrayList parseFile(File input)
            String buffer = null;
            ArrayList data = new ArrayList();
            try
                FileReader fileIn = new FileReader(input);
                BufferedReader bufferIn = new BufferedReader(fileIn);
                buffer = bufferIn.readLine();
                while (buffer != null)
                        //write code here depending on how you arrange your file
                        //store values for name and id in local variables then create
                        //a new employee, if it is a fulltime employee then
                        Emp_FT emp = new Emp_FT(id, first, last, ssn, etc);
                        //or you could create an empoyee first then add the info
                        Emp_FT emp = new Emp_FT();
                        emp.setId(something);
                        emp.setFirstName(something);
                        //then add this employee to your list before proceeding
                        data.add(emp);                    
                    buffer = bufferIn.readLine();
                bufferIn.close();
            catch (IOException e)
                e.printStackTrace();
            return data;
        }

  • Jtable sorting question - string works, but numbers don't

    Hi,
    I have a Jtable which is populated from an Object two-dimensional array (myData). The object itself already containes string types and int types as appropriate (after a cumbersome type conversion).
    I can sort by the string column, but the number column does not get sorted correctly..i.e it shows 1, 11, 2, 3, 33, 50..etc..
    below is the code I am using:
    JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
    JTable jTable1 = new JTable(myData,columNames);
    jTable1.setAutoCreateRowSorter(true);
    add(new JScrollPane(jTable1));
    jScrollPane1.setViewportView(jTable1);
    Can anyone help?
    thanks

    so, could you show me how to do what he suggests, override the getColumnClass thingy
    I can't figure it out.
    package tableclass;
    import java.awt.BorderLayout;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    public class EditorTest extends JFrame
        JTable table = new JTable(10, 5);
        public EditorTest()
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane, BorderLayout.SOUTH);
        @Override;
        public class getColumnClass(int columnIndex){
            //idk wtf i'm doing.
        public static void main(String[] args)
            EditorTest frame = new EditorTest();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }

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

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

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

Maybe you are looking for

  • Can i have two apple tv on the same home sharing imac

    I have apple tv in the living roon which i stream movies from imac via home sharing. Can i use another apple tv on the home sharing, use them both at the same time without any problems.

  • A/R Credit memo Installment

    Hello Expert, Can it possible to generate installment on A/R Credit memo (Like A/R invoice).if it is possible then how?

  • Procure to Pay reports

    Dear all, Could you please let me know the standard reports available in Procure to Pay module. Thanks. Best regards, Venkat

  • AP541N - WPA Enterprise - Failed to connect

    Hi, I am trying to configure an AP541N with WPA Enterprise. My RADIUS server is an MS ISA 2003 and is already working fine with other devices (I have a ASA5510 also configured to use RADIUS authentication with this server). When I try to connect, I a

  • I get a error message (no -42404) when i try to update

    when i try to update itunes i get error message   (-42404) saying my copy of itunes is corrupt  & and reinstall  it but i keep getting same message???