"jrunscript -f" - Run JavaScript in Batch Mode

This section provides a tutorial example on how to use 'jrunscript -f ...' to run JavaScript code in batch mode.

If you want to run JavaScript code stored in a file in batch mode, you use the "jrunscript -f ..." command.

1. Create a test JavaScript code file, While-Loop.js.

// While-Loop.js
//   Copyright (c) HerongYang.com. All Rights Reserved.
//
   var i, j, is_prime;
   i = 3;
   while ( i<=30 ) {
      is_prime = true;
      j = 2;
      while ( j<=i/2 ) {
         is_prime = i%j > 0;
         if (!is_prime) break;
         j++;
      }
      if (is_prime)
         print("Found a prime number: " + i);
      i += 2;
   }

2. Run the JavaScript code file in batch mode with "jrunscript -f ..." command.

herong$ jrunscript -f While-Loop.js 
Warning: Nashorn engine is planned to be removed from a future JDK release

Found a prime number: 3
Found a prime number: 5
Found a prime number: 7
Found a prime number: 11
Found a prime number: 13
Found a prime number: 17
Found a prime number: 19
Found a prime number: 23
Found a prime number: 29

Okay, running JavaScript code in batch mode with "jrunscript" is easy too!

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 jpackage - Binary Package Builder

 java - The Java Program Launcher

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

jrunscript - Script Code Shell

 jrunscript - What Is It

 "jrunscript" - Run JavaScript Interactively

"jrunscript -f" - Run JavaScript in Batch Mode

 serialver - serialVersionUID Generator

 native2ascii - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 Full Version in PDF/EPUB