CS 406 Lab Manual (1) .OdtJAVAFILE
CS 406 Lab Manual (1) .OdtJAVAFILE
Here are the steps to install J2SDK (Java 2 Software Development Kit) on Windows,
macOS, and Linux:
Windows:
1. Go to the Oracle Java download page and click on the "Java SE" button.
2. Select the "Java SE Development Kit" option and click on the "Download" but-
ton.
6. Choose the components to install, such as the JDK, JRE, and Demos.
8. Wait for the installation to complete, and then click "Finish" to close the wiz-
ard.
4. Under "System Variables", scroll down and find the "Path" variable, then click
"Edit".
5. Click "New" and add the path to the JDK bin directory (e.g., C:\Program
Files\Java\jdk-15.0.2\bin).
6. Click "OK" to close all the windows.
macOS/Linux:
1. Open Terminal and add the following lines to your shell configuration file
(e.g., ~/.bashrc or ~/.zshrc)
// Fields (attributes)
private String color;
private String model;
//Constructor
public Car(String color, String model) {
this.color=color;
this.model= model;
}
//Method
public void displayInfo() {
myCar.displayInfo();
// Program - 04
public class TypeCasting {
// Program -05
public class Exception_andling_Example {
try {
}
}
//program - 06
//Vehicle attribute
protected String brand="Ford";
//Vehicle method
public void honk() {
System.out.println("Tuut, tuut!");
}
}
// Car attribute
private String modelName="Mustang";
}
}
}
}
class AccessSpecifierDemo {
System.out.println(demo.publicVar);
//Systemout.println(demma,privateVar); //Error: Cannot access
// Systemout.println(demaprotectedVar); //Error: Cannot access outside
the class without inheritance
}
}
class Car {
private String model;
private int year;
//Constructor
public Car (String model, int year) {
this.model =model;
this.year=year;
}
// Program - 10
interface Animal {
myDog.sound();
myCat.sound();
}
}
// program - 11
package com.example.project;
public class program11 {
import java.awt.*;
import java.awt.event.*;
// program - 14
package com.example.project;
// program - 15
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
// Establish Connection
Connection conn = DriverManager.getConnection(url, user,
password);
// Create a statement
Statement stmt = conn.createStatement();
// Execute a query
ResultSet rs = stmt.executeQuery("SELECT * FROM yourTable");
// Clean up environment
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Note: Applets are deprecated as of Java 9 and removed in later versions, and modern browsers no
longer support Java applets due to security concerns. However, here's how it
would have been written for historical understanding.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</applet>
</body>
</html>
OUTPUT:-
// program 17
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
// program -18
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</applet>
</body>
</html>
OUTPUT:-
// HelloServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Override
resp.setContentType("text/html");
resp.getWriter().println("<html><body>");
resp.getWriter().println("<h1>Hello, Servlet!</h1>");
resp.getWriter().println("</body></html>");