Complete Study Guide
Complete Study Guide
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
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);
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
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();
}
}
10. Synchronization
Synchronization ensures that multiple threads do not interfere with shared resources. Java provides
synchronized methods and blocks.
15. HTTP
HTTP (Hypertext Transfer Protocol) is used for transferring web pages over the Internet.
Cookie:
- Stored on the client browser.
- Less secure.
19. Scriptlet
Scriptlets (<% %>) allow Java code inside JSP pages.