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

Adv. Java Imp

The document provides an overview of various concepts related to threads, networking, and database connectivity in Java. It covers thread priority, synchronization, multithreading, UDP and TCP communication, JDBC, and HTTP communication, along with examples and diagrams for better understanding. Additionally, it briefly mentions the roles of firewalls and proxy servers in network security and communication.
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)
13 views5 pages

Adv. Java Imp

The document provides an overview of various concepts related to threads, networking, and database connectivity in Java. It covers thread priority, synchronization, multithreading, UDP and TCP communication, JDBC, and HTTP communication, along with examples and diagrams for better understanding. Additionally, it briefly mentions the roles of firewalls and proxy servers in network security and communication.
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

1.

Define thread priority


Thread priority defines the importance of a thread for CPU execution.
Higher priority threads are executed first (range: 1–10).
Default is 5 (NORM_PRIORITY).
It helps in scheduling multiple threads efficiently.
Example:
class Demo {
public static void main(String[] args) {
Thread t = new Thread();
[Link](Thread.MAX_PRIORITY);
[Link]([Link]());
}
}
Diagram:
High Priority → Executed First
Low Priority → Executed Later

2. Define thread Synchronization


Synchronization controls access of shared resources by multiple threads.
It prevents data inconsistency and race conditions.
Only one thread executes synchronized block at a time.
Example:
class Table {
synchronized void print(int n) {
for(int i=1;i<=5;i++)
[Link](n*i);
}
}
Diagram:
Thread1 ─┐
├─> [Synchronized Method] → Safe Output
Thread2 ─┘

3. Thread
A thread is a lightweight process used for multitasking.
Threads share memory but run independently.
Example:
class MyThread extends Thread {
public void run() {
[Link]("Thread running");
}
public static void main(String[] args) {
new MyThread().start();
}
}
Diagram:
Process
├─ Thread1
└─ Thread2
4. UDP Server Socket
UDP is connectionless communication using datagrams.
No guarantee of delivery or order.
Example:
import [Link].*;
class UDPServer {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket(9876);
byte[] b = new byte[1024];
DatagramPacket dp = new DatagramPacket(b, [Link]);
[Link](dp);
[Link](new String([Link]()));
}
}
Diagram:
Client ---> Datagram ---> Server
(No connection)

5. Networking
Networking connects computers to share data/resources.
Uses protocols like TCP/IP.
Example (simple connection):
import [Link].*;
class NetDemo {
public static void main(String[] args) throws Exception {
InetAddress ip = [Link]("localhost");
[Link](ip);
}
}
Diagram:
PC1 ---- Router ---- PC2

6. Multithreading
Multithreading executes multiple threads simultaneously.
Improves performance and CPU utilization.
Example:
class A extends Thread {
public void run() { [Link]("Thread A"); }
}
class B extends Thread {
public void run() { [Link]("Thread B"); }
}
class Test {
public static void main(String[] args) {
new A().start();
new B().start();
}
}
Diagram:
Process
├─ T1
├─ T2
└─ T3

7. TCP/IP Client Socket


TCP is connection-oriented and reliable.
Client connects to server using socket.
Example:
import [Link].*;
import [Link].*;
class Client {
public static void main(String[] args) throws Exception {
Socket s = new Socket("localhost", 1234);
OutputStream out = [Link]();
[Link]("Hello Server".getBytes());
}
}
Diagram:
Client ===== TCP Connection ===== Server

8. JDBC
JDBC connects Java with database to execute SQL queries.
Example:
import [Link].*;
class JDBCEx {
public static void main(String[] args) throws Exception {
Connection con = [Link](
"jdbc:mysql://localhost:3306/test","root","1234");
Statement st = [Link]();
ResultSet rs = [Link]("SELECT * FROM student");
while([Link]())
[Link]([Link](1));
}
}
Diagram:
Java App → JDBC → Database

9. Thread Life Cycle


Thread moves through states: New → Runnable → Running → Waiting → Terminated.
Example:
class Life extends Thread {
public void run() {
[Link]("Running");
}
public static void main(String[] args) {
Life t = new Life();
[Link]();
}
}
Diagram:
New → Runnable → Running → Waiting → Dead

10. JDBC Architecture


JDBC uses drivers to connect application to database.
Example:
[Link]("[Link]");
Connection con = [Link](url,"root","1234");
Diagram:
App → JDBC API → Driver → Database

11. HTTP Communication


Client sends request, server sends response using HTTP protocol.
Example:
import [Link].*;
class HTTPDemo {
public static void main(String[] args) throws Exception {
URL url = new URL("[Link]
[Link]([Link]());
}
}
Diagram:
Client → HTTP Request → Server
Client ← HTTP Response ← Server

12. IP Address Class


IP address identifies devices in network.
Class A, B, C are commonly used.
Example:
import [Link].*;
class IPDemo {
public static void main(String[] args) throws Exception {
InetAddress ip = [Link]();
[Link]([Link]());
}
}
Diagram:
IP = Network ID + Host ID
Example: [Link]

13. Short Notes


1) Firewall
Firewall protects network by filtering traffic.
Example (conceptual):
Diagram:
Internet → Firewall → Private Network
2) Proxy Server
Proxy acts as intermediary between client and internet.
Example:
[Link]("[Link]","[Link]");
[Link]("[Link]","8080");
Diagram:
Client → Proxy → Internet

You might also like