List of usage examples for java.lang System exit
public static void exit(int status)
From source file:MainClass.java
public static void main(String[] args) throws Exception { Object f = new Object() { public void finalize() { System.out.println("Running finalize()"); }//from www. j a v a 2s . c om }; Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("Running Shutdown Hook"); } }); f = null; System.gc(); System.out.println("Calling System.exit()"); System.exit(0); }
From source file:MainClass.java
public static void main(String[] args) { File aFile = new File("file.dat"); FileInputStream inFile = null; try {//from w w w . j a v a 2 s . co m inFile = new FileInputStream(aFile); } catch (FileNotFoundException e) { e.printStackTrace(System.err); System.exit(0); } FileChannel inChannel = inFile.getChannel(); final int COUNT = 6; ByteBuffer buf = ByteBuffer.allocate(8 * COUNT); long[] data = new long[COUNT]; try { while (inChannel.read(buf) != -1) { ((ByteBuffer) (buf.flip())).asLongBuffer().get(data); System.out.println(); for (long prime : data) System.out.printf("%10d", prime); buf.clear(); } System.out.println("\nEOF reached."); inFile.close(); } catch (IOException e) { e.printStackTrace(System.err); System.exit(1); } }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton closeButton = new JButton("Close"); contentPane.add(closeButton);//w w w . jav a2s . co m closeButton.addActionListener(e -> System.exit(0)); // Add a MouseListener to the JButton closeButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { closeButton.setText("Mouse has entered!"); } @Override public void mouseExited(MouseEvent e) { closeButton.setText("Mouse has exited!"); } }); frame.pack(); frame.setVisible(true); }
From source file:TestClassForNameNewInstanceApp.java
public static void main(String args[]) { try {/*w w w .j a v a2 s . c om*/ Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); } catch (ClassNotFoundException e) { System.out.println("Oops! Can't find class oracle.jdbc.driver.OracleDriver"); System.exit(1); } catch (IllegalAccessException e) { System.out.println("Uh Oh! You can't load oracle.jdbc.driver.OracleDriver"); System.exit(2); } catch (InstantiationException e) { System.out.println("Geez! Can't instantiate oracle.jdbc.driver.OracleDriver"); System.exit(3); } 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) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); // Add a close button JButton closeButton = new JButton("Close"); contentPane.add(closeButton);//from www .j a v a2 s .c o m closeButton.addActionListener(e -> { System.out.println(e.getActionCommand()); System.exit(0); }); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton closeButton = new JButton("Close"); contentPane.add(closeButton);/*from w ww . j a v a 2 s.c o m*/ closeButton.addActionListener(e -> System.exit(0)); // Add a MouseListener to the JButton closeButton.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { closeButton.setText("Mouse has entered!"); } @Override public void mouseExited(MouseEvent e) { closeButton.setText("Mouse has exited!"); } }); frame.pack(); frame.setVisible(true); }
From source file:com.ltb.Main.java
public static void main(String[] args) throws Exception { File node = new File("//home//juanma//Videos//DSVideo//Cartoons"); displayIt(node);/*from w w w . ja va 2s . co m*/ AudioTrack.returnListLanguages(); System.out.println("# Audio tracks " + audio); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { URLName server = new URLName("protocol://username:password@host/foldername"); Session session = Session.getDefaultInstance(new Properties(), null); Folder folder = session.getFolder(server); if (folder == null) { System.out.println("Folder " + server.getFile() + " not found."); System.exit(1); }//from w w w. j a va2 s .c o m folder.open(Folder.READ_ONLY); // Get the messages from the server Message[] messages = folder.getMessages(); for (int i = 0; i < messages.length; i++) { System.out.println("------------ Message " + (i + 1) + " ------------"); messages[i].writeTo(System.out); } folder.close(false); }
From source file:TestRegularExpression.java
public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage:\n" + "java TestRegularExpression " + "characterSequence regularExpression+"); System.exit(0); }//w w w . jav a 2s. c om System.out.println("Input: \"" + args[0] + "\""); for (int i = 1; i < args.length; i++) { System.out.println("Regular expression: \"" + args[i] + "\""); Pattern p = Pattern.compile(args[i]); Matcher m = p.matcher(args[0]); while (m.find()) { System.out.println("Match \"" + m.group() + "\" at positions " + m.start() + "-" + (m.end() - 1)); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { JOptionPane pane = new JOptionPane("your message", JOptionPane.ERROR_MESSAGE, JOptionPane.OK_OPTION); JDialog d = pane.createDialog(null, "title"); d.pack();//from ww w . ja v a 2s. c om d.setModal(false); d.setVisible(true); while (pane.getValue() == JOptionPane.UNINITIALIZED_VALUE) { try { Thread.sleep(100); } catch (InterruptedException ie) { } } System.exit(0); }