Web Tech
Web Tech
Que1. Write a code in java to create three threads having name Red, Blue and
Green.
OUTPUT
[2]
Que2. Write markup to create web page that contains three vertical columns having
background color as Red, Blue and Green respectively.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial- scale=1.0">
<title>Three Vertical Columns</title>
<style>
.column {
width: 30%;
height: 100vh;
/* Adjust height as needed */
float: left;
padding: 10px;
box-sizing: border-box;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
/* Clear floats after columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
</head>
<body>
<div class="row">
<div class="column red">
<h2>Red Column</h2>
<p>Some content here...</p>
</div>
<div class="column blue">
<h2>Blue Column</h2>
<p>Some content here...</p>
</div>
<div class="column green">
[3]
<h2>Green Column</h2>
<p>Some content here...</p>
</div>
</div>
</body>
</html>
OUTPUT
[4]
Que3: What are the key components of the email message represented in the given
XML?
<?xml version="1.0"?>
<!DOCTYPE email [ <!ELEMENT email (sender, recipients, subject, body, date)>
<!ELEMENT sender (#PCDATA)>
<!ELEMENT recipients (recipient+)>
<!ELEMENT recipient (#PCDATA)>
<!ELEMENT subject (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT date (#PCDATA)>]>
<email>
<sender>[email protected]</sender>
<recipients>
<recipient>[email protected]</recipient>
<recipient>[email protected]</recipient>
</recipients>
<subject>Sample Subject</subject>
<body>This is the body of the email.</body>
<date>2024-05-12 10:30:00</date>
</email>
OUTPUT
[5]
Que4: Creates a java program to find out the IP address of your machine.
import java.net.*;
public class IPAddressFinder {
public static void main(String[] args) {
try {
// Get the local host
InetAddress localHost = InetAddress.getLocalHost();
// Print the IP address of the local host
System.out.println("IP Address of the local machine: " +
localHost.getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
OUTPUT
[6]
Que5: Write index.html to input the some details (Name, Age, Message) from
user.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial- scale=1.0">
<title>User Details Form</title>
<style>
label {
display: block;
margin-bottom: 10px;
}
input[type="text"],
textarea {
width: 100%;
padding: 5px;
margin-bottom: 10px;
}
input[type="submit"] {
padding: 8px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<h2>User Details Form</h2>
<form id="userForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="age">Age:</label>
<input type="text" id="age" name="age" required>
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4" required></textarea>
<input type="submit" value="Submit">
</form>
<script>
document.getElementById('userForm').addEventListener('submit', function (event) {
[7]
OUTPUT
[8]
Que6: Create a CSS rule that makes all the text 2 time larger than the base font of
the system. Mention can you integrate CSS on a webpage.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial- scale=1.0">
<title>Large Text Example</title>
<style>
html {
font-size: 200%;
}
</style>
</head>
<body>
<!-- Your content here -->
</body>
</html>
OUTPUT
[9]
interface A {
void methodA();
}
interface B {
void methodB();
}
class MyClass implements A, B {
public void methodA() {
System.out.println("Method A");
}
public void methodB() {
System.out.println("Method B");
}
}
public class Main {
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.methodA();
obj.methodB();
}
}
OUTPUT
[10]
Que8: Create an HTML code to create a web page that contain the user
Registration form with the following details username, user dob, user address, user
gender, user email id, user mobile number.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial- scale=1.0">
<title>User Registration Form</title>
<style>
label {
display: block;
margin-bottom: 10px;
}
input[type="text"],
input[type="date"],
input[type="email"],
input[type="tel"],
select {
width: 100%;
padding: 5px;
margin-bottom: 10px;
}
input[type="radio"] {
margin-right: 5px;
}
input[type="submit"] {
padding: 8px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
[11]
OUTPUT
[13]
[14]
Que9: Design a JavaScript program to display the current day and time in the
following format--
Today is: Monday
Current Time: 11 AM : 50 : 58
function displayCurrentDateTime() {
var days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
var currentDate = new Date();
var currentDay = days[currentDate.getDay()];
var hours = currentDate.getHours();
var period = hours >= 12 ? "PM" : "AM";
hours = hours % 12 || 12; // Convert to 12-hour format
var minutes = currentDate.getMinutes().toString().padStart(2, "0");
var seconds = currentDate.getSeconds().toString().padStart(2, "0");
var currentTime = hours + " " + period + ":" + minutes + ":" + seconds;
console.log("Today is: " + currentDay);
console.log("Current time: " + currentTime);
}
displayCurrentDateTime();
OUTPUT
[15]
File - index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial- scale=1.0">
<title>To-Do List</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>To-Do List</h1>
<input type="text" id="taskInput" placeholder="Enter task...">
<button onclick="addTask()">Add Task</button>
<ul id="taskList"></ul>
</div>
<script src="script.js"></script>
</body>
</html>
File - style.css
body {
font-family: Arial, sans-serif;
list-style: none;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f9f9f9;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #333;
}
input {
width: 70%;
padding: 10px;
margin-bottom: 10px;
border: 2px solid #912929;
[16]
border-radius: 3px;
outline: none;
}
button {
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
ul {
list-style-type: none;
padding: 0;
}
li {
padding: 10px;
margin-bottom: 5px;
background-color: #fff;
border-radius: 3px;
list-style: none;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
File - script.js
function addTask() {
vartaskInput = document.getElementById("taskInput");
vartaskList = document.getElementById("taskList");
if (taskInput.value.trim() !== "") {
var li = document.createElement("li");
li.textContent = taskInput.value;
taskList.appendChild(li);
taskInput.value = "";
} else {
alert("Please enter a task!");
}
}
[17]
OUTPUT
[18]
Que11: Write a Java program using JDBC to connect to MySQL, create a table
named "products" with column id, name, and price, then insert three sample
records. Handle exceptions appropriately.
import java.sql.*;
public class Main {
static final String JDBC_URL = "jdbc:mysql://localhost:3306/mydatabase";
static final String USERNAME = "username";
static final String PASSWORD = "password";
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
try {
connection = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD);
statement = connection.createStatement();
String createTableSQL = "CREATE TABLE IF NOT EXISTS products (" +
"id INT AUTO_INCREMENT PRIMARY KEY," +
"name VARCHAR(255)," +
"price DECIMAL(10, 2)" +
")";
statement.executeUpdate(createTableSQL);
System.out.println("Table 'products' created successfully.");
String insertRecord1 = "INSERT INTO products (name, price) VALUES ('Product 1', 10.99)";
String insertRecord2 = "INSERT INTO products (name, price) VALUES ('Product 2', 20.49)";
String insertRecord3 = "INSERT INTO products (name, price) VALUES ('Product 3', 15.79)";
statement.executeUpdate(insertRecord1);
statement.executeUpdate(insertRecord2);
statement.executeUpdate(insertRecord3);
System.out.println("Sample records inserted successfully.");
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (statement != null)
statement.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
[19]
}
}
}
}
OUTPUT
[20]
Que12: Write a program in java to fetch and print the data from a table .
import java.sql.*;
public class Main {
// JDBC URL, username, and password of MySQL server
static final String JDBC_URL = "jdbc:mysql://localhost:3306/mydatabase";
static final String USERNAME = "username";
static final String PASSWORD = "password";
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
// Establishing connection to the database
connection = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD);
// Creating a statement
statement = connection.createStatement();
// Executing query to fetch data
String query = "SELECT * FROM products";
resultSet = statement.executeQuery(query);
// Printing fetched data
System.out.println("Products:");
System.out.println("ID\tName\tPrice");
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
double price = resultSet.getDouble("price");
System.out.println(id + "\t" + name + "\t" + price);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
// Closing resources
try {
if (resultSet != null)
resultSet.close();
[21]
if (statement != null)
statement.close();
if (connection != null)
connection.close();
} catch (SQLException e) {.
e.printStackTrace();
}
OUTPUT