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.