Example usage for java.lang System exit

List of usage examples for java.lang System exit

Introduction

In this page you can find the example usage for java.lang System exit.

Prototype

public static void exit(int status) 

Source Link

Document

Terminates the currently running Java Virtual Machine.

Usage

From source file:DefaultButton.java

public static void main(String[] a) {
    JDialog f = new JDialog();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }/*from w w w.  j  a  v a2s  .c  o m*/
    });

    JButton btOK = new JButton("Press Enter to click me, I am the default.");
    btOK.setToolTipText("Save and exit");
    f.getRootPane().setDefaultButton(btOK);

    JPanel p = new JPanel();
    p.add(btOK);
    p.add(new JButton("I am NOT the default."));
    f.getContentPane().add(p);

    f.pack();
    f.setSize(new Dimension(300, 200));

    f.show();

}

From source file:MainClass.java

public static void main(String[] a) {
    File aFile = new File("C:/myFile.text");
    FileInputStream inputFile1 = null;
    FileDescriptor fd = null;//from w w w.ja va  2 s. c  o m
    try {
        inputFile1 = new FileInputStream(aFile);
        fd = inputFile1.getFD();
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
    FileInputStream inputFile2 = new FileInputStream(fd);
}

From source file:ReflectApp.java

public static void main(String args[]) {
    String parm = args[0];/*from w  w w  .j  a v  a 2 s . co m*/
    Class className = void.class;
    try {
        className = Class.forName(parm);
    } catch (ClassNotFoundException ex) {
        System.out.println("Not a class or interface.");
        System.exit(0);
    }
    describeClassOrInterface(className, parm);
}

From source file:TryDOM.java

public static void main(String args[]) {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    try {/*from  w  w  w .j  a  v  a  2s.c o m*/
        builder = builderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.out.println("Builder Factory = " + builderFactory + "\nBuilder = " + builder);
}

From source file:SVGCanvasDemo.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JSVGCanvas Demo");
    frame.setSize(400, 400);//from ww w  . j  a va2s  . c o  m

    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            System.exit(0);
        }
    });

    new SVGCanvasDemo(frame);
}

From source file:Main.java

public static void main(String[] argv) {
    int number = 0;

    System.out.println("The number of words in argv is " + argv.length);

    if (argv.length == 0) {
        number = 1234;/*from ww  w  . j a v  a 2 s .c  om*/
    } else if (argv.length == 1) {
        try {
            number = Integer.parseInt(argv[0]);
        } catch (NumberFormatException e) {
            System.err.println("Number " + argv[0] + " invalid (" + e.getMessage() + ").");
            System.exit(1);
        }
    } else {
        System.err.println("usage: UseArgv number");
        System.exit(1);
    }

    System.out.println("OK, number is " + number);
}

From source file:Unbuffered.java

public static void main(String args[]) {
    Reader reader;//  www .ja va  2s  .c o m
    int ch;
    System.out.println("Start! " + new Date());
    try {
        reader = new FileReader(args[0]);
        while ((ch = reader.read()) != -1) {
            // read entire file
        }
    } catch (IOException io) {
        System.err.println(io);
        System.exit(-1);
    }
    System.out.println("Stop! " + new Date());
}

From source file:TestRegisterDriverApp.java

public static void main(String args[]) {

    try {/*from   ww  w. ja  va  2 s  . c o  m*/
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    } catch (SQLException e) {
        System.out.println("Oops! Got a SQL error: " + e.getMessage());
        System.exit(1);
    }

    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;
    try {
        conn = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");

        stmt = conn.createStatement();
        rset = stmt.executeQuery("select 'Hello '||USER||'!' result from dual");
        while (rset.next())
            System.out.println(rset.getString(1));
        rset.close();
        rset = null;
        stmt.close();
        stmt = null;
        conn.close();
        conn = null;
    } catch (SQLException e) {
        System.out.println("Darn! A SQL error: " + e.getMessage());
    } finally {
        if (rset != null)
            try {
                rset.close();
            } catch (SQLException ignore) {
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (SQLException ignore) {
            }
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException ignore) {
            }
    }
}

From source file:Main.java

public static void main(String[] args) {
    Main frame = new Main();
    frame.setSize(new Dimension(200, 200));
    frame.add(new Button("Hello World"));

    frame.addWindowListener(new WindowAdapter() {

        @Override/* w ww .j ava 2  s. c  om*/
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setVisible(true);
}

From source file:TestClassForNameApp.java

public static void main(String args[]) {

    try {//from  w  w  w  . j a va 2s.co  m
        Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
        System.out.println("Oops! Can't find class oracle.jdbc.driver.OracleDriver");
        System.exit(1);
    }

    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;
    try {
        conn = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");

        stmt = conn.createStatement();
        rset = stmt.executeQuery("select 'Hello '||USER||'!' result from dual");
        while (rset.next())
            System.out.println(rset.getString(1));
        rset.close();
        rset = null;
        stmt.close();
        stmt = null;
        conn.close();
        conn = null;
    } catch (SQLException e) {
        System.out.println("Darn! A SQL error: " + e.getMessage());
    } finally {
        if (rset != null)
            try {
                rset.close();
            } catch (SQLException ignore) {
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (SQLException ignore) {
            }
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException ignore) {
            }
    }
}