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:DatagramReceiver.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("Usage: DatagramReceiver port");
        System.exit(1);
    }/*from   ww  w .  j av  a  2 s  .  co m*/

    try {
        DatagramConnection receiver = (DatagramConnection) Connector.open("datagram://:" + args[0]);
        byte[] buffer = new byte[256];
        Datagram dgram = receiver.newDatagram(buffer, buffer.length);
        for (;;) {
            dgram.setLength(buffer.length);
            receiver.receive(dgram);
            int length = dgram.getLength();
            System.out.println("Datagram received. Length is " + length);

            // Show the content of the datagram.
            for (int i = 0; i < length; i++) {
                System.out.print(buffer[i] + " ");
            }
            System.out.println();

            // Send it back...
            receiver.send(dgram);
        }
    } catch (IOException ex) {
        System.out.println("IOException: " + ex);
    }
}

From source file:ListPlafs.java

public static void main(String args[]) {
    UIManager.LookAndFeelInfo plaf[] = UIManager.getInstalledLookAndFeels();
    for (int i = 0, n = plaf.length; i < n; i++) {
        System.out.println("Name: " + plaf[i].getName());
        System.out.println("  Class name: " + plaf[i].getClassName());
    }//  w w w. j  a  v  a 2 s.c om
    System.exit(0);
}

From source file:FrameClose2.java

public static void main(String[] args) {
    JFrame mainFrame = new JFrame();

    // Exit app when frame is closed.
    mainFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            System.exit(0);
        }//  w  w w  .  j a v  a2s  .  co  m
    });

    mainFrame.setSize(320, 240);
    mainFrame.setVisible(true);
}

From source file:ValidationTestWithPatternAndMatcher.java

public static void main(String args[]) {
    Pattern p = null;/* www  .  ja va  2s .  c  om*/
    try {
        p = Pattern.compile("Java \\d");
    } catch (PatternSyntaxException pex) {
        pex.printStackTrace();
        System.exit(0);
    }

    String candidate = "I love Java 5";
    Matcher m = p.matcher(candidate);

    System.out.println("result=" + m.find());
}

From source file:CollateApp.java

public static void main(String args[]) {
    if (args.length != 1) {
        System.out.println("Usage: java CollateApp file");
        System.exit(0);
    }/*from w w w  . j  a  v a 2  s  .co m*/
    Locale defaultLocale = Locale.getDefault();
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(defaultLocale);
    Vector keyVector = new Vector();
    try {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        String line;
        while ((line = in.readLine()) != null)
            keyVector.addElement(collator.getCollationKey(line));
        in.close();
    } catch (Exception ex) {
        System.out.println(ex);
        System.exit(0);
    }
    CollationKey keys[] = new CollationKey[keyVector.size()];
    for (int i = 0; i < keys.length; ++i)
        keys[i] = (CollationKey) keyVector.elementAt(i);
}

From source file:WindowAdapterTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Window Listener");
    WindowListener listener = new WindowAdapter() {
        public void windowClosing(WindowEvent w) {
            System.exit(0);
        }/* ww w. j a v a2 s.com*/
    };
    frame.addWindowListener(listener);
    frame.setSize(300, 300);
    frame.show();
}

From source file:CollateApp.java

public static void main(String args[]) {
    if (args.length != 1) {
        System.out.println("Usage: java CollateApp file");
        System.exit(0);
    }/*from   w  ww. j av a  2  s.  co  m*/
    Locale defaultLocale = Locale.getDefault();
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(defaultLocale);
    Vector<Object> keyVector = new Vector<Object>();
    try {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        String line;
        while ((line = in.readLine()) != null)
            keyVector.addElement(collator.getCollationKey(line));
        in.close();
    } catch (Exception ex) {
        System.out.println(ex);
        System.exit(0);
    }
    CollationKey keys[] = new CollationKey[keyVector.size()];
    for (int i = 0; i < keys.length; ++i)
        keys[i] = (CollationKey) keyVector.elementAt(i);
}

From source file:GetMessageExample.java

public static void main(String args[]) throws Exception {
    if (args.length != 3) {
        System.err.println("Usage: java MailExample host username password");
        System.exit(-1);
    }/*from   ww  w . j a  v a  2 s.co  m*/

    String host = args[0];
    String username = args[1];
    String password = args[2];

    // Create empty properties
    Properties props = new Properties();

    // Get session
    Session session = Session.getDefaultInstance(props, null);

    // Get the store
    Store store = session.getStore("pop3");
    store.connect(host, username, password);

    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    // Get directory
    Message message[] = folder.getMessages();
    for (int i = 0, n = message.length; i < n; i++) {
        System.out.println(i + ": " + message[i].getFrom()[0] + "\t" + message[i].getSubject());

        System.out.println("Read message? [YES to read/QUIT to end]");
        String line = reader.readLine();
        if ("YES".equalsIgnoreCase(line)) {
            System.out.println(message[i].getContent());
        } else if ("QUIT".equalsIgnoreCase(line)) {
            break;
        }
    }

    // Close connection
    folder.close(false);
    store.close();
}

From source file:MainClass.java

public static void main(String[] a) {
    File aFile = new File("C:/myFile.txt");
    FileInputStream inputFile = null;
    try {//  w w  w.j a  v a2 s . c  om
        inputFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:GuaranteeAFile.java

public static void main(String[] args) {

    String filename = "C:/myFile.txt";
    File aFile = new File(filename);
    if (aFile.isDirectory()) {
        System.out.println("The path " + aFile.getPath() + " does not specify a file. Program aborted.");
        System.exit(1);
    }/*from  w  ww . java 2 s .  c  o  m*/
    if (!aFile.isFile()) {
        aFile = aFile.getAbsoluteFile();
        File parentDir = new File(aFile.getParent());
        if (!parentDir.exists()) {
            parentDir.mkdirs();
        }
    }
    FileOutputStream outputFile = null;
    try {
        outputFile = new FileOutputStream(aFile, true);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
}