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

Complete Study Guide

The document is a comprehensive study guide covering databases, JDBC, multithreading, networking, and web technologies. It explains various concepts such as types of databases, JDBC methods, thread lifecycle, and the client-server model, along with examples and code snippets. Additionally, it discusses Hibernate and its architecture, providing a solid foundation for understanding Java-related technologies.

Uploaded by

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

Complete Study Guide

The document is a comprehensive study guide covering databases, JDBC, multithreading, networking, and web technologies. It explains various concepts such as types of databases, JDBC methods, thread lifecycle, and the client-server model, along with examples and code snippets. Additionally, it discusses Hibernate and its architecture, providing a solid foundation for understanding Java-related technologies.

Uploaded by

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

Complete Study Guide with Detailed Answers

1. What is a database?
A database is an organized collection of data that allows users to store, retrieve, and manage
information efficiently. It is widely used in applications like banking, social media, and e-commerce.

Types of Databases:
- Relational Databases (SQL-based): MySQL, PostgreSQL
- NoSQL Databases: MongoDB, Cassandra
- Cloud Databases: AWS RDS, Google Firebase

Example SQL Query to create a table:


CREATE TABLE Students (ID INT PRIMARY KEY, Name VARCHAR(100), Age INT);

2. Differentiate between Statement and PreparedStatement interface.


In Java JDBC, both Statement and PreparedStatement are used to execute SQL queries, but they
have key differences:

Statement:
- Used for executing static SQL queries.
- Does not prevent SQL injection.
- Slower because the query is compiled every time.

PreparedStatement:
- Used for dynamic queries with parameters.
- Prevents SQL injection.
- Faster because the query is precompiled.

Example:
Using Statement:
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Students");

Using PreparedStatement:
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM Students WHERE ID = ?");
pstmt.setInt(1, 101);

3. When to use various JDBC methods?


- execute(): Used for queries that return multiple results.
- executeUpdate(): Used for INSERT, UPDATE, DELETE queries.
- executeQuery(): Used for SELECT queries.
- Statement: Used for simple SQL queries.
- CallableStatement: Used for stored procedures.
- PreparedStatement: Used for parameterized queries.

Example:
ResultSet rs = stmt.executeQuery("SELECT * FROM Students");

4. JDBC Driver
JDBC Driver is a software component that enables Java applications to interact with databases.

Types:
1. JDBC-ODBC Bridge Driver
2. Native-API Driver
3. Network Protocol Driver
4. Thin Driver

Example Connection Code:


Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "user",
"password");

5. Difference between Connection and Statement


Connection:
- Represents a connection to the database.
- Used to manage transactions.

Statement:
- Used to execute SQL queries.
- Works under a Connection object.

6. What is a thread?
A thread is the smallest unit of execution within a program. Java supports multithreading, where
multiple threads run simultaneously.

Example:
class MyThread extends Thread {
public void run() {
System.out.println("Thread is running");
}
}
public class Main {
public static void main(String args[]) {
MyThread t1 = new MyThread();
t1.start();
}
}

7. Multithreading
Multithreading allows multiple threads to run in parallel, improving performance in applications like
gaming and servers.
Example: Implementing Runnable Interface:
class MyRunnable implements Runnable {
public void run() {
System.out.println("Thread is running");
}
}
public class Main {
public static void main(String args[]) {
Thread t1 = new Thread(new MyRunnable());
t1.start();
}
}

8. Explain the following methods.


- sleep(): Pauses thread execution.
- resume(): Resumes a suspended thread (deprecated).
- getPriority(): Returns the thread's priority.
- getName(): Returns the thread's name.
- wait(): Makes the thread wait until notified.
- notify(): Wakes up a waiting thread.

9. Explain Thread Life Cycle


1. New - Thread is created but not started.
2. Runnable - Thread is ready to run.
3. Running - Thread is executing.
4. Blocked - Waiting for a resource.
5. Terminated - Thread has finished execution.

10. Synchronization
Synchronization ensures that multiple threads do not interfere with shared resources. Java provides
synchronized methods and blocks.

11. What is Networking?


Networking is the communication between computers and devices to share resources and data.

12. What is Internet?


The Internet is a global network connecting millions of private and public networks.

13. What is Client-Server Model?


A computing model where a server provides resources/services to multiple clients.

14. Web Browser


A web browser is an application for accessing websites (e.g., Chrome, Firefox).

15. HTTP
HTTP (Hypertext Transfer Protocol) is used for transferring web pages over the Internet.

16. Proxy Server


A proxy server acts as an intermediary between clients and the Internet for security and
performance.

17. What is a Servlet? Explain the servlet types.


A Servlet is a Java program that handles HTTP requests. Types:
1. GenericServlet
2. HttpServlet

18. Difference between Session and Cookie


Session:
- Stored on the server.
- More secure.

Cookie:
- Stored on the client browser.
- Less secure.

19. Scriptlet
Scriptlets (<% %>) allow Java code inside JSP pages.

20. Explain HTTPRequest and HTTPResponse


HTTPRequest - Represents client request to the server.
HTTPResponse - Represents server response to the client.

21. Explain URL Rewriting


URL Rewriting appends session data to URLs for maintaining state in web applications.

22. What is Hibernate?


Hibernate is a Java ORM framework that maps Java objects to database tables.

23. How is SQL query created in Hibernate?


Using HQL (Hibernate Query Language) or Criteria API.

24. What is ORM?


Object-Relational Mapping (ORM) converts relational data into Java objects.

25. How can we add criteria to a SQL query?


By using Hibernate Criteria API.

26. Explain Hibernate Architecture


It consists of SessionFactory, Session, Transaction, and Query interfaces.

27. JDBC Syntax for connecting to MySQL


import java.sql.*;
class MySQLConnection {
public static void main(String args[]) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "user",
"password");
System.out.println("Connected to Database");
con.close();
} catch(Exception e) { System.out.println(e); }
}
}

You might also like