Java Programming and Dynamic Webpage Design
UNIT-I: Java Programming
Data types, control structures, arrays, strings, and vector; classes (inheritance, package, exception handling); multithreaded programming.
UNIT-II: Java Applets and AWT Controls
Java applets, AWT controls (Button, Labels, Combo box, List, and other Listeners, menu bar), layout manager, string handling (only main functions).
UNIT-III: Networking and JDBC
Networking (datagram socket and TCP/IP-based server socket), event handling. JDBC: Introduction, Drivers, Establishing Connection, Connection Pooling.
UNIT-IV: HTML
Use of commenting, headers, text styling, images, formatting text with <FONT>, special characters, horizontal rules, line breaks, table, forms, image maps, <META> tags, <FRAMESET> tags, file formats including image formats.
UNIT-V: Java Servlets
Introduction, HTTP Servlet Basics, The Servlet Lifecycle, Retrieving Information, Sending HTML Information, Session Tracking, Database Connectivity.
UNIT-VI: Java Server Pages
Introducing Java Server Pages, JSP Overview, Setting Up the JSP Environment, Generating Dynamic Content, Using Custom Tag Libraries and the JSP Standard Tag Library, Processing Input and Output.

UNIT-I: Java Programming

1. Data Types

Java supports various data types to handle different kinds of data. These are categorized into primitive and non-primitive types.

Example:
int age = 25;
double price = 99.99;
char grade = 'A';
        

2. Control Structures

Control structures determine the flow of program execution. Java offers conditional and looping constructs:

Example:
if(score > 50) {
    System.out.println("Passed");
}
        

3. Arrays, Strings, and Vectors

Arrays store multiple values of the same type.

Strings are immutable sequences of characters.

Vectors are dynamic arrays in Java.

Example:
int[] marks = {90, 85, 78};
String name = "Java";
Vector v = new Vector<>();
v.add(10);
        

4. Classes and Inheritance

Classes are blueprints for objects. Inheritance allows a class to inherit properties from another class using extends.

Example:
class Animal {
    void sound() { System.out.println("Sound"); }
}
class Dog extends Animal {
    void bark() { System.out.println("Bark"); }
}
        

5. Packages

Packages group related classes. Java provides built-in packages like java.util, and we can also create user-defined packages.

Example:
package mypack;
public class MyClass { ... }
        

6. Exception Handling

Exception Handling manages runtime errors using try-catch blocks to prevent program crashes.

Example:
try {
    int a = 5 / 0;
} catch (ArithmeticException e) {
    System.out.println("Cannot divide by zero");
}
        

7. Multithreaded Programming

Java allows multithreading, enabling multiple threads to run concurrently using the Thread class or Runnable interface.

Example:
class MyThread extends Thread {
    public void run() {
        System.out.println("Thread running");
    }
}
MyThread t = new MyThread();
t.start();
        

UNIT-II: Applets, AWT Controls & String Handling

1. Java Applets

Applets are small Java programs that run in a web browser. They extend the Applet class and override methods like init(), start(), stop(), and paint().

Example:
public class MyApplet extends Applet {
    public void paint(Graphics g) {
        g.drawString("Hello Applet", 20, 20);
    }
}
        

2. AWT Controls

AWT (Abstract Window Toolkit) provides GUI components such as:

Example:
Button b = new Button("Click Me");
Label l = new Label("Welcome");
Choice cb = new Choice();
cb.add("Option 1");
        

3. Event Listeners

Listeners are interfaces used to handle user interactions:

Example:
b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        System.out.println("Clicked");
    }
});
        

4. Layout Managers

Layout Managers control the positioning of components. Common types:

Example:
setLayout(new FlowLayout());
add(new Button("OK"));
        

5. String Handling (Main Functions)

String handling in Java includes built-in methods for processing text:

Example:
String s = "Java";
System.out.println(s.length());
System.out.println(s.charAt(1));
System.out.println(s.substring(1,3));
        

UNIT-III: Networking and JDBC

1. Networking in Java

Java provides powerful networking capabilities through classes in the java.net package. Two key approaches include:

Example (Datagram):
DatagramSocket ds = new DatagramSocket();

Example (TCP/IP):
ServerSocket server = new ServerSocket(5000);
Socket client = server.accept();
        

2. Event Handling

Event handling allows Java programs to respond to user interactions such as clicks, keypresses, etc. It involves event sources, listeners, and event objects.

Example:
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        System.out.println("Button clicked");
    }
});
        

3. JDBC: Java Database Connectivity

JDBC is an API that allows Java applications to interact with databases. Major components include:

Example:
Connection con = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/mydb", "user", "pass");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
        

UNIT-IV: HTML and Web Elements

1. HTML Basics and Commenting

HTML is used to structure web pages. Comments are ignored by browsers and help explain code.

Example:
<!-- This is a comment -->
        

2. Headers and Text Styling

Headers use <h1> to <h6>. Text styling uses <b>, <i>, and <u>.

Example:
<h1>Main Heading</h1>
<b>Bold</b> <i>Italic</i> <u>Underline</u>
        

3. Images, Line Breaks, and Horizontal Rules

<img> adds images, <br> creates line breaks, <hr> adds horizontal lines.

Example:
<img src="logo.png" alt="Logo">
<hr><br>
        

4. Font Tag and Special Characters

<font> was used to style fonts (deprecated in HTML5). Use entities for special characters.

Example:
<font color="blue">Blue Text</font>
Copyright symbol: &copy;
        

5. Tables and Forms

<table> displays tabular data. <form> collects user input.

Example:
<table border="1">
  <tr><th>Name</th><th>Age</th></tr>
  <tr><td>Alice</td><td>22</td></tr>
</table>

<form>
  Name: <input type="text" name="name">
  <input type="submit">
</form>
        

6. Image Maps

Image maps allow linking specific areas of an image.

Example:
<img src="map.jpg" usemap="#planetmap">
<map name="planetmap">
  <area shape="rect" coords="34,44,270,350" href="sun.html">
</map>
        

7. META and FRAMESET Tags

<meta> provides metadata. <frameset> divides browser window into frames (deprecated in HTML5).

Example:
<meta charset="UTF-8">
<frameset cols="50%,50%">
  <frame src="left.html">
  <frame src="right.html">
</frameset>
        

8. File Formats

Common file types:

UNIT-V: Java Servlets

1. Introduction to Java Servlets

A Java Servlet is a server-side Java program that handles requests and responses in a web application. Servlets run on a web server and provide dynamic web content.

2. HTTP Servlet Basics

HTTP Servlets extend HttpServlet class and handle HTTP requests via doGet() and doPost() methods.

Example:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.getWriter().println("Hello from Servlet");
}
        

3. Servlet Lifecycle

The lifecycle of a servlet consists of:

4. Retrieving Information

Request parameters can be retrieved using request.getParameter("name").

Example:
String user = request.getParameter("username");
        

5. Sending HTML Information

Servlets can send HTML responses by writing to response.getWriter().

Example:
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1>Welcome User</h1>");
        

6. Session Tracking

Session tracking allows storing user data across multiple pages using:

7. Database Connectivity

Servlets can connect to databases using JDBC to perform CRUD operations.

Example:
Connection con = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/mydb", "user", "pass");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
        

UNIT-VI: Java Server Pages (JSP)

1. Introducing Java Server Pages

Java Server Pages (JSP) is a server-side technology that enables the creation of dynamic, platform-independent web content. JSP combines HTML with Java code.

2. JSP Overview

JSP files have a .jsp extension and are translated into servlets at runtime. They allow embedding Java code directly into HTML using special JSP tags like <% %>.

Example:
<% out.println("Welcome to JSP!"); %>
        

3. Setting Up the JSP Environment

To run JSP pages, a servlet container like Apache Tomcat is required. Pages are deployed inside the web application structure under the webapps folder.

4. Generating Dynamic Content

JSP allows inserting Java expressions, scriptlets, and declarations within HTML to generate content based on user inputs or database values.

Example:
<h1>Hello <%= request.getParameter("name") %></h1>
        

5. Using Custom Tag Libraries and JSTL

Custom Tag Libraries allow encapsulating Java code into reusable tags. JSTL (JSP Standard Tag Library) provides common functions like loops and conditionals.

Example:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:if test="${user != null}">
  <p>Welcome, ${user}!</p>
</c:if>
        

6. Processing Input and Output

Input from users is processed using request.getParameter(), and output is sent to the browser via out object or embedded expressions.

Example:
<% String email = request.getParameter("email"); %>
<p>Your email is: <%= email %></p>