Java SQL and Inner Classes Quiz
45 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which method is used to obtain the number of columns in a ResultSet?

  • getColumnCount() (correct)
  • getNumberOfColumn()
  • getColumns()
  • getMaxColumn()

What is the correct return type of the method execute(String query)?

  • boolean (correct)
  • ResultSet
  • int
  • void

Which of the following statements is correct for executing a SQL query using Statement?

  • ResultSet rs = stmt.selectQuery("SELECT ROLLNO, STUDNAME FROM STUDENT")
  • ResultSet rs = stmt.executeQuery("SELECT ROLLNO, STUDNAME FROM STUDENT") (correct)
  • ResultSet rs = stmt.executeSelect("SELECT ROLLNO, STUDNAME FROM STUDENT")
  • ResultSet rs = stmt.executeUpdate("SELECT ROLLNO, STUDNAME FROM STUDENT")

Which interface includes the commit() method?

<p>Connection (B)</p> Signup and view all the answers

Which of the following SQL statement categories do INSERT, DELETE, and UPDATE belong to?

<p>Data Manipulation Language (C)</p> Signup and view all the answers

What will the code output when executed?

<p>data is 30 (B)</p> Signup and view all the answers

Which constants are defined by the AdjustmentEvent class?

<p>BLOCK_DECREMENT, BLOCK_INCREMENT, TRACK (D)</p> Signup and view all the answers

What notation is used to access a nested class in Java?

<p>. (dot) (C)</p> Signup and view all the answers

What type of mechanism does Inner class provide in Java?

<p>Security (A)</p> Signup and view all the answers

Which constants are defined by the ItemEvent class?

<p>DESELECTED, SELECTED (D)</p> Signup and view all the answers

Non-static nested classes are commonly known as what?

<p>inner classes (B)</p> Signup and view all the answers

What is the main purpose of using inner classes?

<p>all of these (C)</p> Signup and view all the answers

Can outer Java classes access the private members of inner classes?

<p>Yes (A)</p> Signup and view all the answers

What is the result when using an adapter class in programming?

<p>It can reduce boilerplate code significantly. (A)</p> Signup and view all the answers

Which event does the method mouseClicked specifically handle?

<p>Mouse clicked (D)</p> Signup and view all the answers

Which class serves as a superclass of ContainerEvent?

<p>ComponentEvent (D)</p> Signup and view all the answers

In an adapter class that contains 5 methods, how many methods are overridden typically?

<p>5 (B)</p> Signup and view all the answers

Which is the abstract adapter class for receiving keyboard focus events?

<p>FocusAdapter (A)</p> Signup and view all the answers

Adapter classes and interfaces are the same.

<p>False (B)</p> Signup and view all the answers

Adapter classes help save which of the following?

<p>All of the above (D)</p> Signup and view all the answers

What is the primary error in the provided Java applet code?

<p>The variable p1 cannot be found (B), JPanel p2 is not initialized (C)</p> Signup and view all the answers

Which of the following is a legitimate return type for a controller action method?

<p>All of these (D)</p> Signup and view all the answers

Which step is NOT part of the execution process in an MVC project?

<p>Creating a database connection (A)</p> Signup and view all the answers

Which method is used to add a GUI component to a Frame object?

<p>.add(Component c) (C)</p> Signup and view all the answers

Which statement about a controller in MVC is TRUE?

<p>The controller executes an incoming request (D)</p> Signup and view all the answers

Which class is responsible for encapsulating an IP address and DNS in Java?

<p>InetAddress (A)</p> Signup and view all the answers

Which option is NOT one of the JFrame operations for window closure?

<p>LOWER_ON_CLOSE (C)</p> Signup and view all the answers

What is the return type of the getString() method?

<p>String (D)</p> Signup and view all the answers

What is the correct SQL statement to delete an employee by ID in the provided code?

<p>sql=&quot;delete from Employee where empid=&quot; + num (B)</p> Signup and view all the answers

Which class do the methods 'add(Component c)', 'setSize(int width, int height)', 'setLayout(LayoutManager m)', and 'setVisible(boolean)' belong to?

<p>Component class (B)</p> Signup and view all the answers

Which container does not have a title bar or menu bar but can contain components like buttons and text fields?

<p>Panel (B)</p> Signup and view all the answers

What is used to create an object that displays a list of choices?

<p>JList (C)</p> Signup and view all the answers

Which of the following is used for storing partial data results and returning values for methods?

<p>Container (C)</p> Signup and view all the answers

Which class is associated with the processActionEvent( ) processing method?

<p>JButton, JList, JMenuItem (A)</p> Signup and view all the answers

Which feature does Swing support that differentiates it from AWT?

<p>It follows MVC architecture. (B)</p> Signup and view all the answers

What makes Swing components lightweight compared to AWT components?

<p>They do not rely on native GUI components. (B)</p> Signup and view all the answers

What method is used to retrieve the local address of a server socket?

<p>getLocalHost() (C)</p> Signup and view all the answers

Which method is used to bind a server socket to a specific address and port?

<p>bind() (D)</p> Signup and view all the answers

The accept method is primarily used for which purpose?

<p>Accepting incoming client connections (A)</p> Signup and view all the answers

Which class represents a socket that facilitates communication between a client and a server?

<p>java.net.Socket (D)</p> Signup and view all the answers

What does the statement 'Socket s1 = new Socket(localhost, 1346);' signify?

<p>A client socket is created to connect with a specified hostname and port. (C)</p> Signup and view all the answers

What will the output be for the following code: 'int a = s1.getPort(); System.out.println(a);' if s1 is created with 'new Socket("localhost", 1234);'?

<p>1234 (B)</p> Signup and view all the answers

Which of the following constructors is a correct way to instantiate a ServerSocket?

<p>All of the above (D)</p> Signup and view all the answers

What output is produced by 'System.out.println(ss.getLocalPort());' if ss is created with 'new ServerSocket(1349);'?

<p>1349 (B)</p> Signup and view all the answers

Signup and view all the answers

Flashcards

What does the next() method do in ResultSet?

The next() method of the ResultSet interface is used to move the cursor to the next row in the result set. It returns true if there is a next row, and false if there are no more rows.

What is the purpose of the Statement interface?

The Statement interface encapsulates an SQL statement. It's used to parse, compile, plan, and execute SQL queries.

What does the getMetaData() method return?

The getMetaData() method of the ResultSet interface returns a ResultSetMetaData object, which contains information about the result set, such as the number of columns and their names.

How to find the number of columns in a ResultSet?

The getColumnCount() method of the ResultSet interface returns the number of columns in the result set.

Signup and view all the flashcards

Which interface does the commit() method belong to?

The commit() method belongs to the Connection interface. It commits the current transaction, making all changes permanent in the database.

Signup and view all the flashcards

What is the purpose of an Adapter Class?

Adapter class makes programmers task easier by providing a simplified way to handle events. It has methods that correspond to the event listener interface, but with empty implementations.

Signup and view all the flashcards

Overridding methods in an Adapter Class

When using an Adapter class, all the methods in the superclass must be overridden. If the class contains 5 methods, all 5 must be overridden to handle specific events.

Signup and view all the flashcards

What is a ComponentEvent?

ComponentEvent is a superclass for events related to changes in a component's state, such as resizing, moving, or hiding. This class represents the events that occur when the state of a component changes.

Signup and view all the flashcards

What is ComponentAdapter?

The ComponentAdapter class is an abstract adapter class that provides empty implementations of the methods in the ComponentListener interface. This class simplifies event handling for components in Java.

Signup and view all the flashcards

What is MouseAdapter?

The MouseListener interface defines methods for handling mouse events. The MouseAdapter class simplifies mouse event handling by providing empty implementations of all the methods in the MouseListener interface. By extending MouseAdapter, you only need to override the methods you're interested in.

Signup and view all the flashcards

What is AWTEvent?

The AWTEvent class is the superclass for all AWT (Abstract Window Toolkit) events. Other event classes, like ComponentEvent and WindowEvent, inherit from AWTEvent. This provides a common base for all AWT events, making event handling more structured and consistent.

Signup and view all the flashcards

What is FocusAdapter?

The FocusListener interface is used to handle events related to changes in the focus of a component. The FocusAdapter class provides default empty implementations for the FocusListener methods, simplifying event handling for focus changes.

Signup and view all the flashcards

Why are Adapter Classes used?

Adapter classes provide a way to implement only the methods you need, avoiding unnecessary overrides and making your code cleaner and more efficient.

Signup and view all the flashcards

Outer class access to inner class private members

A nested class can access private members of its enclosing class even if it is not declared as static. This is because it has access to the enclosing class's private members

Signup and view all the flashcards

Inner classes provide security

Inner classes provide a mechanism for encapsulating code within a class, enhancing security and protection. By limiting access to members, it can be easier to ensure data integrity and prevent unauthorized modifications.

Signup and view all the flashcards

What is an inner class?

Inner class is a class declared inside another class. It provides a way to organize and modularize code within a larger class. It can only access the members of the outer class, including private ones, even if the inner class is declared as non-static

Signup and view all the flashcards

What are AdjustmentEvent constants?

The AdjustmentEvent class defines constants for various events, including BLOCK_DECREMENT, BLOCK_INCREMENT, and TRACK. These constants represent various adjustments that can be applied to a component.

Signup and view all the flashcards

ItemEvent constants

The ItemEvent class defines constants to denote changes in the selection state of an item, such as DESELECTED and SELECTED, representing whether an item has been selected or not.

Signup and view all the flashcards

What are non-static nested classes?

Non-static nested classes have a close dependency on the outer class. They cannot be instantiated without an instance of the outer class. They essentially act as inner members of the outer class and are also known as inner classes.

Signup and view all the flashcards

Why use inner classes?

Inner classes are useful to:

  1. Code optimization, by reducing redundancy and enhancing readability.
  2. Access all members of the outer class, including private members.
  3. Improve code readability and maintainability, by grouping related tasks.
Signup and view all the flashcards

How to access inner class members?

To access members of an inner class, you can use the 'dot' notation (.) to access the inner class's members.

Signup and view all the flashcards

What is the accept() method used for?

The accept() method in Java is used to establish a connection with a client socket that is attempting to connect to the server socket.

Signup and view all the flashcards

SQL DELETE Statement

A SQL statement that removes rows from a table based on a specific condition. In this case, it removes rows from the 'Employee' table where 'empid' matches the inputted 'num'.

Signup and view all the flashcards

What is the ServerSocket class used for?

The ServerSocket class is used to create a server socket, which listens for incoming client connections. It is the foundation for server-side networking.

Signup and view all the flashcards

Component Class

A class in Java that represents a graphical user interface component. It provides methods for adding other components, setting the size, layout, and visibility of the component.

Signup and view all the flashcards

What does the Socket class represent?

The Socket class represents a socket, which is the communication endpoint between a client and a server. It's used for both client-side and server-side networking.

Signup and view all the flashcards

Panel

A container in Java that acts as a blank canvas where you can add buttons, text fields, and other components without a title bar or menu bar. Think of it as a simple area to place GUI elements.

Signup and view all the flashcards

JList

A component in Java used to display a list of choices to the user. Each choice can be selected or deselected independently.

Signup and view all the flashcards

How does the Socket(String hostname, int port) constructor work?

The Socket constructor, Socket(String hostname, int port), creates a client socket and attempts to establish a connection with the specified hostname and port.

Signup and view all the flashcards

ActionListener

A class in Java that is used to handle actions performed by components such as buttons, list items, and menu items. It provides a method called 'processActionEvent()' to handle these actions.

Signup and view all the flashcards

What is the getServerSocket() method used for?

The getServerSocket method is used to retrieve the ServerSocket object that was used to create the current socket. This method is typically used in server-side applications.

Signup and view all the flashcards

Pluggable Look and Feel

A feature of Java Swing, a GUI toolkit, that allows the user interface to adapt to the operating system's theme and appearance. It provides a more native look and feel across different platforms.

Signup and view all the flashcards

What does the getInputStream() method do?

The getInputStream() method of the Socket class returns an InputStream object representing the input stream associated with the socket. It allows you to read data received from the remote endpoint.

Signup and view all the flashcards

MVC (Model View Controller)

A design pattern in software development that separates the presentation, logic, and data management of an application into distinct components. It allows for easier maintenance and separation of concerns.

Signup and view all the flashcards

What does the getOutputStream() method do?

The getOutputStream() method of the Socket class returns an OutputStream object representing the output stream associated with the socket. It allows you to write data to the remote endpoint.

Signup and view all the flashcards

What is the bind() method used for?

The bind() method is used to associate a server socket with a specific port and IP address or local address. This process reserves the port and gets the server ready to listen for connections.

Signup and view all the flashcards

What is the Error in this Java code? p1.add(b1)

A common error in Java programming where a variable is used before it is declared. The compiler cannot find the variable 'p1' because it has not been defined within the scope of the code.

Signup and view all the flashcards

What are some return types for a controller action method?

Controller actions can have different return types depending on the outcome of processing the user request. The 'View Result' returns the view to be rendered, 'Javascript Result' returns JavaScript code to be executed, and 'Redirect Result' redirects to another URL.

Signup and view all the flashcards

What are the steps involved in executing an MVC project?

MVC execution involves handling user requests in a structured manner. First, the application receives a request. Then, it performs routing to determine the appropriate controller. Finally, it creates an MVC request handler to process the request.

Signup and view all the flashcards

Which method is used to add a GUI component to a Frame in Java?

The 'add' method is used in the Frame object to incorporate GUI components into its visual structure. By using the 'add' method, you can embed various GUI elements like buttons, text fields, or panels within the Frame.

Signup and view all the flashcards

What is the main function of the controller in the MVC architecture?

The controller's primary responsibility involves executing the incoming user request within the MVC architecture. It acts as the intermediary between the user interface (view) and the data (model).

Signup and view all the flashcards

Which class combines IP address and DNS information?

The 'netAddress' class encapsulates the IP address and Domain Name System (DNS) information within a single entity. It provides a convenient way to represent and manipulate network addresses.

Signup and view all the flashcards

Which of the following options is NOT a close operation for a JFrame?

A JFrame, a top-level window, provides options for user behavior when you close it. Three options are available: 'DISPOSE_ON_CLOSE' which disposes the window, 'HIDE_ON_CLOSE' which hides the window, and 'DO_NOTHING_ON_CLOSE' which takes no default action. The 'LOWER_ON_CLOSE' option is not available because it is a separate operation for JFrame objects.

Signup and view all the flashcards

What is the return type of the getString() method?

The getString() method is used to retrieve a text string from a user interface. The method returns the collected text data as a string. It allows you to read the input entered by the user.

Signup and view all the flashcards

Study Notes

Adapter Classes

  • Adapter classes provide empty implementations of all methods in an event listener interface.
  • They are used to simplify the process of event handling in Java.
  • Required package for adapter classes is java.awt.event.

Output of Code Examples

  • Different code examples produce different output, depending on the specific actions and methods involved in the code snippet.
  • The output of a code example depends on the implementation of the code's methods and actions.

Additional Questions and Answers

  • Question 1: Classes in Java which have the key listener interface
  • Answer: KeyAdapter
  • Question 2: In Adapter class it is sufficient to include only the methods required for functionality
  • Answer: TRUE
  • Question 3: Adapter class makes programmers task easier.
  • Answer: True
  • Question 4: Which of these methods is defined in MouseMotionAdapter class?
  • Answer: mouseDragged()
  • Question 5: What are the different types of inner classes?
  • Answer: Local, Anonymous
  • Question 6: Which of these is a superclass of all Adapter classes?
  • Answer: Applet
  • Question 7: If an adapter class is inherited there is no need of implementing a listener interfaces
  • Answer: Always
  • Question 8: Adapter class can be also used for incorporating which property ?
  • Answer: All of the above (Inheritance, Polymorphism, Encapsulation)
  • Question 9: Is it sufficient in Adapter classes to include only the methods required?
  • Answer: Yes
  • Question 10: Whether adapter classes use the methods of event classes?
  • Answer: Yes
  • Question 11: Which of these methods is defined in MouseMotionAdapter class?
  • Answer: mouseDragged()
  • Question 12: Which of these is a superclass of all Adapter classes?
  • Answer: Applet
  • Question 13: Which is the abstract adapter class for receiving keyboard focus events?
  • Answer: FocusAdapter
  • Question 14: Adapter Class and interfaces are same?
  • Answer: False
  • Question 15: What are the different types of inner classes?
  • Answer: 1. Local inner classes and 2. Anonymous inner classes
  • Question 16: Adapter class saves?
  • Answer: All of the above (Time, Code, Space)
  • Question 17: Which of these methods is defined in MouseMotionAdapter class?
  • Answer: mouseDragged
  • Question 18: Which of these is a superclass of all Adapter classes?
  • Answer: Applet
  • Question 19: If an adapter class is inherited, is it required to implement listener interfaces?
  • Answer: No
  • Question 20: Which is the abstract adapter class for receiving keyboard focus events?
  • Answer: FocusAdapter
  • Question 21: Are Adapter Class and interfaces same?
  • Answer: No
  • Question 22: Which of these is a superclass of all Adapter classes?
  • Answer: Applet
  • Question 23: In Adapter class, is it sufficient to include only the required methods for the needed functionality?
  • Answer: Yes
  • Question 24: Adapter class makes programmers task easier
  • Answer: True
  • Question 25: What method in Java returns a reference to the component that was added to the container?
  • Answer:'getChild()' :
  • Question 26: A class that has an anonymous name is called as a _________ class in Java?
  • Answer: Anonymous
  • Question 27: What are the two ways to create a Java Anonymous inner class?
  • Answer: Class, Interface
  • Question 28: Which event is generated when a button is pressed?
  • Answer: ActionEvent
  • Question 29: if you compile a file containing inner classes, how many class files will be created?
  • Answer: 2
  • Question 30: When a component is added or removed from a container, which event is generated?
  • Answer: ContainerEvent
  • Question 31: Which of the following is the correct method for displaying a component in Java AWT's paint method?
  • Answer: drawString()
  • Question 32: Which class is the superclass in the inheritance hierarchy of all AWT event objects.
  • Answer: Event
  • Question 33: Which method returns the object that has generated an event?
  • Answer: getSource()
  • Question 34: What class adapts the methods of another class by giving a different name to the same methods?
  • Answer: Adapter Class
  • Question 35: If a class MyWindowAdapter extends WindowAdapter and implements the WindowListener interface, how is it registered?
  • Answer: this.addWindowListener(new MyWindowAdapter());
  • Question 36: What are the common methods of the CardLayout class?
  • Answer: next, previous, first
  • Question 37: What is the name for a class defined inside another class?
  • Answer: Inner Class
  • Question 38: What are the different types of inner classes?
  • Answer: Local and Anonymous inner classes
  • Question 39: Which class is used for handling mouse events?
  • Answer: MyMouseListener
  • Question 40: Which event is generated when a character is entered in a text field?
  • Answer: TextEvent
  • Question 41: Which constants are defined by MouseWheelEvent?
  • Answer: WHEEL_PAGE_SCROLL, WHEEL_TRACK_SCROLL, WHEEL_BLOCK_SCROLL, WHEEL_UNIT_SCROLL
  • Question 42: What is the return type of isTemporary() method?
  • Answer: boolean
  • Question 43: Which abstract class is a subclass of ComponentEvent and handles component input events?
  • Answer: InputEvent
  • Question 44: Can inner classes access all members of the outer class?
  • Answer: Yes
  • Question 45: What can be achieved by using inner classes?
  • Answer: code optimization
  • Question 46: Which method returns the object that generated an event in AWT/Swing ?
  • Answer: getsource()
  • Question 47: Which class is a class that is declared inside a class or interface in Java?
  • Answer: Inner class
  • Question 48: Which interfaces do you need to implement to handle mouse events ?
  • Answer: MouseListener and MouseMotionListener interfaces
  • Question 49: Which method in the Container class is used to return a reference to the component's container?
  • Answer: getParent()
  • Question 50: What is a class that doesn't have a name or is known by an implicit identifier known as in Java?
  • Answer: Anonymous class
  • Question 51: What are two ways to create an anonymous inner class in Java?
  • Answer: Using an interface or a class
  • Question 52: Which event occurs when a button is pressed?
  • Answer: ActionEvent
  • Question 53: How many class files are created when compiling a file with inner classes?
  • Answer: Two
  • Question 54: What event is generated when a component is added to or removed from a container?
  • Answer: ContainerEvent
  • Question 55: What is the protocol that web browsers use to transfer data?
  • Answer: HTTP

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

Test your knowledge on Java SQL execution, ResultSet methods, and inner classes. This quiz covers key concepts, methods, and event handling used in Java programming. Challenge yourself and see how well you understand these important topics!

More Like This

Use Quizgecko on...
Browser
Browser