0% found this document useful (0 votes)
4 views6 pages

Advance Programming Imp Notes

The document contains a compilation of important questions and answers related to Java programming, covering topics such as JDBC, Lambda expressions, multithreading, TCP/UDP, and GUI components. It includes 20 short questions, 4 long questions with code examples, and 20 multiple choice questions (MCQs) with answers. The content serves as a study guide for Java concepts and their practical applications.

Uploaded by

wetiri2686
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Advance Programming Imp Notes

The document contains a compilation of important questions and answers related to Java programming, covering topics such as JDBC, Lambda expressions, multithreading, TCP/UDP, and GUI components. It includes 20 short questions, 4 long questions with code examples, and 20 multiple choice questions (MCQs) with answers. The content serves as a study guide for Java concepts and their practical applications.

Uploaded by

wetiri2686
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

20 Important Short Questions

1. What is JDBC?
JDBC (Java Database Connectivity) is an API to connect and execute queries with
databases from Java programs.

2. What is ODBC?
ODBC is a standard API that allows accessing databases using any language. JDBC is Java-
specific.

3. What is a ResultSet in JDBC?


It's a table-like structure that holds data returned by an SQL query.

4. How do you insert data in JDBC?


Using PreparedStatement with INSERT INTO SQL queries.

5. What is SQL metadata?


Metadata gives info about the database (tables, columns) using DatabaseMetaData.

6. What is Lambda Expression in Java?


A short form of writing a method using ->, introduced in Java 8 for functional
programming.

7. Why use Lambda Expressions?


They reduce boilerplate code and are useful for writing anonymous methods.

8. What is a functional interface?


An interface with only one abstract method. Example: Runnable.

9. What is multithreading?
Running multiple threads (parts of program) at the same time for efficiency.

10. What is concurrency in Java?


Concurrency means executing multiple tasks or threads at once.

11. What is a thread in Java?


A thread is the smallest unit of execution. Java uses Thread class for it.

12. How to create a thread?


By extending Thread class or implementing Runnable interface.

13. What is TCP?


Transmission Control Protocol – reliable, connection-based data transfer.
14. What is UDP?
User Datagram Protocol – fast, connectionless, less reliable than TCP.

15. What is RMI in Java?


Remote Method Invocation allows calling methods of objects located on other
machines.

16. What is GUI in Java?


GUI (Graphical User Interface) means creating windows, buttons, forms using Swing or
JavaFX.

17. What is an Event Listener in Java GUI?


It handles user actions like button clicks, mouse moves, etc.

18. What is a Layout Manager?


It controls the layout/position of GUI components in a container.

19. What is PreparedStatement?


A JDBC object used to execute precompiled SQL statements with parameters.

20. What is executeUpdate() in JDBC?


A method that executes SQL statements like INSERT, UPDATE, DELETE.

4 Long Questions (With Concepts + Code)

1. Explain JDBC with example.

 JDBC connects Java apps with databases.

 Steps:

1. Load Driver

2. Create Connection

3. Create Statement

4. Execute Query

5. Close Connection

Code Example:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");

PreparedStatement pst = con.prepareStatement("INSERT INTO users(name) VALUES(?)");


pst.setString(1, "Ali");

pst.executeUpdate();

2. Explain Lambda Expressions with example.

 Lambda is anonymous function.

 Syntax: (param) -> {body}

Code Example:

Runnable r = () -> System.out.println("Running with Lambda");

Thread t = new Thread(r);

t.start();

3. Explain Multi-threading in Java.

 Multithreading allows multiple threads to run parallel.

 Improves performance and speed.

Code Example:

class MyThread extends Thread {

public void run() {

System.out.println("Thread Running...");

MyThread t = new MyThread();

t.start();

4. Explain TCP and UDP with differences.

 TCP: Reliable, connection-oriented. Used in web, email.

 UDP: Fast, connectionless. Used in games, videos.


20 Multiple Choice Questions (MCQs) with Answers

1. Which class is used to load JDBC driver?


A) Class.forName() ✅
B) DriverManager.load()
C) Driver.load()
D) None

2. Which method is used to insert record in JDBC?


A) executeQuery()
B) insert()
C) executeUpdate() ✅
D) update()

3. Which interface is used in Lambda?


A) Functional ✅
B) Serializable
C) Runnable
D) Cloneable

4. Lambda expressions were introduced in Java:


A) Java 6
B) Java 7
C) Java 8 ✅
D) Java 5

5. UDP is:
A) Connection-based
B) Reliable
C) Fast but not reliable ✅
D) None

6. JDBC stands for:


A) Java Database Command
B) Java DB Connector
C) Java Database Connectivity ✅
D) Java Binary Code

7. Which is a valid Lambda syntax?


A) -> ()
B) () => {}
C) () -> {} ✅
D) None

8. Thread is created using:


A) Runnable only
B) Thread class only
C) Runnable or Thread ✅
D) None

9. TCP is used for:


A) Email ✅
B) Video Games
C) Live Streaming
D) Voice Calls

10. Which protocol is not connectionless?


A) UDP
B) TCP ✅
C) HTTP
D) FTP

11. Which method starts a thread?


A) begin()
B) run()
C) start() ✅
D) init()

12. PreparedStatement is used for:


A) Select only
B) Insert only
C) Precompiled SQL ✅
D) None

13. ResultSet is returned by:


A) executeUpdate()
B) executeQuery() ✅
C) runQuery()
D) result()

14. GUI stands for:


A) Graph User Interface
B) General User Interface
C) Graphical User Interface ✅
D) None

15. RMI stands for:


A) Remote Method Interface
B) Remote Method Invocation ✅
C) Runtime Machine Interface
D) None

16. Which is layout manager in Java?


A) BorderLayout ✅
B) ManagerLayout
C) FrameLayout
D) None

17. Which package is used for GUI?


A) java.util
B) java.io
C) javax.swing ✅
D) java.sql

18. Java uses which class to create a connection?


A) DriverManager ✅
B) Connector
C) SQLManager
D) DBManager

19. Lambda is used for:


A) Writing loops
B) Functional programming ✅
C) Creating classes
D) None

20. UDP is used in:


A) Banking systems
B) File transfer
C) Online gaming ✅
D) Emails

You might also like