Java MCQ Set 1
1. What is the function of the XML parser?
a) Converts XML document to XML DOM object
b) Converts XML DOM object to XML document
c) Converts XML DOM object to a comment
d) None of the mentioned
Answer
Answer: a [Reason:] An XML parser converts an XML document into an XML DOM object – which can then be manipulated with JavaScript.
2. What is the purpose of the method ActiveXObject()?
a) Used to call automation object
b) Used to reference automation object
c) Used to instantiate automation object
d) All of the mentioned
Answer
Answer: c [Reason:] The ActiveXObject() object is used only to instantiate Automation objects, and has no members.
3. What is the purpose of the url json?
a) Belongs to JSON object
b) Reference JSON formatted data
c) Belongs to JSON
d) None of the mentioned
Answer
Answer: b [Reason:] The URL JSON is assumed to reference a file of JSON-formatted data. The value passed to the callback is the object obtained by parsing the URL contents with jQuery.parseJSON(). jQuery.getJSON() uses this type. If the type is “json” and the URL or data string contains “=?”, the type is converted to “jsonp”.
4. What is the parameter of the method Date.parse()?
a) date
b) string
c) datestring
d) string
Answer
Answer: c [Reason:] The parse method is defined as Date.parse(datestring).
5. Which is the function in JavaScript that will print the current page in JavaScript?
a) print()
b) printcurrent()
c) print(now)
d) print(this)
Answer
Answer: a [Reason:] The window.print() can be used to print the current page in JavaScript.
6. To which of the following object does the print() method belong to?
a) window
b) document
c) hash
d) none of the mentioned
Answer
Answer: a [Reason:] The method print() belongs to the window object.
7. What will happen if the radix parameter of the parseInt() function is omitted?
a) Runs in assumption
b) Throws exception
c) Aborts
d) Taken as 0
Answer
Answer: a [Reason:] If the radix parameter is omitted, JavaScript assumes the following:
- If the string begins with “0x”, the radix is 16 (hexadecimal)
- If the string begins with “0”, the radix is 8 (octal). This feature is deprecated
- If the string begins with any other value, the radix is 10 (decimal)
8. What will be the radix value if the string begins with 0x?
a) 13
b) 14
c) 15
d) 16
Answer
Answer: d [Reason:] If the string begins with 0x, then the radix value will be 16.
9. What is the function of the parseInt() method?
a) Parses a datatype and stores in an integer
b) Parses a string and returns an integer
c) Parses an integer and returns a string
d) None of the mentioned
Answer
Answer: b [Reason:] The function parseInt() method parses a string and returns an integer.
10. What does it indicate when the radix value is 16?
a) String begins with 0x
b) String begins with 0
c) String begins with 0P
d) String begins with FF
Answer
Answer: a [Reason:] If the string begins with “0x”, the radix is 16 (hexadecimal).
Java MCQ Set 2
1. How do we define the term Thread?
a) Device that controls input
b) Variable that controls movement
c) Controlled execution of applications
d) All of the mentioned
Answer
Answer: c [Reason:] Threads are sequential units of controlled execution for applications.
2. What does the browser do to set up a TCP/IP connection?
a) TCP one-way handshake
b) TCP two-way handshake
c) TCP three-way handshake
d) None of the mentioned
Answer
Answer: c [Reason:] The browser negotiates a TCP three-way handshake with the remote web server to set up a TCP/ IP connection.
3. What does the handshake pass between the browser and the remote server?
a) Synchronize
b) Accept
c) Reject
d) Decline
Answer
Answer: a [Reason:] The handshake consists of a Synchronize, Synchronize-Acknowledge, and Acknowledge message to be passed between the browser and the remote server.
4. How does the handshake help the server?
a) Acknowledge
b) Accept the attempt
c) Both Acknowledge and Accept the attempt
d) None of the mentioned
Answer
Answer: c [Reason:] The handshake allows the server to acknowledge and accept the attempt.
5. What is the purpose of the transport layer?
a) TCP Communication takes place
b) UDP Communication takes place
c) Both TCP and UDP Communication takes place
d) None of the mentioned
Answer
Answer: c [Reason:] The Transport layer is where our TCP (or UDP) communication takes place.
6. What does the status code 200 indicate?
a) Error in request
b) Error in response
c) Error in server
d) Successful
Answer
Answer: d [Reason:] The status code 200 indicates a successful response from the server.
7. What does the status code 500 indicate?
a) Error in request
b) Error in response
c) Error in server
d) Successful
Answer
Answer: a [Reason:] The status code 500 means that there was an error when trying to fulfill the request.
8. What does the application layer handle?
a) Top-level communication
b) Bottom-level communication
c) Both Top-level and Bottom-level communication
d) None of the mentioned
Answer
Answer: a [Reason:] The Application layer handles the top-level communication that the client and servers use, like HTTP and SMTP for email clients.
9. Which status code indicates that the server could not find the resource requested?
a) 200
b) 404
c) 500
d) 566
Answer
Answer: b [Reason:] The status code 404 means that the server could not find the resource requested.
10. What is the maximum size of an IP packet for IPv4 or IPv6?
a) 65540
b) 65535
c) 65577
d) 67544
Answer
Answer: b [Reason:] The maximum size of an IP packet for IPv4 or IPv6 is 65535.
Java MCQ Set 3
1. How do we define the term Thread?
a) Device that controls input
b) Variable that controls movement
c) Controlled execution of applications
d) All of the mentioned
Answer
Answer: c [Reason:] Threads are sequential units of controlled execution for applications.
2. What does the browser do to set up a TCP/IP connection?
a) TCP one-way handshake
b) TCP two-way handshake
c) TCP three-way handshake
d) None of the mentioned
Answer
Answer: c [Reason:] The browser negotiates a TCP three-way handshake with the remote web server to set up a TCP/ IP connection.
3. What does the handshake pass between the browser and the remote server?
a) Synchronize
b) Accept
c) Reject
d) Decline
Answer
Answer: a [Reason:] The handshake consists of a Synchronize, Synchronize-Acknowledge, and Acknowledge message to be passed between the browser and the remote server.
4. How does the handshake help the server?
a) Acknowledge
b) Accept the attempt
c) Both Acknowledge and Accept the attempt
d) None of the mentioned
Answer
Answer: c [Reason:] The handshake allows the server to acknowledge and accept the attempt.
5. What is the purpose of the transport layer?
a) TCP Communication takes place
b) UDP Communication takes place
c) Both TCP and UDP Communication takes place
d) None of the mentioned
Answer
Answer: c [Reason:] The Transport layer is where our TCP (or UDP) communication takes place.
6. What does the status code 200 indicate?
a) Error in request
b) Error in response
c) Error in server
d) Successful
Answer
Answer: d [Reason:] The status code 200 indicates a successful response from the server.
7. What does the status code 500 indicate?
a) Error in request
b) Error in response
c) Error in server
d) Successful
Answer
Answer: a [Reason:] The status code 500 means that there was an error when trying to fulfill the request.
8. What does the application layer handle?
a) Top-level communication
b) Bottom-level communication
c) Both Top-level and Bottom-level communication
d) None of the mentioned
Answer
Answer: a [Reason:] The Application layer handles the top-level communication that the client and servers use, like HTTP and SMTP for email clients.
9. Which status code indicates that the server could not find the resource requested?
a) 200
b) 404
c) 500
d) 566
Answer
Answer: b [Reason:] The status code 404 means that the server could not find the resource requested.
10. What is the maximum size of an IP packet for IPv4 or IPv6?
a) 65540
b) 65535
c) 65577
d) 67544
Answer
Answer: b [Reason:] The maximum size of an IP packet for IPv4 or IPv6 is 65535.
Java MCQ Set 4
1. Rhino is originated by
a) Microsoft
b) Mozilla
c) Apple
d) None of the mentioned
Answer
Answer: b [Reason:] 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) none of the mentioned
Answer
Answer: a [Reason:] 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);
Answer
Answer: d [Reason:] 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()
Answer
Answer: c [Reason:] 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 interative shell
b) Starting a one to one shell
c) Creating a thread to do simple programs
d) None of the mentioned
Answer
Answer: a [Reason:] Rhino is distributed as a JAR archieve. 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.*);
Answer
Answer: b [Reason:] Because packages and classes are represented as JavaScript objects, you can assign themto 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. Consider the following code snippet
var f = new java.io.File("/tmp/test"); var out = new java.io.FileWriter(f); out instanceof java.io.Reader
What will be the output for the above code snippet?
a) Error
b) True
c) Exception
d) False
Answer
Answer: d [Reason:] 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) None of the mentioned
Answer
Answer: a [Reason:] 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
Answer
Answer: b [Reason:] Just like the JavaScript classes use new operator to instantiate, so does the Java classes.
10. The new Java arrays can be created into a JavaScript programs using which of the following classes?
a) java.Array
b) java.lang.*
c) java.lang.Array
d) java.lang.reflect.Array
Answer
Answer: d [Reason:] 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.
Java MCQ Set 5
1. What are the events generated by the Node objects called?
a) generators
b) emitters
c) dispatchers
d) highevents
Answer
Answer: b [Reason:] Node objects that generate events (known as event emitters) define an on() method for registering handlers.
2. What is the function used to deregister event handler ‘f’?
a) deleteAllListeners(name)
b) deleteListener(name,f)
c) removerListener(name,f)
d) removeAllListeners(name)
Answer
Answer: c [Reason:] The removeListeners(name,f) is used to deregister event handler f represented as :
emitter.removeListener(name,f)
3. What is the function used to remove all handlers for name events?
a) deleteAllListeners(name)
b) deleteListener(name,f)
c) removerListener(name,f)
d) removeAllListeners(name)
Answer
Answer: d [Reason:] The removeAllListeners(name) is used to remove all handlers from name events represented as :
emitter.removeAllListeners(name)
4. Which function is a synonym for on()?
a) addListener()
b) listeners()
c) once()
d) add()
Answer
Answer: a [Reason:] The on() method is used for registering handlers. addListener() is a synonym for on().
5. Which of the following is an event emitter?
a) once
b) process
c) listeners
d) on
Answer
Answer: b [Reason:] The process object is an event emitter. The Node defines other important globals under the process namespaces that contain properties of that object like version, argv, env, pid,getuid(), cwd(), chdir() and exit().
6. When do uncaught exceptions generate events?
a) When handlers are registered
b) When handlers are deregistered
c) When handler functions are called
d) When handlers do not have a matching catch clause
Answer
Answer: a [Reason:] Uncaught exceptions generate events, if any handlers are registered. Otherwise, the exception just makes Node print an error and exit.
process.on("uncaughtException", function(e) { console.log(Exception, e); });
7. Which among the following POSIX signals generate events?
a) SIGDOWN
b) SIGFLOAT
c) SIGINT
d) SIGSHORT
Answer
Answer: c [Reason:] The SIGINT is a POSIX signal that generates event.
8. What is the method used to pause “data” events?
a) s.pause(); b) s.stop(); c) s.halt(); d) s.wait();
Answer
Answer: a [Reason:] The above code snippet is used to pause data events, for throttling uploads, e.g.
9. When the “end” event fires on EOF when no more data will arrive, which function is called?
a) s.on("data",f); b) s.on("end",f); c) s.on("error",f); d) s.on("default",f);
Answer: b [Reason:] The above code snippet gets “end” event fired on EOF when no more data will arrive.Answer
10. What will be the return value of the write() method when the Node cannot write the data immediately and has to buffer it internally?
a) 0
b) 1
c) True
d) False
Answer
Answer: d [Reason:] The write() method never blocks. If Node cannot write the data immediately and has to buffer it internally, the write() method returns false.