This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Scripting Java with Rhino”.
1. Rhino is originated by _______
a) Microsoft
b) Mozilla
c) Apple
d) Chrome
View Answer
Explanation: Rhino is a JavaScript engine written fully in Java and managed by the Mozilla Foundation as open source software. Rhino is free software from Mozilla. You can download a copy from http://www.mozilla.org/rhino/.
2. Which of the following are global functions that are not part of core JavaScript?
a) spawn(f);
b) trim();
c) exult();
d) eval()
View Answer
Explanation: The spawn(f) runs f() or loads and executes file f in a new thread.
3. Which of the following reads the textual contents of a URL and returns as a string?
a) spawn(f);
b) load(filename,…);
c) readFile(file);
d) readUrl(url);
View Answer
Explanation: Rhino defines a handful of important global functions that are not part of core JavaScript in which readUrl(url) reads the textual contents of a URL and return as a string.
4. Which Rhino command quits Rhino environment?
a) terminate()
b) exit()
c) quit()
d) close()
View Answer
Explanation: quit() is a predefined command in rhino. The quit() command makes Rhino exit.
5. Which is a useful way to try out small and simple Rhino programs and one-liners?
a) Starting an interactive shell
b) Starting a one to one shell
c) Creating a thread to do simple programs
d) Starting a multiple shell
View Answer
Explanation: Rhino is distributed as a JAR archive. Start it with a command line like this :
java -jar rhino1_7R2/js.jar program.js
If you omit program.js, Rhino starts an interactive shell, which is useful for trying out simple programs and one-liners.
6. Which is a more formal way of importing packages and classes as JavaScript objects?
a) import(java.util.*);
b) importClass(java.util.*);
c) import.Class(java.util.*);
d) Class.import(java.util.*);
View Answer
Explanation: Because packages and classes are represented as JavaScript objects, you can assign them to variables to give them shorter names. But you can also more formally import them, if you want to:
importClass(java.util.HashMap); // Same as : var HashMap = java.util.HashMap
7. What will be the output of the following JavaScript code?
var f = new java.io.File("/tmp/test"); var out = new java.io.FileWriter(f); out instanceof java.io.Reader
a) Error
b) True
c) Exception
d) False
View Answer
Explanation: The output for the above code snippet is false as it is a writer and not a Reader.
8. What does Rhino do when the getter and setter methods exist?
a) It becomes JavaScript properties
b) Java classes are used to avoid them
c) Java classes & JavaScript properties
d) It act as javascript function
View Answer
Explanation: Rhino allows JavaScript code to query and set the static fields of Java classes and the instance fields of Java objects. Java classes often avoid defining public fields in favor of getter and setter methods. When getter and setter methods exist, Rhino exposes them as JavaScript properties.
9. The JavaScript classes can be instantiated using _____ operator.
a) create
b) new
c) instantiate
d) create.new
View Answer
Explanation: New is a keyword in JavaScript which is used to define new models. New operator is used to create new instance of the class.
10. The new Java arrays can be created into JavaScript programs using which of the following classes?
a) java.Array
b) java.lang.*
c) java.lang.Array
d) java.lang.reflect.Array
View Answer
Explanation: There is no natural JavaScript syntax that Rhino can extend to allow JavaScript programs to create new Java arrays, so you have to do that using the java.lang.reflect.Array class.
11. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.sin(90 * Math.PI / 180); </script>
a) 1
b) 0
c) 1.6
d) 0.5
View Answer
Explanation: Math.sin function evaluates the sine value of a particular input.
Math.PI function generates a value of 3.14.
12. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.abs(-4.5); </script>
a) -4.5
b) 4.5
c) 0
d) Error
View Answer
Explanation: The Math.abs method returns the absolute positive value of the argument passed to it. The above code will hence generate an output of 4.5.
13. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.min(0, 150, 30, 20, -8, -200); </script>
a) 0
b) -8
c) -200
d) 20
View Answer
Explanation: Math.min() returns the lowest value in a list of arguments. The lowest value is -200, hence the output will be -200.
14. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.floor(4.7); </script>
a) 4.5
b) 4
c) 4.7
d) 5
View Answer
Explanation: Math.floor(x) returns the value of x rounded down to its nearest integer. The value is decreased in the decimal is removed.
15. What will be the output of the following JavaScript code?
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.sqrt(49); </script>
a) 6
b) 7
c) 49
d) Error
View Answer
Explanation: Math.sqrt function returns the square root of the argument passed to it. It is found in the math library of Javascript.
Sanfoundry Global Education & Learning Series – Javascript Programming.
- Practice Information Science MCQs
- Check JavaScript Books
- Practice Programming MCQs
- Practice MCA MCQs
- Apply for Computer Science Internship