1.
Which of these packages contains all the classes and methods required for even handling in Java?
Correct Answer
D. java.awt.event
Explanation
The package "java.awt.event" contains all the classes and methods required for event handling in Java. This package provides classes and interfaces for handling events such as mouse clicks, keyboard inputs, and window events. It includes classes like ActionListener, MouseEvent, KeyEvent, and WindowListener, which are essential for implementing event-driven programming in Java. Therefore, "java.awt.event" is the correct answer as it specifically focuses on event handling in Java.
2.
Which of these methods are used to register a mouse motion listener?
Correct Answer
C. AddMouseMotionListner()
Explanation
The correct answer is addMouseMotionListener(). This method is used to register a mouse motion listener in Java. It allows the program to detect and respond to mouse motion events, such as when the mouse is moved or dragged. By using this method, the program can add a listener that will be notified whenever there is a mouse motion event, and perform the desired actions accordingly.
3.
What is a listener in context to event handling?
Correct Answer
B. A listener is a object that is notified when an event occurs.
Explanation
A listener is an object that is notified when an event occurs. This means that when a specific event takes place, the listener object is informed and can perform certain actions or execute specific code in response to that event. The listener acts as a callback mechanism, allowing the program to respond dynamically to events as they happen.
4.
Which of these methods can be used to determine the type of event?
Correct Answer
A. GetID()
Explanation
The method getID() can be used to determine the type of event. This is because the ID of an event can provide information about the type or category of the event. By calling the getID() method, we can retrieve the ID associated with the event and use it to identify the type of event that occurred.
5.
Which of these are integer constants defined in ActionEvent class?
Correct Answer
D. All of the mentioned
Explanation
All of the mentioned options (ALT_MASK, CTRL_MASK, SHIFT_MASK) are integer constants defined in the ActionEvent class. These constants represent modifier keys that can be used in combination with other keys to perform specific actions.
6.
Which of these methods can be used to determine the type of adjustment event?
Correct Answer
C. GetAdjustmentType()
Explanation
The method getAdjustmentType() can be used to determine the type of adjustment event. This method specifically retrieves the adjustment type associated with the event. The other methods getType(), getEventType(), and getEventObjectType() may retrieve different information about the event, but they do not specifically provide the adjustment type. Therefore, getAdjustmentType() is the correct method to use in order to determine the type of adjustment event.
7.
Which of these constant value will change when the button at the end of scroll bar was clicked to increase its value?
Correct Answer
D. UNIT_INCREMENT
Explanation
When the button at the end of the scroll bar is clicked to increase its value, the constant value that will change is UNIT_INCREMENT. This constant represents the amount by which the scroll bar value will increase when the button is clicked.
8.
Which of these is superclass of all Adapter classes?
Correct Answer
A. Applet
Explanation
The superclass of all Adapter classes is Component. The Applet class is a subclass of the Component class, so it is not the superclass. Event and InputEvent are not related to the Adapter classes.
9.
JLabel(String s,Icon i,int align) the align argument can be
Correct Answer
A. LEFT,RIGHT,CENTER,LEADING,TRAILING
Explanation
The align argument in the JLabel constructor can take values such as LEFT, RIGHT, CENTER, LEADING, and TRAILING. These values determine the alignment of the text and icon within the label.
10.
Correct Answer
B. URLConnection Class
URLConnection Class
URLConnection Class
11.
which AWT component is used to create popup list of string items from which only one can be selected at a time.
Correct Answer
B. Choice
Explanation
The Choice component in AWT is used to create a popup list of string items from which only one can be selected at a time. It allows the user to select a single item from a list of options provided. This component is commonly used in forms or menus where the user needs to make a single selection from a predefined set of options.
12.
Which is the passive control
Correct Answer
C. Label
Explanation
The correct answer is Label because a label is a passive control that is used to display text or information. It does not have any interactive functionality or control over user input. The other options, such as Checkbox, Scrollbar, and Button, are all active controls that allow the user to interact with them and perform specific actions.
13.
Select appropriate code for the given output
Correct Answer
A. Code1
14.
Which method is used to display icon on a component?
Correct Answer
B. SetIcon(ImageIcon i)
Explanation
The setIcon(ImageIcon i) method is used to display an icon on a component.
15.
Identify the error in given program
Correct Answer
C. Error in statement in which JTable is created
Explanation
The error in the given program is in the statement where the JTable is created.
16.
What is output of the given code?
Correct Answer
B. Only button Cancel is displayed.
Explanation
The given code is expected to display only the button "Cancel". This can be inferred from the answer choice "Only button Cancel is displayed." The code likely contains a statement or condition that hides or removes the button "OK" from being displayed.
17.
How many types of controls does AWT supports these controls are subclasses of component?
Correct Answer
B. 7
Explanation
AWT (Abstract Window Toolkit) supports 7 types of controls, which are subclasses of the Component class. These controls include Button, Checkbox, Choice, Label, List, TextArea, and TextField. Each control serves a different purpose and allows for user interaction in a graphical user interface.
18.
Identify missing statements in given program
Correct Answer
B. ItemStateChanged(ItemEvent ie);
Explanation
The missing statement in the given program is actionPerformed(ActionEvent ae). This is because the other three methods (adjustmentPerformed, itemStateChanged with ItemEvent, and itemStateChanged with ActionEvent) are already declared and mentioned in the program. However, actionPerformed with ActionEvent is missing, indicating that it needs to be included in the program.
19.
Identify components used in below output
Correct Answer
B. Label, TextField, Button
Explanation
The correct answer is Label, TextField, Button. This is because the output includes a label, a text field, and a button. These components are commonly used in graphical user interfaces to display text, allow user input, and trigger actions respectively. The other options mentioned, such as Applet and Grid Layout, are not components but rather layout managers that can be used to arrange components in a specific way.
20.
What is the purpose of Jtable?
Correct Answer
A. JTable object displays rows and columns of data.
Explanation
The purpose of JTable is to display rows and columns of data.
21.
identify the components used in given output:
Correct Answer
B. Panel, TabbedPane, List
Explanation
The given output includes three components: Panel, TabbedPane, and List. These components are used to create a graphical user interface. The Panel component is a container that can hold other components, while the TabbedPane component allows for the creation of multiple tabs, each containing different content. The List component is used to display a list of items that can be selected by the user.
22.
Select proper output?
Correct Answer
A. Output1
Explanation
The correct answer is "output1" because it is one of the options provided and there is no additional information given to suggest that any of the other options would be the correct output.
23.
What is Purpose of Jtree ?
Correct Answer
D. A tree is a component that presents a hierarchical view of elements
Explanation
The purpose of a JTree is to present a hierarchical view of elements. It is used to display a structure where each element has a parent and can have one or more children. This allows for organizing and visualizing data in a tree-like structure, making it easier to navigate and understand relationships between different elements.
24.
In event handling, A listener is a object that is notified when an event occurs.
Correct Answer
A. True
Explanation
In event handling, a listener is an object that is notified when an event occurs. This means that when an event, such as a button click or a key press, happens, the listener object is informed and can perform some action in response to that event. This allows for the separation of event handling logic from the rest of the program, making it easier to manage and maintain. Therefore, the given answer "True" is correct.
25.
----------------------is a superclass for push button,checkboxes and radiobutton
Correct Answer
C. AbstractButton
Explanation
AbstractButton is the correct answer because it is a superclass for push button, checkboxes, and radio buttons. This means that push button, checkboxes, and radio buttons inherit properties and behaviors from the AbstractButton class. The AbstractButton class provides common functionality for these types of buttons, such as handling user interactions and displaying visual states. Therefore, AbstractButton serves as a higher-level class that encapsulates the shared functionality for these specific types of buttons.
26.
What is output of following program
Correct Answer
C. The Internet address of the host
Explanation
The output of the program will display the Internet address of the host.
27.
The URLConnection class can be used to read and write data to the specified resource referred by the URL?
Correct Answer
A. True
Explanation
The URLConnection class in Java provides a way to establish a connection to a specified resource referred to by a URL. It allows reading and writing data to and from the resource. Therefore, the statement that the URLConnection class can be used to read and write data to the specified resource referred by the URL is true.
28.
Which of these class is used to create servers that listen for either local or remote clientprograms?
Correct Answer
B. ServerSocket
Explanation
The ServerSocket class is used to create servers that listen for either local or remote client programs. This class provides a mechanism for the server to listen for incoming client connections and accept them. Once a client connection is accepted, the server can then communicate with the client using input and output streams. Therefore, the ServerSocket class is the correct choice for creating servers that listen for client programs.
29.
What is the output of this program?import java.net.*;class networking {public static void main(String[] args) throws Exception {URL obj = new URL("http://www.sanfoundry.com/javamcq");URLConnection obj1 = obj.openConnection();System.out.print(obj1.getContentType());} }
Correct Answer
C. Text/html
Explanation
The program uses the URL class to create a URL object with the specified URL "http://www.sanfoundry.com/javamcq". Then, it uses the openConnection() method of the URLConnection class to establish a connection to the URL. Finally, it uses the getContentType() method of the URLConnection class to retrieve the content type of the URL. In this case, the content type is "text/html", which is the correct answer.
30.
Which of these exception is thrown by URL class’s constructors?
Correct Answer
B. MalformedURLException
Explanation
The correct answer is MalformedURLException. The URL class's constructors throw this exception when a malformed URL is encountered. This means that the URL provided is not in the correct format, such as missing the protocol or having invalid characters. The MalformedURLException allows the programmer to handle this specific error and take appropriate action, such as displaying an error message to the user or logging the exception for debugging purposes.
31.
Which of these class is used to encapsulate IP address and DNS?
Correct Answer
C. InetAddress
Explanation
InetAddress is the correct answer because it is a class in Java that is used to encapsulate both IP addresses and DNS names. It provides methods to retrieve and manipulate IP addresses and perform DNS lookups. This class is commonly used in networking applications to identify and communicate with remote hosts using their IP addresses or DNS names.
32.
What is the output of this program?
import java.net.*;class networking {public static void main(String[] args) throws MalformedURLException {URL obj = new URL("http://www.sanfoundry.com/javamcq");System.out.print(obj.getPort());}}
Correct Answer
C. -1
Explanation
The program creates a new URL object with the given URL "http://www.sanfoundry.com/javamcq". The getPort() method is then called on this object. Since the URL does not specify a port number, the getPort() method returns -1.
33.
Which of these class is necessary to implement datagrams?
Correct Answer
D. Both A & B
Explanation
Both the DatagramPacket and DatagramSocket classes are necessary to implement datagrams. The DatagramPacket class represents a datagram packet, which is essentially a container for a message that can be sent over a network. The DatagramSocket class, on the other hand, is responsible for creating a socket that can send and receive datagram packets. Therefore, to implement datagrams, both classes are required.
34.
Which of the method used to to get content type of this file?
Correct Answer
C. GetContentType()
Explanation
The correct answer is "getContentType()". This method is used to retrieve the content type of a file. It is likely a method provided by a programming language or framework that allows developers to access the metadata associated with a file, such as its content type.
35.
TCP,FTP,Telnet,SMTP,POP etc. are examples of ?
Correct Answer
C. Protocol
Explanation
TCP, FTP, Telnet, SMTP, POP, etc. are examples of protocols. A protocol is a set of rules and guidelines that govern the communication between devices in a network. Each of these protocols serves a specific purpose. TCP (Transmission Control Protocol) is responsible for establishing a reliable connection between devices. FTP (File Transfer Protocol) is used for transferring files between computers. Telnet is a protocol that allows remote login to a computer. SMTP (Simple Mail Transfer Protocol) is used for sending emails, and POP (Post Office Protocol) is used for retrieving emails from a mail server.
36.
What is output of following program
Correct Answer
B. Http://www.google.com
Explanation
The given program outputs "http://www.google.com" because it is the only entry in the program that starts with "http://" and ends with ".com". The other entries do not meet this criteria, so they are not included in the output.
37.
What is the output of following program
Correct Answer
B. All IP addresses of www.google.com
Explanation
The correct answer is "All IP addresses of www.google.com". This is because the program is specifically designed to retrieve and display all the IP addresses associated with the domain name "www.google.com". The program does not mention anything about displaying the internet protocols or any other information, so those options are not applicable.
38.
What is the default length of the queue in following constructor of Serversocket? ServerSocket(int portno)
Correct Answer
A. 50
Explanation
The default length of the queue in the ServerSocket constructor with the parameter int portno is 50. This means that the ServerSocket can accept up to 50 incoming connections before it starts rejecting new connections.
39.
Which of these method of DatagramPacket is used to find the length of byte array?
Correct Answer
D. GetLength()
Explanation
The method "getLength()" is used to find the length of the byte array in a DatagramPacket.
40.
Which methods are commonly used in ServerSocket class?
Correct Answer
C. Public Socket accept()
Explanation
The correct answer is "public Socket accept()". This method is commonly used in the ServerSocket class to accept incoming client connections. It waits until a client connection is made and returns a Socket object representing that connection. This allows the server to communicate with the client using the returned Socket object. The other methods mentioned, getOutputStream() and close(), are not commonly used in the ServerSocket class.
41.
In given code ,fill the required methodsimport java.io.*; import java.net.*; public class InetDemo{ public static void main(String[] args){ try{ InetAddress ip=InetAddress.getByName("www.google.com"); System.out.println("Host Name: "+_________________); System.out.println("IP Address: "+__________________); }catch(Exception e){System.out.println(e);} } }
Correct Answer
C. Ip.getHostName(), ip.getHostAddress()
Explanation
The correct answer is "ip.getHostName(), ip.getHostAddress()". This is because the code is trying to print the host name and IP address of "www.google.com". The method "ip.getHostName()" returns the host name, which is "www.google.com", and the method "ip.getHostAddress()" returns the IP address associated with that host, which is the IP address of Google's server. Therefore, using both methods will give us both the host name and IP address of "www.google.com".
42.
UDP you just send packets of data (datagrams) to some IP address on the network
Correct Answer
A. True
Explanation
The given statement is true. UDP (User Datagram Protocol) is a connectionless protocol in which data is sent in the form of packets called datagrams. These datagrams are sent to a specific IP address on the network without establishing a connection beforehand. Unlike TCP, UDP does not guarantee delivery or order of the packets, making it a faster but less reliable protocol for transmitting data.
43.
What is JDBC?
Correct Answer
C. Java API
Explanation
JDBC stands for Java Database Connectivity, which is a Java API that allows Java programs to interact with databases. It provides a set of classes and methods for executing SQL statements, connecting to databases, and retrieving and manipulating data. The correct answer is "Java API" because JDBC is an API specifically designed for database connectivity in Java.
44.
select correct method of statement interface
Correct Answer
D. Public ResultSet executeQuery(String sql)throws SQLException
Explanation
The correct method of the statement interface is "public ResultSet executeQuery(String sql) throws SQLException". This method takes a string parameter representing the SQL query and returns a ResultSet object. It also throws a SQLException if there is an error executing the query.
45.
Write a comment on following method Statement state = con.createStatement();
Correct Answer
B. Creates statement object and returns it as the return value.
Explanation
The given method "Statement state = con.createStatement();" creates a new Statement object and assigns it to the variable "state". The method "createStatement()" is called on the "con" object, which is likely a connection to a database. This method is used to create a new Statement object that can be used to execute SQL queries on the database. The created Statement object is then returned as the return value of the method.
46.
To delete the records from database, use the following sequence of the part of coding:
Correct Answer
A. String b = ""delete from emp where ID=1""; PreparedStatement ps=con.prepareStatement(b);ps.executeUpdate();
Explanation
The correct answer is the first option: String b = "delete from emp where ID=1"; PreparedStatement ps=con.prepareStatement(b);ps.executeUpdate(); This sequence of code uses the correct syntax to delete records from the "emp" table where the ID is equal to 1. The PreparedStatement is used to execute the SQL statement and the executeUpdate() method is used to perform the actual deletion.
47.
The JDBC-ODBC Bridge driver translates the JDBC API to the ODBC API and used with .......
Correct Answer
B. ODBC driver
Explanation
The given correct answer is "ODBC driver". The JDBC-ODBC Bridge driver is used to translate the JDBC API (Application Programming Interface) to the ODBC (Open Database Connectivity) API. This allows Java applications to connect to databases using the ODBC driver. Therefore, the correct answer is the ODBC driver.
48.
The ............................. package contains classes that help in connecting to a database, sending SQL statements to the database, and processing the query results.
Correct Answer
D. Java.sql
Explanation
The java.sql package contains classes that help in connecting to a database, sending SQL statements to the database, and processing the query results. This package provides the necessary tools and functionality for interacting with a database in Java applications. The classes in this package allow developers to establish database connections, execute SQL queries, retrieve and manipulate data, and handle database transactions. This package is essential for any Java application that needs to work with a database.
49.
Which of following statements loads the JDBC-ODBC driver?
Correct Answer
B. Class.forName (“sun.jdbc.odbc.JdbcOdbcDriver”)
Explanation
The correct answer is Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"). This statement is used to load the JDBC-ODBC driver by specifying the fully qualified name of the driver class as a string parameter. The Class.forName method is used to dynamically load the driver class at runtime, and in this case, it loads the JDBC-ODBC driver.
50.
The ................................ method executes a simple query and returns a single Result Set object.
Correct Answer
B. ExecuteQuery()
Explanation
The executeQuery() method is the correct answer because it is used to execute a simple query and retrieve a single Result Set object. This method is typically used when you want to retrieve data from a database, such as selecting records from a table. It returns a Result Set object that contains the data fetched from the database, which can then be processed further in the code.