Java MCQ Number 01107

Java MCQ Set 1

1. How does applet and servlet communicate?
a) HTTP
b) HTTPS
c) FTP
d) HTTP Tunneling

Answer

Answer: d [Reason:] Applet and Servlet communicate through HTTP Tunneling.

2. In CGI, process starts with each request and will initiate OS level process.
a) True
b) False

Answer

Answer: a [Reason:] A new process is started with each client request and that corresponds to initiate a heavy OS level process for each client request.

3. Which class provides system independent server side implementation?
a) Socket
b) ServerSocket
c) Server
d) ServerReader

Answer

Answer: b [Reason:] ServerSocket is a java.net class which provides system independent implementation of server side socket connection.

4. What happens is ServerSocket is not able to listen on the specified port?
a) The system exits gracefully with appropriate message
b) The system will wait till port is free
c) IOException is thrwon when opening the socket
d) PortOccupiedException is thrown

Answer

Answer: c [Reason:] public ServerSocket() creates an unbound server socket.It throws IOException if specified port is busy when opening the socket.

5. What does bind() method of ServerSocket offer?
a) binds the serversocket to a specific address (IPAddress and port)
b) binds the server and client browser
c) binds the server socket to the JVM
d) binds the port to the JVM

Answer

Answer: a [Reason:] bind() binds the serverver socket to a specific address (IPAddress and port). If address is null, the system will pick a emphemeral port and valid local address to bind socket.

6. Which of the below are common network protocols?
a) TCP
b) UDP
c) TCP and UDP
d) CNP

Answer

Answer: c [Reason:] Transmission Control Protocol(TCP) and User Datagram Protocol(UDP) are the two common network protocol. TCP/IP allows reliable communication between two applications. UDP is connection less protocol.

7. Which class represents an Internet Protocol address?
a) InetAddress
b) Address
c) IPAddress
d) TCPAddress

Answer

Answer: a [Reason:] InetAddress represents an Internet Protocol address. It provides static methods like getByAddress(), getByName() and other instance methods like getHostName(), getHostAddress(), getLocalHost().

8. What does local IP address start with?
a) 10.X.X.X
b) 172.X.X.X
c) 192.168.X.X
d) 10.X.X.X, 172.X.X.X, or 192.168.X.X

Answer

Answer: d [Reason:] Local IP addresses look like 10.X.X.X, 172.X.X.X, or 192.168.X.X.

9. What happens if IPAddress of host cannot be determined?
a) The system exit with no message
b) UnknownHostException is thrown
c) IOException is thrown
d) Temporary IPAddress is assigned

Answer

Answer: b [Reason:] UnknownHostException is thrown when IPAddress of host cannot be determined. It is an extension of IOException.

10. What is the java method for ping?
a) hostReachable()
b) ping()
c) isReachable()
d) portBusy()

Answer

Answer: c [Reason:] inet.isReachable(5000) is a way to ping a server in java.

Java MCQ Set 2

1. Which mode allows us to run program interactively while watching source code and variables during execution?
a) safe mode
b) debug mode
c) successfully run mode
d) exception mode

Answer

Answer: b [Reason:] Debug mode allows us to run program interactively while watching source code and variables during execution.

2. How can we move from one desired step to another step?
a) breakpoints
b) System.out.println
c) logger.log
d) logger.error

Answer

Answer: a [Reason:] Breakpoints are inserted in code. We can move from one point to another in the execution of program.

3. Which part stores the program arguments and startup parameters?
a) debug configuration
b) run configuration
c) launch configuration
d) project configuration

Answer

Answer: c [Reason:] Launch configuration stores the startup class, program arguments and vm arguments.

4. How to deep dive into the execution of a method from a method call?
a) F3
b) F5
c) F7
d) F8

Answer

Answer: b [Reason:] F5 executes currently selected line and goes to the next line in the program. If the selected line is a method call, debugger steps into the associated code.

5. Which key helps to step out of the caller of currently executed method?
a) F3
b) F5
c) F7
d) F8

Answer

Answer: c [Reason:] F7 steps out to the caller of the currently executed method. This finishes the execution of the current method and returns to the caller of this method.

6. Which view allows us to delete and deactivate breakpoints and watchpoints?
a) breakpoint view
b) variable view
c) debug view
d) logger view

Answer

Answer: a [Reason:] The Breakpoints view allows us to delete and deactivate breakpoints and watchpoints. We can also modify their properties.

7. What is debugging an application which runs on another java virtual machine on another machine?
a) virtual debugging
b) remote debugging
c) machine debugging
d) compiling debugging

Answer

Answer: b [Reason:] Remote debugging allows us to debug applications which run on another Java virtual machine or even on another machine. We need to set certain flags while starting the application.
java -Xdebug -Xnoagent
-Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005.

8. What happens when the value of variable change?
a) changed value pop on the screen
b) variable changes are printed in logs
c) dump of variable changes are printed on screen on end of execution
d) variable tab shows variables highlighted when values change

Answer

Answer: d [Reason:] When a variable value changes, the value in variable tab is highlighted yellow in eclipse.

9. Which perspective is used to run a program in debug view?
a) java perspective
b) eclipse perspective
c) debug perspective
d) jdbc perspective

Answer

Answer: c [Reason:] We can switch from one perspective to another. Debug perspective shows us the breakpoints, variables, etc.

10. How does eclipse provide capability for debugging browser actions?
a) internal web browser
b) chrome web browser
c) firefox web browser
d) internet explorer browser

Answer

Answer: a [Reason:] Eclipse provides internal web browser to debug browser actions.

Java MCQ Set 3

1. Which of the below is not a valid design pattern?
a) Singleton
b) Factory
c) Command
d) Java

Answer

Answer: d [Reason:] Design pattern is a general repeatable solution to a commonly occurring problem in software design. There are various patterns available for use in day to day coding problems.

2. Which of the below author is not a part of GOF (Gang of Four)?
a) Erich Gamma
b) Gang Pattern
c) Richard Helm
d) Ralph Johnson

Answer

Answer: b [Reason:] Four authors named Richard Helm, Erich Gamma, Ralph Johnson and John Vlissides published a book on design patterns. This book initiated the concept of Design Pattern in Software development. They are known as Gang of Four (GOF).

3. Which of the below is not a valid classification of design pattern?
a) Creational patterns
b) Structural patterns
c) Behavioural patterns
d) Java patterns

Answer

Answer: d [Reason:] Java patterns is not a valid classification of design patterns. The correct one is J2EE patterns.

4. Which design pattern provides a single class which provides simplified methods required by client and delagates call to those methods?
a) Adapter pattern
b) Builder pattern
c) Facade pattern
d) Prototype pattern

Answer

Answer: c [Reason:] Facade pattern hides the complexities of the system and provides an interface to the client using which client can access the system.

5. Which design pattern ensures that only one object of particular class gets created?
a) Singleton pattern
b) Filter pattern
c) State pattern
d) Bridge pattern

Answer

Answer: a [Reason:] Singleton pattern involves a single class which is responsible to create an object while making sure that only one object gets created. This class provides a way to access the only object which can be accessed directly without need to instantiate another object of the same class.

6. Which design pattern suggest multiple classes through which request is passed and multiple but only relevant classes carry out operations on the request?
a) Singleton pattern
b) Chain of responsibility pattern
c) State pattern
d) Bridge pattern

Answer

Answer: b [Reason:] Chain of responsibility pattern creates a chain of receiver objects for a particular request. The sender and receiver of a request are decoupled based on the type of request. This pattern is one of the behavioral patterns.

7. Which design pattern represents a way to access all the objects in a collection?
a) Iterator pattern
b) Facade pattern
c) Builder pattern
d) Bridge pattern

Answer

Answer: a [Reason:] Iterator pattern represents a way to access the elements of a collection object in sequential manner without the need to know its underlying representation.

8. What does MVC pattern stands for ?
a) Mock View Control
b) Model view Controller
c) Mock View Class
d) Model View Class

Answer

Answer: b [Reason:] Model represents an object or JAVA POJO carrying data.View represents the visualization of the data that model contains.Controller acts on both model and view.It is usually used in web development.

9. Is design pattern a logical concept?
a) True
b) False

Answer

Answer: a [Reason:] Design pattern is a logical concept. Various classes and frameworks are provided to enable users to implement these design patterns.

10. Which design pattern works on data and action taken based on data provided?
a) Command pattern
b) Singleton pattern
c) MVC pattern
d) Facade pattern

Answer

Answer: a [Reason:] Command pattern is a data driven design pattern. It is a behavioral pattern. A request is wrapped under an object as command and passed to the invoker object.The invoker object looks for the appropriate object which can handle this command and passes this command to the corresponding object which executes the command.

Java MCQ Set 4

1. Which of the following is not an Enterprise Beans type?
a) Doubleton
b) Singleton
c) Stateful
d) Stateless

Answer

Answer: a [Reason:] Stateful, Stateless and Singleton are session beans.

2. Which of the following is not true about Java beans?
a) Implements java.io.Serializable interface
b) Extends java.io.Serializable class
c) Provides no argument constructor
d) Provides setter and getter methods for its properties

Answer

Answer: b [Reason:] java.io.Serializable is not a class. Instead it is an interface. Hence it cannot be extended.

3. Which file separator should be used by MANIFEST file?
a) /
b)
c) –
d) //

Answer

Answer: a [Reason:] MANIFEST file uses classes using / file separator.

4. Which of the following is correct error when loading JAR file with duplicate name?
a) java.io.NullPointerException
b) java.lang.ClassNotFound
c) java.lang.ClassFormatError
d) java.lang.DuplicateClassError

Answer

Answer: c [Reason:] java.lang.ClassFormatError: Duplicate Name error is thrown when .class file in the JAR contains a class whose class name is different from the expected name.

5. Java Beans are extremely secured?
a) True
b) False

Answer

Answer: b [Reason:] JavaBeans do not add any security features to the Java platform.

6. Which of the following is not feature of Beans?
a) Introspection
b) Events
c) Persistence
d) Serialization

Answer

Answer: d [Reason:] Serialization is not the feature of Java Beans. Introspection, Customization, Events, Properties and Persistence are the features.

7. What is the attribute of java bean to specify scope of bean to have single instance per Spring IOC?
a) prototype
b) singleton
c) request
d) session

Answer

Answer: b [Reason:] Singleton scope of bean specifies only one instance per spring IOC container. This is the default scope.

8. Which attribute is used to specify initialization method?
a) init
b) init-method
c) initialization
d) initialization-method

Answer

Answer: b [Reason:] init-method is used to specify the initialization method.

9. Which attribute is used to specify destroy method?
a) destroy
b) destroy-method
c) destruction
d) destruction-method

Answer

Answer: b [Reason:] destroy-method is used to specify the destruction method.

10. How to specify autowiring by name?
a) @Qualifier
b) @Type
c) @Constructor
d) @Name

Answer

Answer: a [Reason:] Different beans of the same class are identified by name.

  1. 	     @Qualifier("student1")
  2. 	     @Autowired
  3. 	     Student student1;

Java MCQ Set 5

1. Which of the following contains both date and time?
a) java.io.date
b) java.sql.date
c) java.util.date
d) java.util.dateTime

Answer

Answer: d [Reason:] java.util.date contains both date and time. Whereas, java.sql.date contains only date.

2. Which of the following is advantage of using JDBC connection pool?
a) Slow performance
b) Using more memory
c) Using less memory
d) Better performance

Answer

Answer: d [Reason:] Since the JDBC connection takes time to establish. Creating connection at the application start-up and reusing at the time of requirement, helps performance of the application.

3. Which of the following is advantage of using PreparedStatement in Java?
a) Slow performance
b) Encourages SQL injection
c) Prevents SQL injection
d) More memory usage

Answer

Answer: c [Reason:] PreparedStatement in Java improves performance and also prevents from SQL injection.

4. Which one of the following contains date information?
a) java.sql.TimeStamp
b) java.sql.Time
c) java.io.Time
d) java.io.TimeStamp

Answer

Answer: a [Reason:] java.sql.Time contains only time. Whereas, java.sql.TimeStamp contains both time and date.

5. What does setAutoCommit(false) do?
a) commits transaction after each query
b) explicitly commits transaction
c) does not commit transaction automatically after each query
d) never commits transaction

Answer

Answer: c [Reason:] setAutoCommit(false) does not commit transaction automatically after each query. That saves lot of time of the execution and hence improves performance.

6. Which of the following is used to call stored procedure?
a) Statement
b) PreparedStatement
c) CallableStatment
d) CalledStatement

Answer

Answer: c [Reason:] CallableStatement is used in JDBC to call stored procedure from Java program.

7. Which of the following is used to limit the number of rows returned?
a) setMaxRows(int i)
b) setMinRows(int i)
c) getMaxrows(int i)
d) getMinRows(int i)

Answer

Answer: a [Reason:] setMaxRows(int i) method is used to limit the number of rows that the database returns from the query.

8. Which of the following is method of JDBC batch process?
a) setBatch()
b) deleteBatch()
c) removeBatch()
d) addBatch()

Answer

Answer: d [Reason:] addBatch() is a method of JDBC batch process. It is faster in processing than executing one statement at a time.

9. Which of the following is used to rollback a JDBC transaction?
a) rollback()
b) rollforward()
c) deleteTransaction()
d) RemoveTransaction()

Answer

Answer: a [Reason:] rollback() method is used to rollback the transaction. It will rollback all the changes made by the transaction.

10. Which of the following is not a JDBC connection isolation levels?
a) TRANSACTION_NONE
b) TRANSACTION_READ_COMMITTED
c) TRANSACTION_REPEATABLE_READ
d) TRANSACTION_NONREPEATABLE_READ

Answer

Answer: d [Reason:] TRANSACTION_NONREPEATABLE_READ is not a JDBC connection isolation level.

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.