Java MCQ Number 01057

Java MCQ Set 1

1. What is a framework?
a) User time efficiency
b) Author time efficiency
c) Both User time and Author time efficiency
d) None of the mentioned

Answer

Answer: b [Reason:] Frameworks are an author-time efficiency, meaning that they make coding tasks much simpler by abstracting the real work that goes into doing those tasks.

2. Which is the function used to loop in an array to view all the values?
a) all()
b) loop()
c) each()
d) none of the mentioned

Answer

Answer: c [Reason:] The method jQuery.each(array, function) loops through the array.

3. Which of the following has a greater benchmark time for looping and JQuery vs core JavaScript in milliseconds?
a) Chrome JQuery
b) Chrome JavaScript
c) Firefox JQuery
d) Firefox JavaScript

Answer

Answer: a [Reason:] When we try to compare the average benchmark time for looping and JQuery vs core JavaScript in milliseconds, the Chrome JQuery has a greater benchmark time.

4. Which class provides an interface for invoking JavaScript methods and examining JavaScript properties?
a) ScriptObject
b) JSObject
c) JavaObject
d) Jobject

Answer

Answer: b [Reason:] When a JavaScript object is passed or returned to Java code, it is wrapped in an instance of JSObject. When a JSObject instance is passed to the JavaScript engine, it is unwrapped back to its original JavaScript object. The JSObject class provides a way to invoke JavaScript methods and examine JavaScript properties.

5. What is the purpose of the function eval?
a) Executes the string as an integer
b) Gets the value of the string
c) Executing string as JavaScript
d) None of the mentioned

Answer

Answer: c [Reason:] eval is a JavaScript native function that accepts a string and executes the string as JavaScript. It basically fires up the interpreter and allows the passed-in string to be parsed and interpreted at the time of invocation.

6. Which of the following has a lesser benchmark time for using JQuery to access DOM versus pure JavaScript in milliseconds?
a) Chrome JQueryDOM_
b) Chrome JSDOM_benc
c) Firefox JQueryDOM_
d) Firefox JSDOM_benc

Answer

Answer: d [Reason:] When we try to compare the average benchmark time for using JQuery to access DOM versus pure JavaScript in milliseconds, the Firefox JSDOM_benc has a lesser benchmark time.

7. Which is a wrapped Java array, accessed from within JavaScript code?
a) JavaArray
b) JavaClass
c) JavaObject
d) JavaPackage

Answer

Answer: a [Reason:] JavaArray is accessed from within JavaScript code.

8. What is the syntax of close method for document object?
a) Close(object)
b) Close(doc)
c) Close(val)
d) Close()

Answer

Answer: d [Reason:] In order to close a document object, we need to call Close().

9. How do you find the number with the highest value of x and y?
a) ceil(x,y)
b) top(x,y)
c) Math.ceil(x,y)
d) Math.max(x,y)

Answer

Answer: d [Reason:] Math.max(x,y) is used to find the highest value of x and y.

10. How can you find a client’s browser name?
a) browser.name
b) navigator.appName
c) client.navName
d) none of the mentioned

Answer

Answer: b [Reason:] The client’s browser name can be found by using navigator.appName.

Java MCQ Set 2

1. Which of the following is a way of embedding Client-side JavaScript code within HTML documents?
a) From javascript:encoding
b) External file specified by the src attribute of a “script” tag
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] The Client-side JavaScript code is embedded within HTML documents in four ways :

  1. Inline, between a pair of “script” tags
  2. From an external file specified by the src attribute of a “script” tag
  3. In an HTML event handler attribute, such as onclick or onmouseover
  4. In a URL that uses the special javascript: protocol.

2. When does JavaScript code appear inline within an HTML file?
a) Between the “script” tag
b) Outside the “script” tag
c) Between or Outside the “script” tag
d) None of the mentioned

Answer

Answer: a [Reason:] JavaScript code can appear inline within an HTML file between the “script” tags.

3. Which character in JavaScript code will be interpreted as XML markup?
a) !
b) >
c) &
d) .

Answer

Answer: c [Reason:] If your JavaScript code contains the < or & characters, these characters are interpreted as XML markup.

4. Which is the root element in a HTML document?
a) HTML
b) HEAD
c) SCRIPT
d) BODY

Answer

Answer: a [Reason:] The “html” tag is the root element of any HTML document regardless of it containing a JavaScript code or not.

5. What is the code for getting the current time?

a) now = new Date();
b) var now = new Date();
c) var now = Date();
d) var now = new Date(current);
Answer

Answer: b [Reason:] The above code determines the current time and stores it in the variable “now”.

6. What is the code to start displaying the time when document loads?

a) onload = displayTime;
b) window. = displayTime;
c) window.onload = displayTime;
d) window.onload = start;
Answer

Answer: c [Reason:] The above code starts displaying the time when the document loads.

7. One of the main advantage of using src attribute is
a) It becomes self-cached
b) It makes the HTML file modular
c) It restricts manipulation in the HTML file
d) It simplifies the HTML files

Answer

Answer: d [Reason:] The main advantage of using the src attribute is that it simplifies your HTML files by allowing you to remove large blocks of JavaScript code from them—that is, it helps keep content and behavior separate.

8. What will be done if more than one page requires a file of JavaScript code?
a) Downloads that many times
b) Retrives from the browser cache
c) Must be re executed
d) None of the mentioned

Answer

Answer: b [Reason:] If a file of JavaScript code is shared by more than one page, it only needs to be downloaded once, by the first page that uses it—subsequent pages can retrieve it from the browser cache.

9. What is the default value of the type attribute?
a) text/css
b) text/javascript
c) text
d) xml

Answer

Answer: b [Reason:] The default value of the type attribute is “text/javascript”. You can specify this type explicitly if you want, but it is never necessary.

10. The language is commonly used to
a) Specify the user’s language
b) Specify the language going to be scripted
c) No longer in use
d) Specify the programmer’s favorable language

Answer

Answer: c [Reason:] The language attribute is deprecated and should no longer be used.

Java MCQ Set 3

1. What is the purpose of the method plot()?
a) Displays symbols
b) Displays charts
c) Displays symbols and charts
d) None of the mentioned

Answer

Answer: b [Reason:] The plot() function will display a different type of chart depending on the arguments that you pass in to it.

2. How many parameters does the method plot() accept?
a) 6
b) 7
c) 8
d) 9

Answer

Answer: d [Reason:] The method plot() accepts a total of 9 parameters.

3. What is the need for bubble charts?
a) Represent 2D data
b) Represent 3D data
c) Represent 2D and 3D data
d) None of the mentioned

Answer

Answer: b [Reason:] Bubble charts are used to represent three-dimensional data.

4. Which of the following is the initial function used to create a bubble chart natively in R?
a) init()
b) chart(bubble)
c) symbols()
d) none of the mentioned

Answer

Answer: c [Reason:] The method symbols() is used to create a bubble chart natively in R.

5. What is the purpose of the method symbols in R?
a) Draw symbols
b) Draw other shapes
c) Draw symbols and other shapes
d) None of the mentioned

Answer

Answer: b [Reason:] The symbols() function can be used to draw other shapes on a plot; for more information about this type ?symbols at the R console.

6. How to save chart as a Window metafile?
a) metafile()
b) win.metafile()
c) file()
d) metawin()

Answer

Answer: b [Reason:] The method win.metafile([filename]) is used to save chart as a Window metafile.

7. Which is the method used to save chart as a ps file?
a) ps()
b) postscript()
c) script()
d) post(script)

Answer

Answer: b [Reason:] The syntax for the method to save chart as a ps file is : postscript([filename]).

8. Which of the following are methods used to save charts?
a) pdf()
b) jpeg()
c) bmp()
d) all of the mentioned

Answer

Answer: d [Reason:] All of the above mentioned methods are used to save charts in different modes.

9. Which is the method used to draw a bar plot?
a) bar_plot()
b) plot(bar)
c) barplot()
d) plotbar()

Answer

Answer: c [Reason:] The method barplot() can be used to draw a bar plot.

10. What is the purpose of the method par()?
a) Makes the text vertical
b) Makes the text horizontal
c) Makes the text diagonal
d) None of the mentioned

Answer

Answer: b [Reason:] With the method par(), you can make the text horizontal.

Java MCQ Set 4

1. What is the purpose of the method plot()?
a) Displays symbols
b) Displays charts
c) Displays symbols and charts
d) None of the mentioned

Answer

Answer: b [Reason:] The plot() function will display a different type of chart depending on the arguments that you pass in to it.

2. How many parameters does the method plot() accept?
a) 6
b) 7
c) 8
d) 9

Answer

Answer: d [Reason:] The method plot() accepts a total of 9 parameters.

3. What is the need for bubble charts?
a) Represent 2D data
b) Represent 3D data
c) Represent 2D and 3D data
d) None of the mentioned

Answer

Answer: b [Reason:] Bubble charts are used to represent three-dimensional data.

4. Which of the following is the initial function used to create a bubble chart natively in R?
a) init()
b) chart(bubble)
c) symbols()
d) none of the mentioned

Answer

Answer: c [Reason:] The method symbols() is used to create a bubble chart natively in R.

5. What is the purpose of the method symbols in R?
a) Draw symbols
b) Draw other shapes
c) Draw symbols and other shapes
d) None of the mentioned

Answer

Answer: b [Reason:] The symbols() function can be used to draw other shapes on a plot; for more information about this type ?symbols at the R console.

6. How to save chart as a Window metafile?
a) metafile()
b) win.metafile()
c) file()
d) metawin()

Answer

Answer: b [Reason:] The method win.metafile([filename]) is used to save chart as a Window metafile.

7. Which is the method used to save chart as a ps file?
a) ps()
b) postscript()
c) script()
d) post(script)

Answer

Answer: b [Reason:] The syntax for the method to save chart as a ps file is : postscript([filename]).

8. Which of the following are methods used to save charts?
a) pdf()
b) jpeg()
c) bmp()
d) all of the mentioned

Answer

Answer: d [Reason:] All of the above mentioned methods are used to save charts in different modes.

9. Which is the method used to draw a bar plot?
a) bar_plot()
b) plot(bar)
c) barplot()
d) plotbar()

Answer

Answer: c [Reason:] The method barplot() can be used to draw a bar plot.

10. What is the purpose of the method par()?
a) Makes the text vertical
b) Makes the text horizontal
c) Makes the text diagonal
d) None of the mentioned

Answer

Answer: b [Reason:] With the method par(), you can make the text horizontal.

Java MCQ Set 5

1. Consider the following code snippet

const pi=3.14;
var pi=4;
console.log(pi);

What will be the output for the above code snippet?
a) This will flash an error
b) Prints 4
c) Prints 3.14
d) Ambiguity

Answer

Answer: a [Reason:] The above code snippet will flash an error. Attempts to alter the value or re-declaration causes errors.

2. The let keyword can be used
a) in a for or for/in loop, as a substitute for var
b) as a block statement, to define new variables
c) to define variables that are scoped to a single expression
d) all of the mentioned

Answer

Answer: d [Reason:] The let keyword can be used in four ways :

  1. as a variable declaration like var;
  2. in a for or for/in loop, as a substitute for var;
  3. as a block statement, to define new variables and explicitly delimit their scope; and
  4. to define variables that are scoped to a single expression.

3. The main difference between the variables declared with var and with let is
a) var is confined to a particular function but let is not
b) let is confined to a particular function but var is not
c) var defines values based on conditions but let does not
d) none of the mentioned

Answer

Answer: b [Reason:] Variables declared with var are defined throughout the enclosing function. Variables declared with let are defined only within the closest enclosing block (and any blocks nested within it, of course).

4. Consider the following code snippet

function oddsums(n) 
{
     let total = 0, result=[]; 
     for(let x = 1; x <= n; x++) 
     { 
        let odd = 2*x-1; 
        total += odd;
        result.push(total);
     }
     return result;
}

What would be the output if

oddsums(5);

is executed afted the above code snippet ?
a) Returns [1,4,9,16,25].
b) Returns [1,2,3,4,5].
c) Returns [3,6,9,12,15].
d) Returns [1,3,5,7,9].

Answer

Answer: a [Reason:] The above code returns 1,4,9,16,25 which is the square of the first five natural numbers. Notice the usage of let keyword in the above code snippet.

5. Consider the following code snippet

console.log(p)

If p is not defined, what would be the result or type of error?
a) Zero
b) Null
c) ReferenceError
d) ValueNotFoundError

Answer

Answer: c [Reason:] In the above code snippet, p is not defined. Hence, it gives a ReferenceError.

6. Consider the following code snippet

let x=x+1;
console.log(x);

What will be the result for the above code snippet?
a) 0
b) Null
c) ReferenceError
d) NaN

Answer

Answer: d [Reason:] Since x is a let variable and since x is undefined, so x+1 is NaN. Thus, the above code snippet prints NaN.

7. Consider the following code snippet

[x,y]=[y,x];

What is the result of the above code snippet?
a) Throws exception
b) Swap the value of the two variables
c) Flashes an error
d) Creates a new reference object

Answer

Answer: c [Reason:] The above code snippet swaps the value of the two variables.

8. Which looping statement allows XML tags to appear in JavaScript programs and adds API for operating on XML data?
a) for loop
b) while loop
c) for/each loop
d) all of the mentioned

Answer

Answer: c [Reason:] The for/each loop is a new looping statement standardized by E4X. E4X (ECMAScript for XML) is a language extension that allows XML tags to appear literally in JavaScript programs and adds syntax and API for operating on XML data.

9. Which exception does the Iterators throw from their next() method when there are no more values to iterate, that work on finite collections ?
a) ExitIteration
b) AbortIteration
c) Abort
d) StopIteration

Answer

Answer: d [Reason:] Iterators that work on finite collections throw StopIteration from their next() method when there are no more values to iterate. StopIteration is a property of the global object in JavaScript 1.7. Its value is an ordinary object (with no properties of its own) that is reserved for this special purpose of terminating iterations. Note, in particular,that StopIteration is not a constructor function like TypeError() or RangeError().

10. Which method of the iterable object returns an iterator object for the collection?
a) iterator()
b) _iterator_()
c) _iteration_()
d) _return_iterator_()

Answer

Answer: b [Reason:] An iterable object represents a collection of values that can be iterated. An iterable object must define a method named __iterator__() (with two underscores at the start and end of the name) which returns an iterator object for the collection.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.