Jrunscript.exe use of JDK 1.6

Source: Internet
Author: User
Tags stdin
Today, we talked about the discovery of JDK 1.6 installation directory under a jrunscript.exe, do not know what to do, in DOS to run a look at:

D:\jee5training\jdk1.6.0\bin>jrunscript.exe
js> var a = 2;
js> Print (a)
2js> println (a)
2
Js>
Js> Alert (a)
Script Error:sun.org.mozilla.javascript.internal.EcmaError:ReferenceError: "Al
ERT ' is not defined. (<STDIN> #1) in <STDIN> at line number 1
Js> New JFrame ("a"). Show ();
Script Error:sun.org.mozilla.javascript.internal.EcmaError:ReferenceError: "JF
Rame ' is not defined. (<STDIN> #1) in <STDIN> at line number 1
Js> New Javax.swing.JFrame ("a"). Show ();

The original JS interpreter, note that not running in the browser, so alert such a method is not available. However, you can invoke Java classes, such as GUI libraries.

Such a DOS command interpreter application can also be done in Java, for example, the following code implements a prompt commmand: command line application:

Import java.io.*;
public class Customcmd
{public
    static void Main (string[] args) throws IOException
    {
      BufferedReader Cmdin = new BufferedReader (new InputStreamReader (system.in));
      System.out.println ("Enter \" quit\ "to Quit");
      for (;;) {
        System.out.print ("Command:");
        String cmd = Cmdin.readline ();
        if (Cmd.equalsignorecase ("Quit")) break;//Quit The program
        System.out.println ("Your input:" + cmd.touppercase ()) ;
        Process the Command
      }
    }

Some of the other command line small code:

Repeatedly output text on the same line under command line use System.out.print ("... \ r");/\ r indicates carriage return, \ n indicates a newline

Parse command line input with options

such as:-S <server>-P <port>-M <message>
public static void Main (String args[]) {
Parse the command line options
for (int i = 0; i < args.length-1; i++) {
if (Args[i].equalsignorecase ("-S")) {
String Server = args[i + 1];
}else if (args[i].equalsignorecase ("-P")) {
String Port = args[i + 1];
}
...//Other parameters
}

Related information: Java 6, the default JS script engine is Rhino, is Mozilla open source JS engine, based on Java, we can download its separate package in JDK 1.4 or 1.5. This application can be implemented with some business logic code JS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.