0% found this document useful (0 votes)
3 views7 pages

NPTEL_Java_Extra_Topics

The document outlines several Java topics not covered in Edureka videos, including Java Applets, AWT, Servlets, and Networking. Each section provides definitions, key features, lifecycle methods, and example code for better understanding. It serves as a supplementary guide for learning these Java concepts.

Uploaded by

biswastushar672
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)
3 views7 pages

NPTEL_Java_Extra_Topics

The document outlines several Java topics not covered in Edureka videos, including Java Applets, AWT, Servlets, and Networking. Each section provides definitions, key features, lifecycle methods, and example code for better understanding. It serves as a supplementary guide for learning these Java concepts.

Uploaded by

biswastushar672
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/ 7

### Java Topics Not Covered in Edureka Video (Based on NPTEL PDF)

---

## 1. **Java Applets**

### Definition:

Applets are small Java programs that are embedded in web pages and run in a web browser using a Java-enabled

plugin. They are used to create interactive features such as games, graphics, or animations.

### Key Features:

- Do not have a `main()` method.

- Extend `java.applet.Applet` class or `javax.swing.JApplet` for Swing-based applets.

- Run in a browser or applet viewer.

### Applet Lifecycle Methods:

1. `init()` - Called once when the applet is first loaded.

2. `start()` - Called every time the applet becomes visible.

3. `paint(Graphics g)` - Used to render output (like drawing).

4. `stop()` - Called when the applet is no longer visible.

5. `destroy()` - Called when the applet is closed/unloaded.

### Example Code:

```java

import java.applet.Applet;

import java.awt.Graphics;
public class HelloApplet extends Applet {

public void paint(Graphics g) {

g.drawString("Welcome to Applet", 20, 20);

```

### HTML to Load Applet:

```html

<applet code="HelloApplet.class" width="300" height="200"></applet>

```

---

## 2. **Abstract Window Toolkit (AWT)**

### Definition:

AWT is Java's original platform-dependent GUI library. It allows creation of graphical applications with components such

as windows, buttons, text fields, etc.

### Components:

- `Frame`, `Button`, `Label`, `TextField`, `TextArea`, `Checkbox`, `Choice`, etc.

### Layout Managers:

- FlowLayout

- BorderLayout

- GridLayout

- CardLayout
### Event Handling:

- Delegation event model.

- Interfaces like `ActionListener`, `WindowListener`.

- Classes like `ActionEvent`, `WindowEvent`.

### Example:

```java

import java.awt.*;

import java.awt.event.*;

public class AWTExample {

public static void main(String[] args) {

Frame f = new Frame("AWT Example");

Label l = new Label("Enter your name:");

TextField tf = new TextField();

Button b = new Button("Submit");

l.setBounds(50, 50, 150, 20);

tf.setBounds(50, 80, 150, 20);

b.setBounds(50, 110, 60, 30);

f.add(l); f.add(tf); f.add(b);

f.setSize(300, 200);

f.setLayout(null);

f.setVisible(true);

}
}

```

---

## 3. **Java Servlets**

### Definition:

Servlets are server-side Java programs used to create dynamic web content. They run inside a servlet container (like

Apache Tomcat).

### Servlet Lifecycle:

1. `init()` - Initialization logic

2. `service()` - Handles client requests

3. `destroy()` - Cleanup logic

### HTTP Servlet Methods:

- `doGet()` - Handles HTTP GET requests

- `doPost()` - Handles HTTP POST requests

### Required Packages:

- `javax.servlet.*`

- `javax.servlet.http.*`

### Example:

```java

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

res.setContentType("text/html");

PrintWriter out = res.getWriter();

out.println("<h1>Hello from Servlet</h1>");

```

---

## 4. **Java Networking**

### Definition:

Java supports networking through classes in the `java.net` package. It enables communication between computers over

a network using TCP/IP protocols.

### Key Classes:

- `Socket` - Used by the client to send requests to the server.

- `ServerSocket` - Waits for and accepts client connections.

- `InetAddress` - Represents an IP address.

### Client-Server Example:

#### Server:

```java

import java.io.*;
import java.net.*;

public class Server {

public static void main(String[] args) throws IOException {

ServerSocket ss = new ServerSocket(5000);

Socket s = ss.accept();

DataInputStream dis = new DataInputStream(s.getInputStream());

String message = dis.readUTF();

System.out.println("Client says: " + message);

ss.close();

```

#### Client:

```java

import java.io.*;

import java.net.*;

public class Client {

public static void main(String[] args) throws IOException {

Socket s = new Socket("localhost", 5000);

DataOutputStream dout = new DataOutputStream(s.getOutputStream());

dout.writeUTF("Hello Server");

dout.flush();

dout.close();

s.close();
}

```

You might also like