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 { if (args.length != 2) { System.out.println("Usage: java JavaDBDemo <Name> <Address>"); System.exit(1); }/*from w ww .j a v a 2s . c o m*/ String driver = "org.apache.derby.jdbc.EmbeddedDriver"; String dbName = "AddressBookDB"; String connectionURL = "jdbc:derby:" + dbName + ";create=true"; String createString = "CREATE TABLE ADDRESSBOOKTbl (NAME VARCHAR(32) NOT NULL, ADDRESS VARCHAR(50) NOT NULL)"; Class.forName(driver); conn = DriverManager.getConnection(connectionURL); Statement stmt = conn.createStatement(); stmt.executeUpdate(createString); PreparedStatement psInsert = conn.prepareStatement("insert into ADDRESSBOOKTbl values (?,?)"); psInsert.setString(1, args[0]); psInsert.setString(2, args[1]); psInsert.executeUpdate(); Statement stmt2 = conn.createStatement(); ResultSet rs = stmt2.executeQuery("select * from ADDRESSBOOKTbl"); System.out.println("Addressed present in your Address Book\n\n"); int num = 0; while (rs.next()) { System.out.println(++num + ": Name: " + rs.getString(1) + "\n Address" + rs.getString(2)); } rs.close(); }
From source file:MainClass.java
public static void main(String[] args) { if (args.length != 2) { String err = "Usage: KeyGeneratorApp algorithmName keySize"; System.out.println(err);/*from www.j a va 2s .c o m*/ System.exit(0); } int keySize = (new Integer(args[1])).intValue(); SecretKey skey = null; KeyPair keys = null; String algorithm = args[0]; try { KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm); kpg.initialize(keySize); keys = kpg.genKeyPair(); } catch (NoSuchAlgorithmException ex1) { try { KeyGenerator kg = KeyGenerator.getInstance(algorithm); kg.init(keySize); skey = kg.generateKey(); } catch (NoSuchAlgorithmException ex2) { System.out.println("Algorithm not supported: " + algorithm); System.exit(0); } } }
From source file:Main.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 a 2s .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.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { File aFile = new File("charData.txt"); FileInputStream inFile = null; try {// w w w . j a v a2 s . c om inFile = new FileInputStream(aFile); } catch (FileNotFoundException e) { e.printStackTrace(System.err); System.exit(1); } FileChannel inChannel = inFile.getChannel(); }
From source file:AuthorizedFileWriter.java
public static void main(String[] args) { System.setSecurityManager(new SecurityManager()); String file = "authorized.txt"; String fileBody = "test"; try {// w w w . j a va 2 s . c o m FileWriter fileWriter = new FileWriter(file); fileWriter.write(fileBody); fileWriter.close(); System.exit(0); } catch (IOException ioException) { ioException.printStackTrace(); System.exit(1); } }
From source file:MainClass.java
public static void main(String args[]) { Scanner conin = new Scanner(System.in); int count = 0; System.out.println("Enter numbers to average."); while (conin.hasNext()) { if (conin.hasNextDouble()) { System.out.println(conin.nextDouble()); count++;//from w ww.j a v a 2 s .co m } if (count == 3) { System.exit(0); } } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { FileInputStream fis = new FileInputStream("test"); ObjectInputStream ois = new ObjectInputStream(fis); Object o = ois.readObject();//from w w w . jav a 2 s . co m if (!(o instanceof String)) { System.out.println("Unexpected data in file"); System.exit(-1); } String data = (String) o; System.out.println("Got message " + data); o = ois.readObject(); if (!(o instanceof byte[])) { System.out.println("Unexpected data in file"); System.exit(-1); } byte origDigest[] = (byte[]) o; MessageDigest md = MessageDigest.getInstance("SHA"); md.update(data.getBytes()); if (MessageDigest.isEqual(md.digest(), origDigest)) System.out.println("Message is valid"); else System.out.println("Message was corrupted"); }
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 w w w . ja va2 s. c o m*/ closeButton.addActionListener(e -> System.exit(0)); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { FileInputStream fis = new FileInputStream("test"); ObjectInputStream ois = new ObjectInputStream(fis); Object o = ois.readObject();/*from w ww .j a va2s .co m*/ if (!(o instanceof String)) { System.out.println("Unexpected data in file"); System.exit(-1); } String data = (String) o; System.out.println("Got message " + data); o = ois.readObject(); if (!(o instanceof byte[])) { System.out.println("Unexpected data in file"); System.exit(-1); } byte origDigest[] = (byte[]) o; byte pass[] = "aaa".getBytes(); byte buf[] = data.getBytes(); MessageDigest md = MessageDigest.getInstance("SHA"); md.update(pass); md.update(buf); byte digest1[] = md.digest(); md.update(pass); md.update(digest1); System.out.println(MessageDigest.isEqual(md.digest(), origDigest)); }
From source file:MainClass.java
public static void main(String args[]) { String phrase = "a word word"; String duplicatePattern = "\\b(\\w+) \\1\\b"; Pattern p = null;/*from w w w .j a v a2 s . c om*/ try { p = Pattern.compile(duplicatePattern); } catch (PatternSyntaxException pex) { pex.printStackTrace(); System.exit(0); } // count the number of matches. int matches = 0; // get the matcher Matcher m = p.matcher(phrase); String val = null; // find all matching Strings while (m.find()) { val = ":" + m.group() + ":"; System.out.println(val); matches++; } }