flexboxDemo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flexbox and Animations Demo</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
width: 80%;
max-width: 1200px;
margin: 20px;
padding: 20px;
background-color: white;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
border-radius: 10px;
}
.box {
flex: 1 1 200px;
margin: 15px;
padding: 20px;
background-color: #4CAF50;
color: white;
text-align: center;
border-radius: 8px;
transition: transform 0.3s ease, background-color 0.3s ease;
animation: fadeIn 0.5s ease forwards;
opacity: 0;
}
@keyframes fadeIn {
to {
opacity: 1;
}
}
.box:hover {
transform: scale(1.05);
background-color: #45a049;
}
h1 {
margin-bottom: 20px;
}
</style>
</head>
<body>
<h1>Flexbox and Animations Demo</h1>
<div class="container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
<div class="box">Box 4</div>
<div class="box">Box 5</div>
<div class="box">Box 6</div>
</div>
</body>
</html>
popUpDemo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Pop-Up Boxes</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 15px;
font-size: 16px;
margin: 10px;
}
</style>
</head>
<body>
<h1>JavaScript Pop-Up Box Demonstration</h1>
<button onclick="showAlert()">Show Alert</button>
<button onclick="showConfirm()">Show Confirm</button>
<button onclick="showPrompt()">Show Prompt</button>
<script>
function showAlert() {
alert("This is an alert box!");
}
function showConfirm() {
const result = confirm("Do you want to proceed?");
if (result) {
alert("You clicked OK!");
} else {
alert("You clicked Cancel!");
}
}
function showPrompt() {
const name = prompt("Please enter your name:");
if (name) {
alert("Hello, " + name + "!");
} else {
alert("No name entered.");
}
}
</script>
</body>
</html>
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Web Design Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
color: #333;
}
header {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 1em;
text-align: center;
}
main {
display: flex;
flex-direction: row;
flex-wrap: wrap;
max-width: 1200px;
padding: 1em;
}
.box {
flex: 1 1 30%;
background-color: #f1f1f1;
margin: 10px;
padding: 20px;
text-align: center;
}
footer {
width: 100%;
background-color: #333;
color: white;
text-align: center;
padding: 1em;
position: fixed;
bottom: 0;
}
@media (max-width: 768px) {
.box {
flex: 1 1 45%;
}
header, footer {
padding: 0.8em;
}
}
@media (max-width: 480px) {
main {
flex-direction: column;
align-items: center;
}
.box {
flex: 1 1 100%;
}
header, footer {
font-size: 1.2em;
}
}
</style>
</head>
<body>
<header>
<h1>Responsive Web Design</h1>
<p>This is a simple responsive layout using media queries</p>
</header>
<main>
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
<div class="box">Box 4</div>
<div class="box">Box 5</div>
<div class="box">Box 6</div>
</main>
<footer>
<p>© 2024 Responsive Web Design Demo</p>
</footer>
</body>
</html>
asyncDemo.js
function fetchDataCallback(callback) {
setTimeout(() => {
callback("Data fetched using callback");
}, 2000);
}
function displayDataCallback() {
fetchDataCallback((data) => {
console.log(data);
});
}
function fetchDataPromise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Data fetched using promise");
}, 2000);
});
}
function displayDataPromise() {
fetchDataPromise()
.then((data) => console.log(data))
.catch((error) => console.error("Error:", error));
}
async function fetchDataAsync() {
return new Promise((resolve) => {
setTimeout(() => {
resolve("Data fetched using async/await");
}, 2000);
});
}
async function displayDataAsync() {
try {
const data = await fetchDataAsync();
console.log(data);
} catch (error) {
console.error("Error:", error);
}
}
console.log("Starting Callback example...");
displayDataCallback();
setTimeout(() => {
console.log("\nStarting Promise example...");
displayDataPromise();
}, 3000);
setTimeout(() => {
console.log("\nStarting Async/Await example...");
displayDataAsync();
}, 6000);
books.xml
<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="books.xsd">
<book>
<title>Introduction to XML</title>
<author>John Doe</author>
<isbn>978-0-123456-47-2</isbn>
<publisher>Example Press</publisher>
<edition>3rd</edition>
<price>39.99</price>
</book>
<book>
<title>Advanced XML Concepts</title>
<author>Jane Smith</author>
<isbn>978-0-765432-10-5</isbn>
<publisher>Tech Books Publishing</publisher>
<edition>1st</edition>
<price>45.00</price>
</book>
</bookstore>
books.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="isbn" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
<xs:element name="edition" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
books.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bookstore SYSTEM "bookstore.dtd">
<bookstore>
<book>
<title>Introduction to XML</title>
<author>John Doe</author>
<isbn>978-0-123456-47-2</isbn>
<publisher>Example Press</publisher>
<edition>3rd</edition>
<price>39.99</price>
</book>
<book>
<title>Advanced XML Concepts</title>
<author>Jane Smith</author>
<isbn>978-0-765432-10-5</isbn>
<publisher>Tech Books Publishing</publisher>
<edition>1st</edition>
<price>45.00</price>
</book>
</bookstore>
bookstore.dtd
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, isbn, publisher, edition, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
books.xml
<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="books.xsd">
<book>
<title>Introduction to XML</title>
<author>John Doe</author>
<isbn>978-0-123456-47-2</isbn>
<publisher>Example Press</publisher>
<edition>3rd</edition>
<price>39.99</price>
</book>
<book>
<title>Advanced XML Concepts</title>
<author>Jane Smith</author>
<isbn>978-0-765432-10-5</isbn>
<publisher>Tech Books Publishing</publisher>
<edition>1st</edition>
<price>45.00</price>
</book>
</bookstore>
books.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="isbn" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
<xs:element name="edition" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
AND(
OR(
ISBLANK(ANY(SELECT(Filters Slice[Staff], USEREMAIL()=[Email]))),
ANY(SELECT(Filters Slice[Staff], USEREMAIL()=[Email])) = [Staff]
),
OR(
ISBLANK(ANY(SELECT(Filters Slice[From...], USEREMAIL()=[Email]))),
[Date] >= ANY(SELECT(Filters Slice[From...], USEREMAIL()=[Email]))
),
OR(
ISBLANK(ANY(SELECT(Filters Slice[To...], USEREMAIL()=[Email]))),
[Date] <= ANY(SELECT(Filters Slice[To...], USEREMAIL()=[Email]))
)
)
* GOAL: Within a macro, you want to create a new variable name.
* It could then be used as a data set name, or a variable name to be assigned, etc.;
%macro newname(dset=,varname=);
* You have to make the new name before you use it in
* another data statement;
data _NULL_;
L1=CATS("&varname","_Plus1");
CALL SYMPUT('namenew',L1);
;
* Now you can use the variable name created by SYMPUT;
DATA REVISED;SET &DSET;
&namenew=&varname+1;
run;
%mend;
Data try;
input ABCD @@;
datalines;
1 2 3 4
;run;
%newname(dset=try,varname=ABCD);
proc print data=revised;run;
proc sql;
select jobcode,avg(salary) as Avg
from sasuser.payrollmaster
group by jobcode
having avg(salary)>40000
order by jobcode;
ParserError: Expected '' but got 'Number' --> myc:1:10: | 1 | GNU nano 7.2 payabledistributor.sol// SPDX-License-Identifier: MIT | ^^^
#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
>>> import keyword >>> print(keyword.kwlist) ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HAHU CRYPTO</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
/* General Styling */
body {
font-family: 'Arial', sans-serif;
background-color: white;
color: black;
margin: 0;
padding: 20px;
transition: background-color 0.3s, color 0.3s;
user-select: none;
}
body.high-mode {
background-color: black;
color: white;
}
.container {
max-width: 800px;
margin: auto;
padding: 20px;
text-align: center;
}
h1 {
font-size: 2.5em;
margin-bottom: 20px;
}
/* Hamburger Menu Styling */
.hamburger {
font-size: 2em;
cursor: pointer;
position: absolute;
top: 20px;
left: 20px;
}
.menu {
position: fixed;
top: 0;
left: 0;
width: 300px;
height: 100%;
background-color: #333;
color: white;
transform: translateX(-100%);
transition: transform 0.3s;
z-index: 1000;
padding: 20px;
}
.menu.active {
transform: translateX(0);
}
.menu .close-btn {
font-size: 1.5em;
cursor: pointer;
position: absolute;
top: 20px;
right: 20px;
}
.menu ul {
list-style: none;
padding: 0;
}
.menu ul li {
display: flex;
align-items: center;
margin-bottom: 20px;
cursor: pointer;
}
.menu ul li img {
width: 40px;
height: 40px;
margin-right: 10px;
border-radius: 50%;
flex-shrink: 0;
}
.menu ul li a {
color: white;
text-decoration: none;
font-size: 1.2em;
margin: 0;
display: inline-flex;
align-items: center;
}
/* Search Input */
input[type="text"] {
width: 80%;
padding: 15px;
border: 2px solid #007BFF;
border-radius: 5px;
font-size: 1.2em;
margin: 20px auto;
display: block;
transition: border-color 0.3s ease;
background-color: white;
color: #333;
}
body.high-mode input[type="text"] {
background-color: #444;
color: white;
border: 2px solid #555;
}
/* Task List */
.task {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
border-bottom: 1px solid #e1e9ef;
transition: background 0.3s;
}
.task:last-child {
border-bottom: none;
}
.task:hover {
background: #f9f9f9;
}
body.high-mode .task:hover {
background: #333;
}
/* Button Styling */
button {
padding: 10px 15px;
border: none;
background-color: #007BFF;
color: white;
border-radius: 5px;
font-size: 1em;
cursor: pointer;
transition: background 0.3s, transform 0.2s;
}
button:hover {
background-color: #0056b3;
transform: scale(1.05);
}
/* Footer */
footer {
text-align: center;
margin-top: 20px;
font-size: 0.9em;
color: #666;
}
body.high-mode footer {
color: #ccc;
}
/* Toast Notification */
.toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #007BFF;
color: white;
padding: 10px 20px;
border-radius: 5px;
z-index: 1000;
animation: slideIn 0.5s ease, fadeOut 0.5s 2.5s forwards;
}
@keyframes slideIn {
from {
bottom: -50px;
opacity: 0;
}
to {
bottom: 20px;
opacity: 1;
}
}
@keyframes fadeOut {
to {
opacity: 0;
}
}
/* Mood Toggle */
.mood-toggle {
cursor: pointer;
font-size: 2em;
position: absolute;
top: 20px;
right: 20px;
transition: transform 0.3s;
}
.mood-toggle:hover {
transform: scale(1.1);
}
</style>
</head>
<body>
<!-- Hamburger Icon -->
<div class="hamburger" id="hamburger">☰</div>
<!-- Hamburger Menu -->
<div class="menu" id="menu">
<span class="close-btn" id="closeMenu">×</span>
<ul>
<li><a href="https://t.me/Hahucryptoet" target="_blank"><img src="https://i.ibb.co/Nyjtq7B/IMG-20241029-004716-176.jpg" alt="Hahu Crypto"> Hahu Crypto</a></li>
<li><a href="https://t.me/hahu_Support" target="_blank"><img src="https://i.ibb.co/Nyjtq7B/IMG-20241029-004716-176.jpg" alt="Hahu Support"> Hahu Support</a></li>
<li><a href="https://t.me/leap10" target="_blank"><img src="https://i.ibb.co/6ByXcTT/IMG-20241028-235223-445.jpg" alt="Dev"> Dev </></a></li>
</ul>
</div>
<!-- Main Content -->
<div class="container">
<div style="display: flex; justify-content: center; gap: 20px; margin-bottom: 20px;">
<div style="width: 80px; height: 80px; border-radius: 50%; overflow: hidden; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);">
<img src="https://i.ibb.co/Nyjtq7B/IMG-20241029-004716-176.jpg" alt="Image 1" style="width: 100%; height: 100%; object-fit: cover;">
</div>
<div style="width: 80px; height: 80px; border-radius: 50%; overflow: hidden; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRnyTH33Ds8Z_vpe2LOZEdwXVCYtYl86sVgeA&s" alt="Image 2" style="width: 100%; height: 100%; object-fit: cover;">
</div>
</div>
<h1><a href="https://t.me/tapswap_bot?startapp" style="text-decoration: none;">Tapswap</a> Cinema Codes</h1>
<i class="fas fa-sun mood-toggle" id="moodToggle" title="Switch to High Mode"></i>
<input type="text" id="search" placeholder="Search for tasks..." onkeyup="searchTasks()">
<div id="task-list"></div>
<footer>
<p>Powered by <a href="https://t.me/Hahucryptoet" style="text-decoration: none;">Hahu Crypto</a> Team</p>
</footer>
</div>
<script>
// Sample Tasks Data
const tasks = [
{ task: 'Crypto scandals and triumps', code: '739002' },
{ task: 'Tapswap news: highlights from the AMA session on TON\'s space', code: '5' },
{ task: 'Why did Tapswap change the blockchain?', code: '548719' },
{ task: 'Tapswap Education: Bitcoin and altcoin', code: '030072' },
{ task: 'New in the crypto world', code: '739551' },
{ task: '5 main crypto terms in 5mins', code: '2614907' },
{ task: 'Tapswap Education: The most famous cryptocurrency', code: 'D57U94' },
{ task: 'How you can make money when crypto falling?', code: 'genesis' },
{ task: 'Drops and rises in the crypto world', code: '27F53K9' },
{ task: '5 easy ways to make money on crypto', code: 'encryption' },
{ task: 'Tapswap Education: Memes and cryptocurrencies', code: '4D80N74' },
{ task: 'How to get started in crypto without investments?', code: 'TRIBALISM' },
{ task: '8 Warren buffet rules in 8 mins', code: 'ABENOMICS' },
{ task: 'Tapswap Education: Fake news and real news', code: 'G5D73H20' },
{ task: 'Cryptocurrency worldwide news!', code: '3PM71AK03X' },
{ task: 'How to buy crypto in 2024?', code: 'delisting' },
{ task: '10 crypto terms in 5mins', code: 'collateral' },
{ task: 'Tapswap: curious facts', code: 'L6SE704V81' },
{ task: 'How cryptocurrency and money actually works', code: 'fibonacci' },
{ task: 'Tapswap: curious facts. Top 7 most expensive NFT', code: 'F35K90V3' },
{ task: 'What is bitcoin? The simplest explanation', code: 'liveness' },
{ task: 'Hot crypto news: Ethereum ETFs', code: '5J6OL847G7' },
{ task: 'The most dangerous cryptoscams you should know about!', code: 'RANSOMWARE' },
{ task: 'Tapswap education: Can u earn 1 bitcoin per day? How bitcoin mining works.', code: '4K7U6E10G7' },
{ task: 'What are NFTs and why they cost millions?', code: 'tardigrade' },
{ task: 'Lunch Dates, Token Conversion, Mining, and Future Features!', code: 'F9L34V5A' },
{ task: 'How Elon Musk impacts crypto', code: 'unbanked' },
{ task: 'Financial face-off: Bitcoin custody vs Bank accounts', code: 'D5784VHPC377' },
{ task: '7 AI tools that will make you rich', code: 'infinite' },
{ task: 'The dark side of crypto: Top 8 cyber attacks and how to prevent them', code: '5SP670KR66' },
{ task: 'Crypto is not real money! Will cryptocurrency REPLACE fiat money?', code: 'parachain' },
{ task: 'Unlocking the future: The power of a trio of blockchain, IoT, and AI', code: 'D772WQ9Z5' },
{ task: 'How to make $1 Million as a TEENAGER (30 Money Tips)', code: 'instamine' },
{ task: 'USDT vs USDC', code: '7N008TQ31V' },
{ task: 'Without this knowledge you WILL NOT MAKE MONEY in crypto!', code: 'WebSocket' },
{ task: 'Crypto revolution: Pay with crypto using debit cards', code: '0TJN63R97A' },
{ task: 'The Best Crypto Portfolio for 2024! (LAST CHANCE BEFORE BULL RUN)', code: 'unstoppable' },
{ task: 'Top15 crypto news: what is the hottest? Bitcoin, USDT', code: '3KKLF7JO5' },
{ task: 'Make 10x On Crypto', code: 'Onchain' },
{ task: 'Bitcoin integration to the real life: new digital gold', code: '547JL6AM7R' },
{ task: 'Earn on Airdrops', code: 'tendermint' },
{ task: 'Delicious crypto news: ethereum ETF, Tether on TON, Dogecoin\'s Real world impact', code: 'Q7P9N3VD' },
{ task: '10 Passive Income Ideas - How I Earn $1,271 A Day!', code: 'renewable' },
{ task: 'Top 10 bitcoin whales: The biggest bitcoin holders revealed!', code: '5G36SQ' },
{ task: 'Ethereum will be worth $20,000! What is Ethereum?', code: 'emission' },
{ task: 'Top 10 bitcoin whales: The biggest bitcoin holders revealed! Part 2', code: '27MZ' },
{ task: 'Secure your crypto: The role of public and private keys', code: '5WH71' },
{ task: 'How Blockchain ACTUALLY Work | A Simple Explanation For Beginners (12mins)', code: 'marlowe' },
{ task: 'Secure your crypto: The role of public and private keys | Part 2 (3mins)', code: '0P6E' },
{ task: 'рџ¤– If I Wanted to Become a Millionaire In 2024 - I\'d Do This (10mins)', code: 'function' },
{ task: 'Secure your crypto: CEX vs self custodial wallets (5mins)', code: '1T89G' },
{ task: 'How I Stay Productive 99% of Every Day? (8mins)', code: 'quantum' },
{ task: 'Secure your crypto: CEX vs self custodial wallets | Part 2 (5mins)', code: 'L3AE7' },
{ task: '10 Websites Where Rich People Give Away FREE Money (10mins)', code: 'watchlist' },
{ task: 'Bitcoin halving: what future price are crypto experts predicting? (4mins)', code: '7JSZ7' },
{ task: 'If I Started From Scratch Again - I’d Do This (8mins)', code: 'farming' },
{ task: 'Where To Start in Crypto', code: 'electrum' },
{ task: 'What CRYPTO To Buy With $500', code: 'hashgraph' },
{ task: 'Bitcoin Halving Part 2', code: 'YK797' },
{ task: 'How To Earn $2000+ Watching Youtube Videos (11mins)', code: 'immutable' },
{ task: 'crypto news! Bitcoin\'s rollercoaster and vitalik buterin\'s film. Will btc hit $100k next? (4mins)', code: '1MH89S' },
{ task: 'How To Make $500 A Day With Cryptocurrency Arbitrage (10 mins)', code: 'backlog' },
{ task: 'How To Make $5,000 per Month With Crypto Bots! Guide For Beginners (8 mins)', code: 'royalties' },
{ task: 'TON Ecosystem Alert: Avoiding security risks on telegram (4mins)', code: '8NL6FW9' },
{ task: 'How To Farm 1 MILLION Coins Per A Click In TapSwap (10mins)', code: 'timelock' },
{ task: 'Crypto Bots are SCAMMING you! EARNINGS From 0$ (8mins)', code: 'inflation' },
{ task: 'Block chain secrets: Can data availability save us? (3mins)', code: '2V3L5' },
{ task: 'рџ¤– You Will LOSE Your Money If You Make These Mistakes (8mins)', code: 'rebalancing' },
{ task: 'Crypto Bots are SCAMMING you!', code: 'inflation' },
{ task: 'Get Paid +750$ Every 20 minutes Online', code: 'scaling' },
{ task: 'TapSwap Internal News', code: '1T75S7' },
{ task: '10 Websites That Will Pay You', code: 'keylogger' },
{ task: 'Why are people going crazy for NFTs? What\'s making digital tokens So popular (3mins)', code: '2NV4Z' },
{ task: 'How To Earn $2,000 Listening to Music for FREE (2024) (8mins)', code: 'raiden' },
{ task: 'Blockchain Secrets: Can data availability save us? | Part 2', code: '9SX634' },
{ task: 'Why are people going crazy for NFTs? What\'s making digital tokens So popular | Part 2 (3mins)', code: 'J9RO8' },
{ task: 'I Lost $10,000 - Don\'t Make These Mistakes (8mins)', code: 'nominators' },
{ task: 'I Made a Million Dollar Meme Coin In 10 Minutes (9mins)', code: 'payout' },
{ task: 'How To Create Your OWN COIN', code: 'payout' },
{ task: 'Bitcoin Update: Mt. Gox Payout', code: 'PD9S6HN81M' },
{ task: 'How To Make Money On Stock', code: 'fakeout' },
{ task: 'Hot News!', code: '5FR63U' },
{ task: 'Make $30 Per Word With Typing Jobs From Home (10mins)', code: 'ledger' },
{ task: 'Mastering Bitcoin', code: 'No codes' },
{ task: 'Cool News!', code: '5L32DN' },
{ task: '10 Legit APPs That Will Pay You Daily Within 24 HOURS (10mins)', code: 'darknodes' },
{ task: 'Tapswap Education. Part 1', code: 'J386XS' },
{ task: 'How To Make $12,000/month', code: 'lambo' },
{ task: 'Tapswap Education. Part 2', code: '5UY4W1' },
{ task: '7 laziest way to make money', code: 'replay' },
{ task: 'Make $5000+ with Pinterest', code: 'invest' },
{ task: 'Earn $100+ Per Day In Telegram', code: 'curve' },
{ task: 'How to spot 100Г— Altcoin', code: 'lachesis' },
{ task: 'Start Your Business Under 10', code: 'liquid' },
{ task: '10 Habits Of Millionaires (10mins)', code: 'mainnet' },
{ task: 'Make $755 While You Sleep (10mins)', code: 'quorum' },
{ task: '10 Best Dropshipping Niches (15mins)', code: 'perpetual' },
{ task: 'Sell Your Photos For $5 Per On (10mins)', code: 'scam' },
{ task: '20 Best YouTube Niche (14mins)', code: 'flashbots' },
{ task: '5 REAL Apps That Pay You To Walk', code: 'capital' },
{ task: '10 Best Budgeting Apps (8mins)', code: 'node' },
{ task: '15 Powerful Secrets To Get Rich', code: 'long' },
{ task: 'Avoid This To Become Rich', code: 'libp2p' },
{ task: 'Earn $300/Daily From Binance (11mins)', code: 'jager' },
{ task: '7 Best Cash Back Apps (10mins)', code: 'gwei' },
{ task: 'Make Money Playing Video Games (11mins)', code: 'monopoly' },
{ task: '$50 Per Survey + Instant Payment (9mins)', code: 'dumping' },
{ task: 'High Paying Micro Task Websites (10mins)', code: 'custody' },
{ task: 'What is Doxing? Part 2 (3mins)', code: 'No code required' },
{ task: 'Make Your First $100,000 (10mins)', code: 'moon' },
{ task: 'Stable Crypto News (3mins)', code: 'No code required' },
{ task: 'Travel and Earn Money', code: 'bag' },
{ task: 'Crypto Scams Exposed: Beware of Fake Tokens | Part 1 (3mins)', code: 'No Code' },
{ task: 'Passive Income (10mins)', code: 'network' },
{ task: 'Crypto Scams Exposed | Part 2 (3mins)', code: 'No code' },
{ task: 'Earn $5,000 with Chat GPT (11mins)', code: 'newb' },
{ task: 'Don\'t Get Hacked (3mins)', code: 'No code' },
{ task: 'Earn $500 By Reviewing Products! (10mins)', code: 'fakeout' },
{ task: 'Don\'t Get Hacked | Part 2 (3mins)', code: 'No code' },
{ task: 'Make REAL MONEY Before 2025 (10mins)', code: 'money' },
{ task: 'Tappy Town Guide: Gems, Blocks and Builders | Part 1 (3mins)', code: 'No code' },
{ task: '15 Time Management Tips (11mins)', code: 'taint' },
{ task: 'Reselling In 2024 (Easy $10,000) (9 mins)', code: 'pair' },
{ task: 'Bitcoin\'s Ride: Understanding Price Fluctuations | Crypto Volatility Explained. (4 mins)', code: 'No code' },
{ task: 'Tapswap Update! (4 mins)', code: 'airnode' },
{ task: 'TOP 10 And More (9mins)', code: 'No code' },
{ task: 'Make $10,000 in TikTok (11 mins)', code: 'payee' },
{ task: 'Crypto Pitfalls Part 1 (3mins)', code: 'No code' },
{ task: 'Top Free Finance Courses (9 mins)', code: 'protocol' },
{ task: 'Crypto Pitfalls Part 2 (3mins)', code: 'No code' },
{ task: 'Top Future Professions (10 mins)', code: 'scamcoin' },
{ task: 'Crypto Pitfalls Part 3 (3mins)', code: 'No code' },
{ task: 'Make Money On Social Media (11 mins)', code: 'dyor' },
{ task: 'Web3 Explained (4 mins)', code: 'No code' },
{ task: 'Phone-Based Side Hustles (10 mins)', code: 'liquidity' },
{ task: 'Web3 Explained | Part 2 (3 mins)', code: 'No code' },
{ task: 'Earning with Affiliate Programs (10 mins)', code: 'peg' },
{ task: 'Web3 Explained | Part 3 (3 mins)', code: 'No code' },
{ task: 'Monetize Your Blog! (11 mins)', code: 'phishing' },
{ task: 'Crypto News! (2mins)', code: 'No code' },
{ task: 'Make Money Online! (10 mins)', code: 'platform' },
{ task: 'Crypto News! | Part 2 (2mins)', code: 'No code' },
{ task: 'How To Earn Free Bitcoin! (11mins)', code: 'address' },
{ task: 'Crypto News! | Part 3 (2mins)', code: 'No code' },
{ task: 'Start Earning With Airbnb (9 mins)', code: 'hacking' },
{ task: 'Crypto News! | Part 4 (2mins)', code: 'No code' },
{ task: 'Monetize Your Hobby (8 mins)', code: 'geth' },
{ task: 'Simple earning on binance', code: 'rekt' },
{ task: 'Open Best Online Businesses', code: 'roadmap' },
{ task: 'Make $5000 In A Month On X', code: 'abstract' },
{ task: 'Get Free Gifts Using Loyalty Programs', code: 'rebase' },
{ task: 'Make money from Instagram', code: 'account' },
{ task: 'I asked companies for free stuff', code: 'affiliate' },
{ task: 'Make money with your car!', code: 'oversold' },
{ task: 'Millionaire-Making Crypto Exchanges!', code: 'honeypot' },
{ task: 'Make $5000+ with copy Trading', code: 'gas' },
{ task: 'Stay out of poverty!', code: 'validator' },
{ task: 'Amazon success!', code: 'vaporware' },
{ task: 'Start a profitable youtube channel!', code: 'virus' },
{ task: 'Facebook ads tutorial', code: 'volatility' },
{ task: 'Famous crypto millionaires', code: 'volume' },
{ task: 'Selling Your Art Online', code: 'wei' },
{ task: 'Get paid to playtest', code: 'wallet' },
{ task: 'The Best Side Hustles Ideas!', code: 'regens' },
{ task: 'Be Productive Working From Home', code: 'whale' },
{ task: 'Make $1000 Per Day', code: 'whitelist' },
{ task: 'Make Big Money In Small Towns', code: 'whitepaper' },
{ task: 'Make money as a student', code: 'zkapps' },
{ task: 'Work From Home', code: 'zkoracle' },
{ task: 'Secrets To Secure Business Funding', code: 'zksharding' },
{ task: 'Anyone can get rich!', code: 'honeyminer' },
{ task: 'Achieve everything you want', code: 'accrue' },
{ task: 'Watch to get rich!', code: 'regulated' },
{ task: 'Make Money Anywhere', code: 'restaking' },
{ task: 'Save your first $10,000', code: 'retargeting' },
{ task: 'Online business from $0', code: 'whitepaper' },
{ task: 'Amazon Success 2', code: 'rust' },
{ task: 'Make Money On Weekends', code: 'scrypt' },
{ task: 'Telegram wallet 2024', code: 'security' },
{ task: '$5,000 Month Flipping Items On eBay', code: 'settlement' },
{ task: 'Make $3,000 Per Month By Selling', code: 'shard' },
{ task: 'They Changed Our Lives', code: 'tangle' },
{ task: 'How To Retire Early', code: 'taproot' },
{ task: '10 Business Ideas For Digital Nomads', code: 'shilling' },
{ task: 'Earn $250 Per Hour On Freelance', code: 'shitcoin' },
{ task: '16,000 per Month with an online agency', code: 'short' },
{ task: 'Earn $5500 Per Month On Text Writing', code: 'sidechain' },
{ task: 'Earn $8,000 Per Month with online course', code: 'signal' },
{ task: 'Top 10 side Hustles For Busy Professionals', code: 'slashing' },
{ task: 'Make $1,000 Per A Day By Flip', code: 'slippage' },
{ task: 'Buy REAL ESTATE With Only $100', code: 'snapshot' },
{ task: 'How To Start Investing In Real Estate With No Money', code: 'spac' },
{ task: 'Start Your First Business', code: 'gems' },
{ task: 'Start a successful online business', code: 'roi' },
{ task: 'Millionaire on a low salary', code: 'skynet' },
{ task: '5 Remote Jobs For Stay At Home', code: 'snapshot' },
{ task: 'Earnings on launchpad', code: 'unconfirmed' },
{ task: '7 High Paying Freelance Skills', code: 'accountability' },
{ task: 'Make Money With Your Voice', code: 'acquisition' },
{ task: '10 Best Freelancing Platform', code: 'spyware' },
{ task: '$100,000 By IT Professions With No code', code: 'stablecoin' },
{ task: 'Invest as a teenager', code: 'staking' },
{ task: '10 Most Profitable Niches', code: 'stroop' },
{ task: '4 Business Ideas To Start with $0', code: 'subnet' },
{ task: 'Make People BUY FROM YOU', code: 'substrate' },
{ task: 'Earn $550 Per A Day By Selling ebooks', code: 'supercomputer' },
{ task: '10 AI Tools That Will Make You Rich', code: 'supercycle' },
{ task: 'Websites That will pay you', code: 'swarm' },
{ task: 'Lazy Ways to Make Money Online (2025)', code: 'capitulation' },
{ task: 'Make Money With Graphic Design', code: 'cash' },
{ task: 'YouTube Gaming Channel', code: 'cashtoken' },
{ task: 'Earn with your smartphone', code: 'censorship' },
{ task: 'Make Money by Flipping Furniture', code: 'piece' },
{ task: 'Make money with your hobby', code: 'graduate' },
{ task: 'Earn $10,000 per Month on Twitch', code: 'helpful' },
{ task: 'TikTok in 2024', code: 'morning' },
{ task: 'Earn $5000 With A Drone', code: 'tuesday' },
{ task: 'Digital Product Ideas', code: 'tomorrow' },
{ task: 'Ways to Make Money on Fiverr', code: 'kinder' },
{ task: 'Selling Your Music Online', code: 'neons' },
{ task: 'Secret Crypto Projects', code: 'proof' },
{ task: 'Traffic Arbitrage', code: 'hashtag' },
{ task: 'Lazy Ways to Make Money', code: 'routine' },
{ task: 'Make $100,000 with SOCIAL MEDIA', code: 'hello' },
{ task: 'Trading FOREX', code: 'happy' },
{ task: '100,000 Followers In 1 Month', code: 'amazing' },
{ task: 'YouTube Shorts', code: 'heshday' },
{ task: '$1000/Day With ChatGPT', code: 'uzumy' },
{ task: 'Make Money At Any Age', code: 'ledhos' },
{ task: 'Selling CANVA Templates', code: 'miner' },
{ task: 'Instagram Reels', code: 'laugh' },
{ task: 'Selling Your Old Clothes', code: 'tested' },
{ task: 'Industries That Make Billionaires', code: 'hesoyam' },
{ task: 'Make Money by Offering Language Lessons', code: 'facture' },
{ task: 'Creating ASMR Content', code: 'practice' },
{ task: '$20,000 A Month From UGC', code: 'loser' },
{ task: 'Creating Virtual Escape Rooms', code: 'winner' },
{ task: 'Get Your Dream Job', code: 'windows' },
{ task: 'Earn $10,000 With Escape Rooms', code: 'cores' },
{ task: 'Selling Your Dreams', code: 'geforce' },
{ task: 'Creating GIFs', code: 'potato' },
{ task: 'Earn Money as a Virtual Friend', code: 'bulls' },
{ task: 'Learned To Code in 2 Months', code: 'bear' },
{ task: '10 Principles of Leadership', code: 'positive' },
{ task: 'Post Unoriginal Content', code: 'memory' },
{ task: 'Faceless TikTok Niches', code: 'boost' },
{ task: 'Pros and Cons of Entrepreneurship', code: 'september' },
{ task: 'Get Ahead of 99% of Teenagers', code: 'open' },
{ task: 'Turning Trash Into Art', code: 'update' },
{ task: 'Making Money from Odd Jobs', code: 'jingle' },
{ task: 'Make Money Creating and Selling Online Quizzes', code: 'green' },
{ task: 'Create and Sell Printable Coloring Pages', code: 'lobster' },
{ task: 'Make Money With Alibaba', code: 'viral' },
{ task: 'Monetize Your Spotify Playlists', code: 'monetize' },
{ task: 'Products That Will Make you a MILLIONAIRE', code: 'income' },
{ task: 'FUN JOBS THAT PAY WELL', code: 'numpad' },
{ task: 'Start Your Own Clothing Brand', code: 'timer' },
{ task: 'Earn EXTRA CASH from Home', code: 'purple' },
{ task: 'Ways To Make Money FAST', code: 'waves' },
{ task: 'Make MONEY with AR', code: 'ifresh' },
{ task: 'Selling NOTION TEMPLATES', code: 'friday' },
{ task: 'Tools For Making Money', code: 'october' },
{ task: '$10,000 a Month with DeFi', code: 'position' },
{ task: 'Freelance Video Editor', code: 'solana' },
{ task: 'Earn $8,200 per month', code: 'double' },
{ task: 'Rich people avoid paying taxes', code: 'december' },
{ task: 'REAL Profit from Selling VIRTUAL Real Estate', code: 'company' },
{ task: 'Make Money With 3D Printing', code: 'contains' },
{ task: 'YouTube WITHOUT MONETIZATION', code: 'heets' },
{ task: 'Skills That Pay Off Forever', code: 'ryzen' },
{ task: '$15,000 on designs for brands', code: 'turbo' },
{ task: 'Make Money with Customizable Tech Gadgets', code: 'gadgets' },
{ task: 'Myths About Making Money', code: 'about' },
{ task: 'Offering Pet Care Services', code: 'sanyo' },
{ task: 'Trading Mistakes', code: 'grapes' },
{ task: 'Promote Your Business', code: 'keyboard' },
{ task: 'Multiple Income Streams', code: 'universial' },
{ task: 'Instagram Reels VIRAL', code: 'monitor' },
{ task: 'Affiliate Marketing With AI', code: 'lemonade' },
{ task: 'Professions That Pay Well', code: 'linktg' },
{ task: 'Mistakes New Entrepreneurs Make', code: 'mistake' },
{ task: 'It\'s Time to Quit Your 9 to 5 Job', code: 'views' },
{ task: 'Create a Successful Business Plan', code: 'pending' },
{ task: 'TikTok Shop Dropshipping', code: 'holland' },
{ task: 'Stay Productive as a Solopreneur', code: 'mistakes' },
{ task: 'Mistakes to Avoid in Your 20s', code: 'solopr' },
{ task: 'Save Money While Traveling', code: 'ideas3' },
{ task: 'Business Ideas for Students', code: 'google' },
{ task: 'Spoiler Alert! Who Is Satoshi? | Part 1', code: 'K&(9)' },
{ task: '$500/Day with Google Search', code: 'student' },
{ task: 'Outsource Effectively', code: 'owner' },
{ task: 'Use LinkedIn to Grow', code: 'career' },
{ task: 'Spoiler Alert! Who Is Satoshi? | Part 2', code: '6A3=H' },
{ task: 'Make Money With GOOGLE', code: 'books' },
{ task: 'Become a Crypto Ambassador | Part 4', code: 'Рљ6@40' },
{ task: 'Products to SELL in Fallwinter', code: 'products' },
{ task: 'Create a Marketing Plan', code: 'market' },
{ task: 'Become a Crypto Ambassador | Part 5', code: 'F5O%3' },
{ task: '5 AI Apps to Automate Your Day', code: 'wasting' },
{ task: 'Minimalist Budget That Works', code: 'budget' },
{ task: 'Financial Goals to Set in Your 30s', code: 'goals' },
{ task: 'Own Website With No Coding', code: 'website' },
{ task: 'Spoiler Alert! Who Is Satoshi? | Part 3', code: 'W3#94' },
{ task: 'Online Portfolio That Gets You Hired', code: 'hired' },
{ task: 'Spoiler Alert! Who Is Satoshi? | Part 4', code: 'L5DC#' },
{ task: '16 Life lessons', code: 'before' },
{ task: 'Dropshipping with AI', code: 'dropship' },
{ task: 'Best Low-Cost Franchises', code: 'sport' },
{ task: 'Monetize Your Knowledge', code: 'unusual' },
{ task: 'YouTube Niches', code: 'niches' },
{ task: 'Professional Problem Solver', code: 'solver' },
{ task: 'Milady Maker NFTs Explained | Part 5', code: 'KL4$Y' },
{ task: 'Start a Zero-Waste Product Line', code: 'waste' },
{ task: 'Is Peter Todd Really Satoshi?', code: 'V1Y&E' },
{ task: 'Monetize Your Blog', code: 'zeros' },
{ task: "Twitter Explodes Over HBO's Claim!", code: 'JM5@S' },
{ task: 'Custom-Mode Clothing Line', code: 'printing' },
{ task: 'PERFECT TEAM For Business', code: 'perfect' },
{ task: '10 Rules of Success', code: 'negotiate' },
{ task: 'Fake Paparazzi', code: 'startn' },
{ task: 'Personalised Gift Business', code: 'laser' },
{ task: 'One Person Business', code: 'build' }
];
// Display tasks
function displayTasks(filteredTasks) {
const taskList = document.getElementById('task-list');
taskList.innerHTML = '';
if (filteredTasks.length === 0) {
taskList.innerHTML = `<div class="task"><span>No tasks found</span></div>`;
return;
}
filteredTasks.forEach((item) => {
const taskDiv = document.createElement('div');
taskDiv.className = 'task';
taskDiv.innerHTML = `<span>${item.task}</span><button onclick="copyCode('${item.code}')">Copy</button>`;
taskList.appendChild(taskDiv);
});
}
// Search Tasks
function searchTasks() {
const searchInput = document.getElementById('search');
const searchTerm = searchInput.value.toLowerCase();
const filteredTasks = tasks.filter(task =>
task.task.toLowerCase().includes(searchTerm)
);
displayTasks(filteredTasks);
}
// Copy Code
function copyCode(code) {
navigator.clipboard.writeText(code).then(() => {
showToast('Code copied to clipboard');
}, () => {
showToast('Failed to copy code');
});
}
// Show Toast Notification
function showToast(message) {
const toast = document.createElement('div');
toast.className = 'toast';
toast.innerText = message;
document.body.appendChild(toast);
setTimeout(() => {
document.body.removeChild(toast);
}, 3000);
}
// Dark Mode Toggle
document.getElementById('moodToggle').addEventListener('click', function() {
document.body.classList.toggle('high-mode');
this.classList.toggle('fa-moon');
this.classList.toggle('fa-sun');
this.title = document.body.classList.contains('high-mode') ? "Switch to Low Mode" : "Switch to High Mode";
});
// Hamburger Menu Toggle
const hamburger = document.getElementById('hamburger');
const menu = document.getElementById('menu');
const closeMenu = document.getElementById('closeMenu');
hamburger.addEventListener('click', function() {
menu.classList.add('active');
});
closeMenu.addEventListener('click', function() {
menu.classList.remove('active');
});
// Initial display of tasks
displayTasks(tasks);
</script>
</body>
</html>
books.dtd
<!ELEMENT library (book+)>
<!ELEMENT book (title, author, isbn, publisher, edition, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
books.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="isbn" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
<xs:element name="edition" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
use itb;
create table students(name varchar(50),rollno int,branch varchar(20));
insert into students (name,rollno,branch) values
('niha',90,'it'),
('nishka',95,'it'),
('nishu',96,'it');
JAVA
package jdbc;
import java.sql.*;
public class Simple_Connection {
Connection conn = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/itb","root","root");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery("Select * from students");
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getString(3));
}
conn.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
5.Javascript program to demostrate working of prototypal inheritance ,closure,callbacks,promises and sync/await
// Prototypal Inheritance
function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function() {
console.log(`${this.name} makes a noise.`);
};
function Dog(name) {
Animal.call(this, name); // Call the parent constructor
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.speak = function() {
console.log(`${this.name} barks.`);
};
// Closure
function createCounter() {
let count = 0; // Private variable
return {
increment: function() {
count++;
return count;
},
decrement: function() {
count--;
return count;
},
getCount: function() {
return count;
}
};
}
// Callback
function fetchData(callback) {
setTimeout(() => {
const data = { message: "Data fetched!" };
callback(data);
}, 1000);
}
// Promise
function fetchDataPromise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
const data = { message: "Data fetched with Promise!" };
resolve(data);
}, 1000);
});
}
// Async/Await
async function fetchDataAsync() {
const data = await fetchDataPromise();
console.log(data.message);
}
// Demonstration
function demo() {
// Prototypal Inheritance
const dog = new Dog('Buddy');
dog.speak(); // Output: Buddy barks.
// Closure
const counter = createCounter();
console.log(counter.increment()); // Output: 1
console.log(counter.increment()); // Output: 2
console.log(counter.decrement()); // Output: 1
console.log(counter.getCount()); // Output: 1
// Callback
fetchData((data) => {
console.log(data.message); // Output: Data fetched!
});
// Promise
fetchDataPromise().then((data) => {
console.log(data.message); // Output: Data fetched with Promise!
});
// Async/Await
fetchDataAsync(); // Output: Data fetched with Promise!
}
// Run the demonstration
demo();
3.Validate the registration ,user login,user profile and payment pages using javascript .Make use of any needed javascrpt objects
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Register</h1>
<form id="registrationForm">
<input type="text" id="username" placeholder="Username" required>
<input type="email" id="email" placeholder="Email" required>
<input type="password" id="password" placeholder="Password" required>
<button type="submit">Register</button>
<div id="message" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("registrationForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateRegistration();
});
function validateRegistration() {
const username = document.getElementById("username").value;
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const messageDiv = document.getElementById("message");
messageDiv.textContent = "";
// Simple validation
if (username.length < 3) {
messageDiv.textContent = "Username must be at least 3 characters.";
return;
}
if (!/\S+@\S+\.\S+/.test(email)) {
messageDiv.textContent = "Email is not valid.";
return;
}
if (password.length < 6) {
messageDiv.textContent = "Password must be at least 6 characters.";
return;
}
messageDiv.textContent = "Registration successful!";
// You can proceed to send the data to the server here
}
User Login Page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Login</h1>
<form id="loginForm">
<input type="email" id="loginEmail" placeholder="Email" required>
<input type="password" id="loginPassword" placeholder="Password" required>
<button type="submit">Login</button>
<div id="loginMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("loginForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateLogin();
});
function validateLogin() {
const email = document.getElementById("loginEmail").value;
const password = document.getElementById("loginPassword").value;
const loginMessageDiv = document.getElementById("loginMessage");
loginMessageDiv.textContent = "";
// Simple validation
if (!/\S+@\S+\.\S+/.test(email)) {
loginMessageDiv.textContent = "Email is not valid.";
return;
}
if (password.length < 6) {
loginMessageDiv.textContent = "Password must be at least 6 characters.";
return;
}
loginMessageDiv.textContent = "Login successful!";
// You can proceed to authenticate the user here
}
User Profile Page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>User Profile</h1>
<form id="profileForm">
<input type="text" id="profileUsername" placeholder="Username" required>
<input type="email" id="profileEmail" placeholder="Email" required>
<button type="submit">Update Profile</button>
<div id="profileMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("profileForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateProfile();
});
function validateProfile() {
const username = document.getElementById("profileUsername").value;
const email = document.getElementById("profileEmail").value;
const profileMessageDiv = document.getElementById("profileMessage");
profileMessageDiv.textContent = "";
// Simple validation
if (username.length < 3) {
profileMessageDiv.textContent = "Username must be at least 3 characters.";
return;
}
if (!/\S+@\S+\.\S+/.test(email)) {
profileMessageDiv.textContent = "Email is not valid.";
return;
}
profileMessageDiv.textContent = "Profile updated successfully!";
// You can proceed to update the user profile on the server here
}
Payment page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payment</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Payment</h1>
<form id="paymentForm">
<input type="text" id="cardNumber" placeholder="Card Number" required>
<input type="text" id="expiryDate" placeholder="MM/YY" required>
<input type="text" id="cvv" placeholder="CVV" required>
<button type="submit">Pay</button>
<div id="paymentMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("paymentForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validatePayment();
});
function validatePayment() {
const cardNumber = document.getElementById("cardNumber").value;
const expiryDate = document.getElementById("expiryDate").value;
const cvv = document.getElementById("cvv").value;
const paymentMessageDiv = document.getElementById("paymentMessage");
paymentMessageDiv.textContent = "";
// Simple validation
if (!/^\d{16}$/.test(cardNumber)) {
paymentMessageDiv.textContent = "Card number must be 16 digits.";
return;
}
if (!/^(0[1-9]|1[0-2])\/\d{2}$/.test(expiryDate)) {
paymentMessageDiv.textContent = "Expiry date must be in MM/YY format.";
return;
}
if (!/^\d{3}$/.test(cvv)) {
paymentMessageDiv.textContent = "CVV must be 3 digits.";
return;
}
paymentMessageDiv.textContent = "Payment successful!";
// You can proceed to process the payment here
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Web Page with Bootstrap</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="bg-success text-white text-center py-4">
<h1>My Awesome Web Page</h1>
</header>
<main class="container my-5">
<section class="row">
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 1</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 2</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 3</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 4</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 5</h5>
</div>
</div>
</div>
</section>
</main>
<footer class="bg-dark text-white text-center py-3">
<p>Footer Content</p>
</footer>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
CSS
.grid-item {
background-color: #ffcc00;
transition: transform 0.3s ease, background-color 0.3s ease;
}
.grid-item:hover {
transform: scale(1.05);
background-color: #ffd700;
}
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Submission</title>
</head>
<body>
<form action="/submit-form" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
// server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.post('/submit-form', (req, res) => {
const { name, email } = req.body;
res.send(Hello, ${name}! We have received your email: ${email}.);
});
app.listen(port, () => {
console.log(Server is running on http://localhost:${port});
});
TASK 13
Servlet code
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/exampleServlet")
public class ExampleServlet extends HttpServlet {
// Initialize the servlet and get ServletConfig and ServletContext
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Get ServletConfig parameters
String param1 = config.getInitParameter("param1");
String param2 = config.getInitParameter("param2");
// Print ServletConfig parameters
System.out.println("ServletConfig param1: " + param1);
System.out.println("ServletConfig param2: " + param2);
// Get ServletContext
ServletContext context = config.getServletContext();
// Get context parameters
String contextParam1 = context.getInitParameter("contextParam1");
// Print ServletContext parameters
System.out.println("ServletContext contextParam1: " + contextParam1);
}
// Handle HTTP GET requests
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.getWriter().println("<h1>ServletConfig and ServletContext Parameters</h1>");
response.getWriter().println("<p>Check the server logs for printed parameters.</p>");
}
}
Web. Xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>exampleServlet</servlet-name>
<servlet-class>ExampleServlet</servlet-class>
<init-param>
<param-name>param1</param-name>
<param-value>Value1</param-value>
</init-param>
<init-param>
<param-name>param2</param-name>
<param-value>Value2</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>exampleServlet</servlet-name>
<url-pattern>/exampleServlet</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextParam1</param-name>
<param-value>ContextValue1</param-value>
</context-param>
</web-app>
TASK 07
DTD
<!DOCTYPE library [
<!ELEMENT library (book+)>
<!ELEMENT book (title, author, isbn, publisher, edition, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
]>
XML
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="isbn" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
<xs:element name="edition" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
TASK 06
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<isbn>9780743273565</isbn>
<publisher>Charles Scribner's Sons</publisher>
<edition>First</edition>
<price>10.99</price>
</book>
<book>
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<isbn>9780060935467</isbn>
<publisher>J.B. Lippincott & Co.</publisher>
<edition>50th Anniversary</edition>
<price>7.99</price>
</book>
<book>
<title>1984</title>
<author>George Orwell</author>
<isbn>9780451524935</isbn>
<publisher>Harcourt Brace Jovanovich</publisher>
<edition>Signet Classics</edition>
<price>9.99</price>
</book>
</library>
package task11;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class metadata {
// Database URL, user, and password
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your username
static final String JDBC_PASSWORD = "root"; // Replace with your password
public static void main(String[] args) {
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD)) {
// Get database metadata
DatabaseMetaData dbMetaData = connection.getMetaData();
// Display general database information
System.out.println("Database Product Name: " + dbMetaData.getDatabaseProductName());
System.out.println("Database Product Version: " + dbMetaData.getDatabaseProductVersion());
System.out.println("Database Driver Name: " + dbMetaData.getDriverName());
System.out.println("Database Driver Version: " + dbMetaData.getDriverVersion());
// Retrieve and display table metadata
System.out.println("\nTables in the database:");
ResultSet tables = dbMetaData.getTables(null, null, "%", new String[] { "TABLE" });
while (tables.next()) {
String tableName = tables.getString("TABLE_NAME");
System.out.println("Table: " + tableName);
// Retrieve and display column metadata for each table
ResultSet columns = dbMetaData.getColumns(null, null, tableName, "%");
while (columns.next()) {
String columnName = columns.getString("COLUMN_NAME");
String columnType = columns.getString("TYPE_NAME");
int columnSize = columns.getInt("COLUMN_SIZE");
System.out.println(" Column: " + columnName + " - Type: " + columnType + " - Size: " + columnSize);
}
columns.close();
}
tables.close();
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task10;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class updandscroll {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
Statement statement = connection.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, // Scrollable ResultSet
ResultSet.CONCUR_UPDATABLE)) { // Updatable ResultSet
// Query to select all records from Students
String selectSQL = "SELECT id, name, age, grade FROM Students";
ResultSet resultSet = statement.executeQuery(selectSQL);
// Scroll to last row and display data
if (resultSet.last()) {
System.out.println("Last Row - ID: " + resultSet.getInt("id") +
", Name: " + resultSet.getString("name") +
", Age: " + resultSet.getInt("age") +
", Grade: " + resultSet.getString("grade"));
}
// Move to the first row and update the age and grade
resultSet.first();
resultSet.updateInt("age", resultSet.getInt("age") + 1); // Increase age by 1
resultSet.updateString("grade", "A"); // Set grade to 'A'
resultSet.updateRow(); // Commit the update
System.out.println("Updated first row age and grade.");
// Insert a new row into the ResultSet
resultSet.moveToInsertRow();
resultSet.updateInt("id", 101); // Example ID
resultSet.updateString("name", "New Student");
resultSet.updateInt("age", 20);
resultSet.updateString("grade", "B");
resultSet.insertRow();
System.out.println("Inserted new row.");
// Display all rows after the updates
resultSet.beforeFirst(); // Move cursor to the beginning
System.out.println("Updated Students Table:");
while (resultSet.next()) {
System.out.println("ID: " + resultSet.getInt("id") +
", Name: " + resultSet.getString("name") +
", Age: " + resultSet.getInt("age") +
", Grade: " + resultSet.getString("grade"));
}
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task9;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class preparedstmt {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
// SQL query to insert data into the Students table
String insertSQL = "INSERT INTO Students (name, age, grade) VALUES (?, ?, ?)";
// Try with resources to automatically close the connection and statement
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
PreparedStatement preparedStatement = connection.prepareStatement(insertSQL)) {
// Insert first student
preparedStatement.setString(1, "Alice");
preparedStatement.setInt(2, 20);
preparedStatement.setString(3, "A");
preparedStatement.executeUpdate();
System.out.println("Inserted first student: Alice");
// Insert second student
preparedStatement.setString(1, "Bob");
preparedStatement.setInt(2, 22);
preparedStatement.setString(3, "B");
preparedStatement.executeUpdate();
System.out.println("Inserted second student:s Bob");
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task9;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class callableprocedures {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
// SQL query to call the stored procedure
String callProcedureSQL = "{call selectGradeAStudents()}";
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
CallableStatement callableStatement = connection.prepareCall(callProcedureSQL);
ResultSet resultSet = callableStatement.executeQuery()) {
System.out.println("Students with Grade A:");
while (resultSet.next()) {
// Assuming the Students table has columns: id, name, age, and grade
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
String grade = resultSet.getString("grade");
System.out.printf("ID: %d, Name: %s, Age: %d, Grade: %s%n", id, name, age, grade);
}
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task9;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class callablefunctions {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
// SQL query to call the stored function
String callFunctionSQL = "{? = call getAverageAgeByGrade(?)}";
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
CallableStatement callableStatement = connection.prepareCall(callFunctionSQL)) {
// Register the output parameter (the average age)
callableStatement.registerOutParameter(1, java.sql.Types.DOUBLE);
// Set the input parameter (the grade for which we want the average age)
callableStatement.setString(2, "A"); // Change the grade as needed
// Execute the function
callableStatement.execute();
// Retrieve the output parameter
double averageAge = callableStatement.getDouble(1);
System.out.println("Average age of students with grade 'A': " + averageAge);
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task8;
import java.sql.*;
public class jdbcex {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
try {
// Load the MySQL JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
// Establish the connection
Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
System.out.println("Connected to the database.");
// Create a statement object to execute SQL commands
Statement statement = connection.createStatement();
// SQL query to create a table named "Students"
String createTableSQL = "CREATE TABLE IF NOT EXISTS Students (" +
"id INT AUTO_INCREMENT PRIMARY KEY, " +
"name VARCHAR(50) NOT NULL, " +
"age INT, " +
"grade VARCHAR(10)" +
");";
// Execute the SQL command to create the table
statement.executeUpdate(createTableSQL);
System.out.println("Table 'Students' created successfully.");
// Close the statement and connection
statement.close();
connection.close();
} catch (SQLException | ClassNotFoundException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
TASK 05
// Prototypal inheritance
function Person(name) {
this.name = name;
}
Person.prototype.greet = function () {
console.log(Hello, my name is ${this.name}.);
};
function Employee(name, jobTitle) {
Person.call(this, name); // Call parent constructor
this.jobTitle = jobTitle;
}
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.constructor = Employee;
Employee.prototype.describeJob = function () {
console.log(I am a ${this.jobTitle}.);
};
// Closure example
function createCounter() {
let count = 0; // Private variable
return () => ++count; // Increment count and return
}
// Callback example
function fetchData(callback) {
setTimeout(() => {
const data = { id: 1, name: "John Doe" };
callback(data);
}, 1000); // Simulate async operation
}
// Promise example
function fetchDataPromise() {
return new Promise((resolve) => {
setTimeout(() => {
resolve({ id: 2, name: "Jane Smith" });
}, 1000);
});
}
// Async/Await example
async function fetchAndProcessData() {
const data = await fetchDataPromise();
console.log(Fetched data: ${JSON.stringify(data)});
}
// Instantiate and use
const person = new Person("Alice");
const employee = new Employee("Bob", "Developer");
person.greet(); // Hello, my name is Alice.
employee.greet(); // Hello, my name is Bob.
employee.describeJob(); // I am a Developer.
const counter = createCounter();
console.log(counter()); // 1
console.log(counter()); // 2
fetchData((data) => {
console.log(Fetched data using callback: ${JSON.stringify(data)});
});
fetchAndProcessData(); // Fetched data: {"id":2,"name":"Jane Smith"}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scientific Calculator</title>
<style>
body { display: flex; justify-content: center; align-items: center; height: 100vh; background: #f4f4f4; font-family: Arial; }
.calculator { background: #fff; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); padding: 20px; }
#display { width: 100%; height: 40px; font-size: 24px; text-align: right; border: 1px solid #ddd; border-radius: 5px; padding: 5px; margin-bottom: 10px; }
.buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
button { padding: 15px; font-size: 18px; background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; }
button:hover { background: #0056b3; }
</style>
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<div class="buttons">
<button onclick="clearDisplay()">C</button>
<button onclick="appendToDisplay('(')">(</button>
<button onclick="appendToDisplay(')')">)</button>
<button onclick="appendToDisplay('/')">/</button>
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('')"></button>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="appendToDisplay('-')">-</button>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('+')">+</button>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="appendToDisplay('.')">.</button>
<button onclick="calculate()">=</button>
<button onclick="appendToDisplay('Math.sqrt(')">√</button>
<button onclick="appendToDisplay('Math.pow(')">x²</button>
<button onclick="appendToDisplay('Math.sin(')">sin</button>
<button onclick="appendToDisplay('Math.cos(')">cos</button>
<button onclick="appendToDisplay('Math.tan(')">tan</button>
</div>
</div>
<script>
function appendToDisplay(value) { document.getElementById('display').value += value; }
function clearDisplay() { document.getElementById('display').value = ''; }
function calculate() {
try { document.getElementById('display').value = eval(document.getElementById('display').value); }
catch { document.getElementById('display').value = 'Error'; }
}
</script>
</body>
</html>
Task -3
Registration page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration</title>
</head>
<body>
<form id="registrationForm">
<input type="text" id="username" placeholder="Username" required><br>
<input type="email" id="email" placeholder="Email" required><br>
<input type="password" id="password" placeholder="Password" required><br>
<input type="text" id="phone" placeholder="Phone" required><br>
<button type="submit">Register</button>
</form>
<script>
registrationForm.onsubmit = (e) => {
e.preventDefault();
const username = username.value, email = email.value, password = password.value, phone = phone.value;
const errors = [
username.length < 5 && "Username must be 5+ characters",
!/@/.test(email) && "Invalid email",
password.length < 6 && "Password must be 6+ characters",
!/^\d{10}$/.test(phone) && "Phone must be 10 digits"
].filter(Boolean);
alert(errors.length ? errors.join("\n") : "Registration successful!");
};
</script>
</body>
</html>
Task-3
Login page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<form id="loginForm">
<input type="text" id="loginUsername" placeholder="Username" required><br>
<input type="password" id="loginPassword" placeholder="Password" required><br>
<button type="submit">Login</button>
</form>
<script>
loginForm.onsubmit = (e) => {
e.preventDefault();
const username = loginUsername.value, password = loginPassword.value;
alert(username && password ? "Login successful!" : "Please fill out all fields.");
};
</script>
</body>
</html>
Task -3
User profile page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
</head>
<body>
<form id="profileForm">
<input type="text" id="name" placeholder="Name" required><br>
<input type="email" id="profileEmail" placeholder="Email" required><br>
<input type="text" id="address" placeholder="Address" required><br>
<button type="submit">Update</button>
</form>
<script>
profileForm.onsubmit = (e) => {
e.preventDefault();
const name = name.value, email = profileEmail.value, address = address.value;
const errors = [
name.length < 3 && "Name must be 3+ characters",
!/@/.test(email) && "Invalid email",
address.length < 5 && "Address must be 5+ characters"
].filter(Boolean);
alert(errors.length ? errors.join("\n") : "Profile updated!");
};
</script>
</body>
</html>
Task -3
Payment page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payment</title>
</head>
<body>
<form id="paymentForm">
<input type="text" id="cardNumber" placeholder="Card Number" required><br>
<input type="text" id="expiryDate" placeholder="MM/YY" required><br>
<input type="text" id="cvv" placeholder="CVV" required><br>
<button type="submit">Pay</button>
</form>
<script>
paymentForm.onsubmit = (e) => {
e.preventDefault();
const cardNumber = cardNumber.value, expiryDate = expiryDate.value, cvv = cvv.value;
const errors = [
!/^\d{16}$/.test(cardNumber) && "Card must be 16 digits",
!/^\d{2}\/\d{2}$/.test(expiryDate) && "Invalid date format",
!/^\d{3}$/.test(cvv) && "CVV must be 3 digits"
].filter(Boolean);
alert(errors.length ? errors.join("\n") : "Payment successful!");
};
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Bootstrap Layout</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Header -->
<header class="bg-primary text-white text-center py-5">
<h1>Welcome to My Page</h1>
<p>Explore Bootstrap Layouts!</p>
</header>
<!-- Main Content -->
<main class="container my-5">
<div class="row">
<!-- Cards Section -->
<section class="col-lg-8 col-md-7 mb-4">
<div class="row">
<div class="col-sm-6 mb-4">
<div class="card shadow-sm">
<div class="card-body text-center">Card 1</div>
</div>
</div>
<div class="col-sm-6 mb-4">
<div class="card shadow-sm">
<div class="card-body text-center">Card 2</div>
</div>
</div>
</div>
</section>
<!-- Sidebar -->
<aside class="col-lg-4 col-md-5 mb-4">
<div class="card shadow-sm">
<div class="card-body">
<h2>Sidebar</h2>
<p>Sidebar content here.</p>
</div>
</div>
</aside>
</div>
</main>
<!-- Footer -->
<footer class="bg-dark text-white text-center py-3">
<p>© 2024 My Page</p>
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
1.create a web page using the advanced features of css:Grid,Flexbox.And apply transition and animations on the contents of the webpage
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Grid and Flexbox Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="header">
<h1>My Awesome Web Page</h1>
</header>
<main class="main-content">
<section class="grid-container">
<div class="grid-item">Item 1</div>
<div class="grid-item">Item 2</div>
<div class="grid-item">Item 3</div>
<div class="grid-item">Item 4</div>
<div class="grid-item">Item 5</div>
</section>
</main>
<footer class="footer">
<p>Footer Content</p>
</footer>
</body>
</html>
CSS
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
height: 100vh;
}
.header {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 20px;
}
.main-content {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
background-color: #f4f4f4;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 15px;
padding: 20px;
}
.grid-item {
background-color: #ffcc00;
padding: 20px;
border-radius: 5px;
text-align: center;
transition: transform 0.3s ease, background-color 0.3s ease;
}
.grid-item:hover {
transform: scale(1.1);
background-color: #ffd700;
}
.footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.header, .footer {
animation: fadeIn 1s ease-in;
}
2.make the webpages created in the above experiment as responsive web page with Bootstrap Framework
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Web Page with Bootstrap</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="bg-success text-white text-center py-4">
<h1>My Awesome Web Page</h1>
</header>
<main class="container my-5">
<section class="row">
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 1</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 2</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 3</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 4</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 5</h5>
</div>
</div>
</div>
</section>
</main>
<footer class="bg-dark text-white text-center py-3">
<p>Footer Content</p>
</footer>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
CSS
.grid-item {
background-color: #ffcc00;
transition: transform 0.3s ease, background-color 0.3s ease;
}
.grid-item:hover {
transform: scale(1.05);
background-color: #ffd700;
}
3.Validate the registration ,user login,user profile and payment pages using javascript .Make use of any needed javascrpt objects
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Register</h1>
<form id="registrationForm">
<input type="text" id="username" placeholder="Username" required>
<input type="email" id="email" placeholder="Email" required>
<input type="password" id="password" placeholder="Password" required>
<button type="submit">Register</button>
<div id="message" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("registrationForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateRegistration();
});
function validateRegistration() {
const username = document.getElementById("username").value;
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const messageDiv = document.getElementById("message");
messageDiv.textContent = "";
// Simple validation
if (username.length < 3) {
messageDiv.textContent = "Username must be at least 3 characters.";
return;
}
if (!/\S+@\S+\.\S+/.test(email)) {
messageDiv.textContent = "Email is not valid.";
return;
}
if (password.length < 6) {
messageDiv.textContent = "Password must be at least 6 characters.";
return;
}
messageDiv.textContent = "Registration successful!";
// You can proceed to send the data to the server here
}
User Login Page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Login</h1>
<form id="loginForm">
<input type="email" id="loginEmail" placeholder="Email" required>
<input type="password" id="loginPassword" placeholder="Password" required>
<button type="submit">Login</button>
<div id="loginMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("loginForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateLogin();
});
function validateLogin() {
const email = document.getElementById("loginEmail").value;
const password = document.getElementById("loginPassword").value;
const loginMessageDiv = document.getElementById("loginMessage");
loginMessageDiv.textContent = "";
// Simple validation
if (!/\S+@\S+\.\S+/.test(email)) {
loginMessageDiv.textContent = "Email is not valid.";
return;
}
if (password.length < 6) {
loginMessageDiv.textContent = "Password must be at least 6 characters.";
return;
}
loginMessageDiv.textContent = "Login successful!";
// You can proceed to authenticate the user here
}
User Profile Page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>User Profile</h1>
<form id="profileForm">
<input type="text" id="profileUsername" placeholder="Username" required>
<input type="email" id="profileEmail" placeholder="Email" required>
<button type="submit">Update Profile</button>
<div id="profileMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("profileForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateProfile();
});
function validateProfile() {
const username = document.getElementById("profileUsername").value;
const email = document.getElementById("profileEmail").value;
const profileMessageDiv = document.getElementById("profileMessage");
profileMessageDiv.textContent = "";
// Simple validation
if (username.length < 3) {
profileMessageDiv.textContent = "Username must be at least 3 characters.";
return;
}
if (!/\S+@\S+\.\S+/.test(email)) {
profileMessageDiv.textContent = "Email is not valid.";
return;
}
profileMessageDiv.textContent = "Profile updated successfully!";
// You can proceed to update the user profile on the server here
}
Payment page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payment</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Payment</h1>
<form id="paymentForm">
<input type="text" id="cardNumber" placeholder="Card Number" required>
<input type="text" id="expiryDate" placeholder="MM/YY" required>
<input type="text" id="cvv" placeholder="CVV" required>
<button type="submit">Pay</button>
<div id="paymentMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("paymentForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validatePayment();
});
function validatePayment() {
const cardNumber = document.getElementById("cardNumber").value;
const expiryDate = document.getElementById("expiryDate").value;
const cvv = document.getElementById("cvv").value;
const paymentMessageDiv = document.getElementById("paymentMessage");
paymentMessageDiv.textContent = "";
// Simple validation
if (!/^\d{16}$/.test(cardNumber)) {
paymentMessageDiv.textContent = "Card number must be 16 digits.";
return;
}
if (!/^(0[1-9]|1[0-2])\/\d{2}$/.test(expiryDate)) {
paymentMessageDiv.textContent = "Expiry date must be in MM/YY format.";
return;
}
if (!/^\d{3}$/.test(cvv)) {
paymentMessageDiv.textContent = "CVV must be 3 digits.";
return;
}
paymentMessageDiv.textContent = "Payment successful!";
// You can proceed to process the payment here
}
4.Build a scientific calculator
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scientific Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<div class="buttons">
<button onclick="clearDisplay()">C</button>
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('/')">/</button>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="appendToDisplay('*')">*</button>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('-')">-</button>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="appendToDisplay('.')">.</button>
<button onclick="calculate()">=</button>
<button onclick="appendToDisplay('+')">+</button>
<button onclick="calculate('sqrt')">√</button>
<button onclick="calculate('pow')">x²</button>
<button onclick="calculate('sin')">sin</button>
<button onclick="calculate('cos')">cos</button>
<button onclick="calculate('tan')">tan</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
.calculator {
background-color: white;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 300px;
}
#display {
width: 100%;
height: 40px;
text-align: right;
font-size: 24px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
padding: 5px;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
button {
height: 40px;
font-size: 18px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
script.js
function appendToDisplay(value) {
document.getElementById("display").value += value;
}
function clearDisplay() {
document.getElementById("display").value = "";
}
function calculate(operation) {
const display = document.getElementById("display");
let result;
try {
if (operation === 'sqrt') {
result = Math.sqrt(eval(display.value));
} else if (operation === 'pow') {
result = Math.pow(eval(display.value), 2);
} else if (['sin', 'cos', 'tan'].includes(operation)) {
const angle = eval(display.value) * (Math.PI / 180); // Convert to radians
result = Math[operation](angle);
} else {
result = eval(display.value);
}
display.value = result;
} catch (error) {
display.value = "Error!";
}
}
5.Javascript program to demostrate working of prototypal inheritance ,closure,callbacks,promises and sync/await
// Prototypal Inheritance
function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function() {
console.log(`${this.name} makes a noise.`);
};
function Dog(name) {
Animal.call(this, name); // Call the parent constructor
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.speak = function() {
console.log(`${this.name} barks.`);
};
// Closure
function createCounter() {
let count = 0; // Private variable
return {
increment: function() {
count++;
return count;
},
decrement: function() {
count--;
return count;
},
getCount: function() {
return count;
}
};
}
// Callback
function fetchData(callback) {
setTimeout(() => {
const data = { message: "Data fetched!" };
callback(data);
}, 1000);
}
// Promise
function fetchDataPromise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
const data = { message: "Data fetched with Promise!" };
resolve(data);
}, 1000);
});
}
// Async/Await
async function fetchDataAsync() {
const data = await fetchDataPromise();
console.log(data.message);
}
// Demonstration
function demo() {
// Prototypal Inheritance
const dog = new Dog('Buddy');
dog.speak(); // Output: Buddy barks.
// Closure
const counter = createCounter();
console.log(counter.increment()); // Output: 1
console.log(counter.increment()); // Output: 2
console.log(counter.decrement()); // Output: 1
console.log(counter.getCount()); // Output: 1
// Callback
fetchData((data) => {
console.log(data.message); // Output: Data fetched!
});
// Promise
fetchDataPromise().then((data) => {
console.log(data.message); // Output: Data fetched with Promise!
});
// Async/Await
fetchDataAsync(); // Output: Data fetched with Promise!
}
// Run the demonstration
demo();
6.Write an xml file which will display the Book information with the following fields : Title of the book,Author name,ISBN number ,Publisher name,Edition,Price.
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<isbn>978-0743273565</isbn>
<publisher>Scribner</publisher>
<edition>1st</edition>
<price>10.99</price>
</book>
<book>
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<isbn>978-0061120084</isbn>
<publisher>Harper Perennial Modern Classics</publisher>
<edition>50th Anniversary Edition</edition>
<price>7.19</price>
</book>
<book>
<title>1984</title>
<author>George Orwell</author>
<isbn>978-0451524935</isbn>
<publisher>Signet Classics</publisher>
<edition>Anniversary Edition</edition>
<price>9.99</price>
</book>
<book>
<title>Moby Dick</title>
<author>Herman Melville</author>
<isbn>978-1503280786</isbn>
<publisher>CreateSpace Independent Publishing Platform</publisher>
<edition>1st</edition>
<price>11.95</price>
</book>
<book>
<title>Brave New World</title>
<author>Aldous Huxley</author>
<isbn>978-0060850524</isbn>
<publisher>Harper Perennial Modern Classics</publisher>
<edition>Reissue</edition>
<price>14.99</price>
</book>
</library>
7.Define a Document Type Definition(DTD) and xml schema to validate the above created xml Documents
books.dtd
<!ELEMENT library (book+)>
<!ELEMENT book (title, author, isbn, publisher, edition, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
books.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="isbn" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
<xs:element name="edition" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
8.8.write a java program to establish a connection to a database and execute simple SQL queries
SQL
use itb;
create table students(name varchar(50),rollno int,branch varchar(20));
insert into students (name,rollno,branch) values
('niha',90,'it'),
('nishka',95,'it'),
('nishu',96,'it');
JAVA
package jdbc;
import java.sql.*;
public class Simple_Connection {
Connection conn = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/itb","root","root");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery("Select * from students");
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getString(3));
}
conn.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
9.write a java program to demonstrate the usage of JDBC in performing various DML statements .Use prepared statements and callable statements
SQL
CREATE DATABASE sampledb;
USE sampledb;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
JAVA
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.CallableStatement;
import java.sql.ResultSet;
public class JdbcDmlExample {
private static final String URL = "jdbc:mysql://localhost:3306/sampledb";
private static final String USERNAME = "your_username"; // Replace with your DB username
private static final String PASSWORD = "your_password"; // Replace with your DB password
public static void main(String[] args) {
Connection connection = null;
try {
// Establishing the connection
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("Connected to the database successfully.");
// Inserting data using PreparedStatement
insertUser(connection, "Alice Johnson", "alice@example.com");
insertUser(connection, "Bob Smith", "bob@example.com");
// Updating data using PreparedStatement
updateUserEmail(connection, 1, "alice.new@example.com");
// Calling stored procedure using CallableStatement
callUserCountProcedure(connection);
} catch (SQLException e) {
System.err.println("SQL Exception: " + e.getMessage());
} finally {
// Closing the connection
try {
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Database connection closed.");
}
} catch (SQLException e) {
System.err.println("Failed to close the connection: " + e.getMessage());
}
}
}
// Method to insert user using PreparedStatement
private static void insertUser(Connection connection, String name, String email) throws SQLException {
String insertSQL = "INSERT INTO users (name, email) VALUES (?, ?)";
try (PreparedStatement pstmt = connection.prepareStatement(insertSQL)) {
pstmt.setString(1, name);
pstmt.setString(2, email);
int rowsAffected = pstmt.executeUpdate();
System.out.println(rowsAffected + " user(s) inserted.");
}
}
// Method to update user email using PreparedStatement
private static void updateUserEmail(Connection connection, int userId, String newEmail) throws SQLException {
String updateSQL = "UPDATE users SET email = ? WHERE id = ?";
try (PreparedStatement pstmt = connection.prepareStatement(updateSQL)) {
pstmt.setString(1, newEmail);
pstmt.setInt(2, userId);
int rowsAffected = pstmt.executeUpdate();
System.out.println(rowsAffected + " user(s) updated.");
}
}
// Method to call a stored procedure using CallableStatement
private static void callUserCountProcedure(Connection connection) throws SQLException {
// Assuming there is a stored procedure named `GetUserCount` that returns the count of users
String procedureCall = "{ CALL GetUserCount() }";
try (CallableStatement cstmt = connection.prepareCall(procedureCall)) {
try (ResultSet rs = cstmt.executeQuery()) {
if (rs.next()) {
int userCount = rs.getInt(1);
System.out.println("Total users: " + userCount);
}
}
}
}
}
10.write a java based application to demonstrate the Updatable and Scrollable resultsets
SQL
CREATE DATABASE sampledb;
USE sampledb;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
JAVA
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;
public class UpdatableScrollableResultSetExample {
private static final String URL = "jdbc:mysql://localhost:3306/sampledb";
private static final String USERNAME = "your_username"; // Replace with your DB username
private static final String PASSWORD = "your_password"; // Replace with your DB password
public static void main(String[] args) {
Connection connection = null;
try {
// Establishing the connection
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("Connected to the database successfully.");
// Inserting some sample data
insertSampleData(connection);
// Using Updatable and Scrollable ResultSet
try (Statement stmt = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
String query = "SELECT * FROM users";
ResultSet rs = stmt.executeQuery(query);
// Moving to the last record
if (rs.last()) {
System.out.println("Last Record: ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Email: " + rs.getString("email"));
}
// Moving to the first record
if (rs.first()) {
System.out.println("First Record: ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Email: " + rs.getString("email"));
}
// Updating the first record
if (rs.first()) {
System.out.println("Updating record...");
rs.updateString("name", "Updated Name");
rs.updateRow();
System.out.println("Record updated.");
}
// Displaying updated records
System.out.println("Updated Records:");
rs.beforeFirst(); // Move cursor to before the first record
while (rs.next()) {
System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Email: " + rs.getString("email"));
}
}
} catch (SQLException e) {
System.err.println("SQL Exception: " + e.getMessage());
} finally {
// Closing the connection
try {
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Database connection closed.");
}
} catch (SQLException e) {
System.err.println("Failed to close the connection: " + e.getMessage());
}
}
}
// Method to insert sample data into the users table
private static void insertSampleData(Connection connection) throws SQLException {
String insertSQL = "INSERT INTO users (name, email) VALUES (?, ?)";
try (PreparedStatement pstmt = connection.prepareStatement(insertSQL)) {
pstmt.setString(1, "John Doe");
pstmt.setString(2, "john@example.com");
pstmt.executeUpdate();
pstmt.setString(1, "Jane Smith");
pstmt.setString(2, "jane@example.com");
pstmt.executeUpdate();
System.out.println("Sample data inserted into users table.");
}
}
}
11.write a java program to access metadata of the SQL database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DatabaseMetadataExample {
private static final String URL = "jdbc:mysql://localhost:3306/sampledb"; // Replace with your DB URL
private static final String USERNAME = "your_username"; // Replace with your DB username
private static final String PASSWORD = "your_password"; // Replace with your DB password
public static void main(String[] args) {
Connection connection = null;
try {
// Establishing the connection
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("Connected to the database successfully.");
// Accessing database metadata
DatabaseMetaData metaData = connection.getMetaData();
// Retrieve and display basic information
System.out.println("Database Product Name: " + metaData.getDatabaseProductName());
System.out.println("Database Product Version: " + metaData.getDatabaseProductVersion());
System.out.println("Driver Name: " + metaData.getDriverName());
System.out.println("Driver Version: " + metaData.getDriverVersion());
System.out.println("SQL Syntax: " + metaData.getSQLKeywords());
// Get and display the tables
System.out.println("\nTables in the database:");
ResultSet tables = metaData.getTables(null, null, "%", new String[]{"TABLE"});
while (tables.next()) {
String tableName = tables.getString("TABLE_NAME");
System.out.println("Table: " + tableName);
// Get and display columns for each table
ResultSet columns = metaData.getColumns(null, null, tableName, null);
System.out.println(" Columns in " + tableName + ":");
while (columns.next()) {
String columnName = columns.getString("COLUMN_NAME");
String columnType = columns.getString("TYPE_NAME");
int columnSize = columns.getInt("COLUMN_SIZE");
System.out.printf(" %s (%s, Size: %d)%n", columnName, columnType, columnSize);
}
}
} catch (SQLException e) {
System.err.println("SQL Exception: " + e.getMessage());
} finally {
// Closing the connection
try {
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Database connection closed.");
}
} catch (SQLException e) {
System.err.println("Failed to close the connection: " + e.getMessage());
}
}
}
}
12. write a java program to accept request parameters a form and generate the response
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Form</title>
</head>
<body>
<h1>User Information Form</h1>
<form action="ResponseServlet" method="POST">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
ResponseServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ResponseServlet")
public class ResponseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the response content type
response.setContentType("text/html");
// Get the parameters from the request
String name = request.getParameter("name");
String email = request.getParameter("email");
// Generate the response
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h2>User Information</h2>");
out.println("<p>Name: " + name + "</p>");
out.println("<p>Email: " + email + "</p>");
out.println("</body></html>");
}
}
13.write a program to accept ServletConfig and ServletContext parameters
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ConfigServlet")
public class ConfigServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the response content type
response.setContentType("text/html");
// Get ServletConfig and ServletContext
ServletConfig config = getServletConfig();
ServletContext context = getServletContext();
// Get parameters from ServletConfig
String servletParam = config.getInitParameter("servletParam");
// Get parameters from ServletContext
String contextParam = context.getInitParameter("contextParam");
// Generate the response
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h2>Servlet Config and Context Parameters</h2>");
out.println("<p>Servlet Parameter: " + servletParam + "</p>");
out.println("<p>Context Parameter: " + contextParam + "</p>");
out.println("</body></html>");
}
}
1.create a web page using the advanced features of css:Grid,Flexbox.And apply transition and animations on the contents of the webpage
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Grid and Flexbox Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="header">
<h1>My Awesome Web Page</h1>
</header>
<main class="main-content">
<section class="grid-container">
<div class="grid-item">Item 1</div>
<div class="grid-item">Item 2</div>
<div class="grid-item">Item 3</div>
<div class="grid-item">Item 4</div>
<div class="grid-item">Item 5</div>
</section>
</main>
<footer class="footer">
<p>Footer Content</p>
</footer>
</body>
</html>
CSS
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
height: 100vh;
}
.header {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 20px;
}
.main-content {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
background-color: #f4f4f4;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 15px;
padding: 20px;
}
.grid-item {
background-color: #ffcc00;
padding: 20px;
border-radius: 5px;
text-align: center;
transition: transform 0.3s ease, background-color 0.3s ease;
}
.grid-item:hover {
transform: scale(1.1);
background-color: #ffd700;
}
.footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.header, .footer {
animation: fadeIn 1s ease-in;
}
2.make the webpages created in the above experiment as responsive web page with Bootstrap Framework
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Web Page with Bootstrap</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="bg-success text-white text-center py-4">
<h1>My Awesome Web Page</h1>
</header>
<main class="container my-5">
<section class="row">
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 1</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 2</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 3</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 4</h5>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card grid-item">
<div class="card-body">
<h5 class="card-title">Item 5</h5>
</div>
</div>
</div>
</section>
</main>
<footer class="bg-dark text-white text-center py-3">
<p>Footer Content</p>
</footer>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
CSS
.grid-item {
background-color: #ffcc00;
transition: transform 0.3s ease, background-color 0.3s ease;
}
.grid-item:hover {
transform: scale(1.05);
background-color: #ffd700;
}
3.Validate the registration ,user login,user profile and payment pages using javascript .Make use of any needed javascrpt objects
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Register</h1>
<form id="registrationForm">
<input type="text" id="username" placeholder="Username" required>
<input type="email" id="email" placeholder="Email" required>
<input type="password" id="password" placeholder="Password" required>
<button type="submit">Register</button>
<div id="message" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("registrationForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateRegistration();
});
function validateRegistration() {
const username = document.getElementById("username").value;
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const messageDiv = document.getElementById("message");
messageDiv.textContent = "";
// Simple validation
if (username.length < 3) {
messageDiv.textContent = "Username must be at least 3 characters.";
return;
}
if (!/\S+@\S+\.\S+/.test(email)) {
messageDiv.textContent = "Email is not valid.";
return;
}
if (password.length < 6) {
messageDiv.textContent = "Password must be at least 6 characters.";
return;
}
messageDiv.textContent = "Registration successful!";
// You can proceed to send the data to the server here
}
User Login Page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Login</h1>
<form id="loginForm">
<input type="email" id="loginEmail" placeholder="Email" required>
<input type="password" id="loginPassword" placeholder="Password" required>
<button type="submit">Login</button>
<div id="loginMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("loginForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateLogin();
});
function validateLogin() {
const email = document.getElementById("loginEmail").value;
const password = document.getElementById("loginPassword").value;
const loginMessageDiv = document.getElementById("loginMessage");
loginMessageDiv.textContent = "";
// Simple validation
if (!/\S+@\S+\.\S+/.test(email)) {
loginMessageDiv.textContent = "Email is not valid.";
return;
}
if (password.length < 6) {
loginMessageDiv.textContent = "Password must be at least 6 characters.";
return;
}
loginMessageDiv.textContent = "Login successful!";
// You can proceed to authenticate the user here
}
User Profile Page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>User Profile</h1>
<form id="profileForm">
<input type="text" id="profileUsername" placeholder="Username" required>
<input type="email" id="profileEmail" placeholder="Email" required>
<button type="submit">Update Profile</button>
<div id="profileMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("profileForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validateProfile();
});
function validateProfile() {
const username = document.getElementById("profileUsername").value;
const email = document.getElementById("profileEmail").value;
const profileMessageDiv = document.getElementById("profileMessage");
profileMessageDiv.textContent = "";
// Simple validation
if (username.length < 3) {
profileMessageDiv.textContent = "Username must be at least 3 characters.";
return;
}
if (!/\S+@\S+\.\S+/.test(email)) {
profileMessageDiv.textContent = "Email is not valid.";
return;
}
profileMessageDiv.textContent = "Profile updated successfully!";
// You can proceed to update the user profile on the server here
}
Payment page(HTML)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payment</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Payment</h1>
<form id="paymentForm">
<input type="text" id="cardNumber" placeholder="Card Number" required>
<input type="text" id="expiryDate" placeholder="MM/YY" required>
<input type="text" id="cvv" placeholder="CVV" required>
<button type="submit">Pay</button>
<div id="paymentMessage" class="error-message"></div>
</form>
<script src="script.js"></script>
</body>
</html>
script.js
document.getElementById("paymentForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
validatePayment();
});
function validatePayment() {
const cardNumber = document.getElementById("cardNumber").value;
const expiryDate = document.getElementById("expiryDate").value;
const cvv = document.getElementById("cvv").value;
const paymentMessageDiv = document.getElementById("paymentMessage");
paymentMessageDiv.textContent = "";
// Simple validation
if (!/^\d{16}$/.test(cardNumber)) {
paymentMessageDiv.textContent = "Card number must be 16 digits.";
return;
}
if (!/^(0[1-9]|1[0-2])\/\d{2}$/.test(expiryDate)) {
paymentMessageDiv.textContent = "Expiry date must be in MM/YY format.";
return;
}
if (!/^\d{3}$/.test(cvv)) {
paymentMessageDiv.textContent = "CVV must be 3 digits.";
return;
}
paymentMessageDiv.textContent = "Payment successful!";
// You can proceed to process the payment here
}
4.Build a scientific calculator
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scientific Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<div class="buttons">
<button onclick="clearDisplay()">C</button>
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('/')">/</button>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="appendToDisplay('*')">*</button>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('-')">-</button>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="appendToDisplay('.')">.</button>
<button onclick="calculate()">=</button>
<button onclick="appendToDisplay('+')">+</button>
<button onclick="calculate('sqrt')">√</button>
<button onclick="calculate('pow')">x²</button>
<button onclick="calculate('sin')">sin</button>
<button onclick="calculate('cos')">cos</button>
<button onclick="calculate('tan')">tan</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
.calculator {
background-color: white;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 300px;
}
#display {
width: 100%;
height: 40px;
text-align: right;
font-size: 24px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
padding: 5px;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
button {
height: 40px;
font-size: 18px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
script.js
function appendToDisplay(value) {
document.getElementById("display").value += value;
}
function clearDisplay() {
document.getElementById("display").value = "";
}
function calculate(operation) {
const display = document.getElementById("display");
let result;
try {
if (operation === 'sqrt') {
result = Math.sqrt(eval(display.value));
} else if (operation === 'pow') {
result = Math.pow(eval(display.value), 2);
} else if (['sin', 'cos', 'tan'].includes(operation)) {
const angle = eval(display.value) * (Math.PI / 180); // Convert to radians
result = Math[operation](angle);
} else {
result = eval(display.value);
}
display.value = result;
} catch (error) {
display.value = "Error!";
}
}
5.Javascript program to demostrate working of prototypal inheritance ,closure,callbacks,promises and sync/await
// Prototypal Inheritance
function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function() {
console.log(`${this.name} makes a noise.`);
};
function Dog(name) {
Animal.call(this, name); // Call the parent constructor
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.speak = function() {
console.log(`${this.name} barks.`);
};
// Closure
function createCounter() {
let count = 0; // Private variable
return {
increment: function() {
count++;
return count;
},
decrement: function() {
count--;
return count;
},
getCount: function() {
return count;
}
};
}
// Callback
function fetchData(callback) {
setTimeout(() => {
const data = { message: "Data fetched!" };
callback(data);
}, 1000);
}
// Promise
function fetchDataPromise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
const data = { message: "Data fetched with Promise!" };
resolve(data);
}, 1000);
});
}
// Async/Await
async function fetchDataAsync() {
const data = await fetchDataPromise();
console.log(data.message);
}
// Demonstration
function demo() {
// Prototypal Inheritance
const dog = new Dog('Buddy');
dog.speak(); // Output: Buddy barks.
// Closure
const counter = createCounter();
console.log(counter.increment()); // Output: 1
console.log(counter.increment()); // Output: 2
console.log(counter.decrement()); // Output: 1
console.log(counter.getCount()); // Output: 1
// Callback
fetchData((data) => {
console.log(data.message); // Output: Data fetched!
});
// Promise
fetchDataPromise().then((data) => {
console.log(data.message); // Output: Data fetched with Promise!
});
// Async/Await
fetchDataAsync(); // Output: Data fetched with Promise!
}
// Run the demonstration
demo();
6.Write an xml file which will display the Book information with the following fields : Title of the book,Author name,ISBN number ,Publisher name,Edition,Price.
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<isbn>978-0743273565</isbn>
<publisher>Scribner</publisher>
<edition>1st</edition>
<price>10.99</price>
</book>
<book>
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<isbn>978-0061120084</isbn>
<publisher>Harper Perennial Modern Classics</publisher>
<edition>50th Anniversary Edition</edition>
<price>7.19</price>
</book>
<book>
<title>1984</title>
<author>George Orwell</author>
<isbn>978-0451524935</isbn>
<publisher>Signet Classics</publisher>
<edition>Anniversary Edition</edition>
<price>9.99</price>
</book>
<book>
<title>Moby Dick</title>
<author>Herman Melville</author>
<isbn>978-1503280786</isbn>
<publisher>CreateSpace Independent Publishing Platform</publisher>
<edition>1st</edition>
<price>11.95</price>
</book>
<book>
<title>Brave New World</title>
<author>Aldous Huxley</author>
<isbn>978-0060850524</isbn>
<publisher>Harper Perennial Modern Classics</publisher>
<edition>Reissue</edition>
<price>14.99</price>
</book>
</library>
7.Define a Document Type Definition(DTD) and xml schema to validate the above created xml Documents
books.dtd
<!ELEMENT library (book+)>
<!ELEMENT book (title, author, isbn, publisher, edition, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
books.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="isbn" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
<xs:element name="edition" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
8.8.write a java program to establish a connection to a database and execute simple SQL queries
SQL
use itb;
create table students(name varchar(50),rollno int,branch varchar(20));
insert into students (name,rollno,branch) values
('niha',90,'it'),
('nishka',95,'it'),
('nishu',96,'it');
JAVA
package jdbc;
import java.sql.*;
public class Simple_Connection {
Connection conn = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/itb","root","root");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery("Select * from students");
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getString(3));
}
conn.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
9.write a java program to demonstrate the usage of JDBC in performing various DML statements .Use prepared statements and callable statements
SQL
CREATE DATABASE sampledb;
USE sampledb;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
JAVA
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.CallableStatement;
import java.sql.ResultSet;
public class JdbcDmlExample {
private static final String URL = "jdbc:mysql://localhost:3306/sampledb";
private static final String USERNAME = "your_username"; // Replace with your DB username
private static final String PASSWORD = "your_password"; // Replace with your DB password
public static void main(String[] args) {
Connection connection = null;
try {
// Establishing the connection
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("Connected to the database successfully.");
// Inserting data using PreparedStatement
insertUser(connection, "Alice Johnson", "alice@example.com");
insertUser(connection, "Bob Smith", "bob@example.com");
// Updating data using PreparedStatement
updateUserEmail(connection, 1, "alice.new@example.com");
// Calling stored procedure using CallableStatement
callUserCountProcedure(connection);
} catch (SQLException e) {
System.err.println("SQL Exception: " + e.getMessage());
} finally {
// Closing the connection
try {
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Database connection closed.");
}
} catch (SQLException e) {
System.err.println("Failed to close the connection: " + e.getMessage());
}
}
}
// Method to insert user using PreparedStatement
private static void insertUser(Connection connection, String name, String email) throws SQLException {
String insertSQL = "INSERT INTO users (name, email) VALUES (?, ?)";
try (PreparedStatement pstmt = connection.prepareStatement(insertSQL)) {
pstmt.setString(1, name);
pstmt.setString(2, email);
int rowsAffected = pstmt.executeUpdate();
System.out.println(rowsAffected + " user(s) inserted.");
}
}
// Method to update user email using PreparedStatement
private static void updateUserEmail(Connection connection, int userId, String newEmail) throws SQLException {
String updateSQL = "UPDATE users SET email = ? WHERE id = ?";
try (PreparedStatement pstmt = connection.prepareStatement(updateSQL)) {
pstmt.setString(1, newEmail);
pstmt.setInt(2, userId);
int rowsAffected = pstmt.executeUpdate();
System.out.println(rowsAffected + " user(s) updated.");
}
}
// Method to call a stored procedure using CallableStatement
private static void callUserCountProcedure(Connection connection) throws SQLException {
// Assuming there is a stored procedure named `GetUserCount` that returns the count of users
String procedureCall = "{ CALL GetUserCount() }";
try (CallableStatement cstmt = connection.prepareCall(procedureCall)) {
try (ResultSet rs = cstmt.executeQuery()) {
if (rs.next()) {
int userCount = rs.getInt(1);
System.out.println("Total users: " + userCount);
}
}
}
}
}
10.write a java based application to demonstrate the Updatable and Scrollable resultsets
SQL
CREATE DATABASE sampledb;
USE sampledb;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
JAVA
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;
public class UpdatableScrollableResultSetExample {
private static final String URL = "jdbc:mysql://localhost:3306/sampledb";
private static final String USERNAME = "your_username"; // Replace with your DB username
private static final String PASSWORD = "your_password"; // Replace with your DB password
public static void main(String[] args) {
Connection connection = null;
try {
// Establishing the connection
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("Connected to the database successfully.");
// Inserting some sample data
insertSampleData(connection);
// Using Updatable and Scrollable ResultSet
try (Statement stmt = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
String query = "SELECT * FROM users";
ResultSet rs = stmt.executeQuery(query);
// Moving to the last record
if (rs.last()) {
System.out.println("Last Record: ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Email: " + rs.getString("email"));
}
// Moving to the first record
if (rs.first()) {
System.out.println("First Record: ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Email: " + rs.getString("email"));
}
// Updating the first record
if (rs.first()) {
System.out.println("Updating record...");
rs.updateString("name", "Updated Name");
rs.updateRow();
System.out.println("Record updated.");
}
// Displaying updated records
System.out.println("Updated Records:");
rs.beforeFirst(); // Move cursor to before the first record
while (rs.next()) {
System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Email: " + rs.getString("email"));
}
}
} catch (SQLException e) {
System.err.println("SQL Exception: " + e.getMessage());
} finally {
// Closing the connection
try {
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Database connection closed.");
}
} catch (SQLException e) {
System.err.println("Failed to close the connection: " + e.getMessage());
}
}
}
// Method to insert sample data into the users table
private static void insertSampleData(Connection connection) throws SQLException {
String insertSQL = "INSERT INTO users (name, email) VALUES (?, ?)";
try (PreparedStatement pstmt = connection.prepareStatement(insertSQL)) {
pstmt.setString(1, "John Doe");
pstmt.setString(2, "john@example.com");
pstmt.executeUpdate();
pstmt.setString(1, "Jane Smith");
pstmt.setString(2, "jane@example.com");
pstmt.executeUpdate();
System.out.println("Sample data inserted into users table.");
}
}
}
11.write a java program to access metadata of the SQL database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DatabaseMetadataExample {
private static final String URL = "jdbc:mysql://localhost:3306/sampledb"; // Replace with your DB URL
private static final String USERNAME = "your_username"; // Replace with your DB username
private static final String PASSWORD = "your_password"; // Replace with your DB password
public static void main(String[] args) {
Connection connection = null;
try {
// Establishing the connection
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("Connected to the database successfully.");
// Accessing database metadata
DatabaseMetaData metaData = connection.getMetaData();
// Retrieve and display basic information
System.out.println("Database Product Name: " + metaData.getDatabaseProductName());
System.out.println("Database Product Version: " + metaData.getDatabaseProductVersion());
System.out.println("Driver Name: " + metaData.getDriverName());
System.out.println("Driver Version: " + metaData.getDriverVersion());
System.out.println("SQL Syntax: " + metaData.getSQLKeywords());
// Get and display the tables
System.out.println("\nTables in the database:");
ResultSet tables = metaData.getTables(null, null, "%", new String[]{"TABLE"});
while (tables.next()) {
String tableName = tables.getString("TABLE_NAME");
System.out.println("Table: " + tableName);
// Get and display columns for each table
ResultSet columns = metaData.getColumns(null, null, tableName, null);
System.out.println(" Columns in " + tableName + ":");
while (columns.next()) {
String columnName = columns.getString("COLUMN_NAME");
String columnType = columns.getString("TYPE_NAME");
int columnSize = columns.getInt("COLUMN_SIZE");
System.out.printf(" %s (%s, Size: %d)%n", columnName, columnType, columnSize);
}
}
} catch (SQLException e) {
System.err.println("SQL Exception: " + e.getMessage());
} finally {
// Closing the connection
try {
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Database connection closed.");
}
} catch (SQLException e) {
System.err.println("Failed to close the connection: " + e.getMessage());
}
}
}
}
12. write a java program to accept request parameters a form and generate the response
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Form</title>
</head>
<body>
<h1>User Information Form</h1>
<form action="ResponseServlet" method="POST">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
ResponseServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ResponseServlet")
public class ResponseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the response content type
response.setContentType("text/html");
// Get the parameters from the request
String name = request.getParameter("name");
String email = request.getParameter("email");
// Generate the response
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h2>User Information</h2>");
out.println("<p>Name: " + name + "</p>");
out.println("<p>Email: " + email + "</p>");
out.println("</body></html>");
}
}
13.write a program to accept ServletConfig and ServletContext parameters
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ConfigServlet")
public class ConfigServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the response content type
response.setContentType("text/html");
// Get ServletConfig and ServletContext
ServletConfig config = getServletConfig();
ServletContext context = getServletContext();
// Get parameters from ServletConfig
String servletParam = config.getInitParameter("servletParam");
// Get parameters from ServletContext
String contextParam = context.getInitParameter("contextParam");
// Generate the response
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h2>Servlet Config and Context Parameters</h2>");
out.println("<p>Servlet Parameter: " + servletParam + "</p>");
out.println("<p>Context Parameter: " + contextParam + "</p>");
out.println("</body></html>");
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stylish Page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="header">
<h1>Welcome to My Stylish Page</h1>
<p>Experience CSS Grid, Flexbox, and Animations!</p>
</header>
<main class="container">
<section class="content">
<div class="card">Card 1</div>
<div class="card">Card 2</div>
<div class="card">Card 3</div>
<div class="card">Card 4</div>
</section>
<aside class="sidebar">
<h2>Sidebar</h2>
<p>This is the sidebar content.</p>
</aside>
</main>
<footer class="footer">
<p>© 2024 My Stylish Page</p>
</footer>
</body>
</html>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
color: #333;
}
.container {
display: grid;
grid-template-columns: 3fr 1fr;
gap: 20px;
padding: 20px;
}
.header, .footer {
text-align: center;
background-color: #333;
color: #fff;
padding: 20px;
}
.content {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.card {
flex: 1 1 calc(50% - 20px);
background: #4CAF50;
color: #fff;
padding: 20px;
border-radius: 10px;
text-align: center;
transition: transform 0.3s, background 0.3s;
cursor: pointer;
}
.card:hover {
transform: scale(1.05);
background: #45a049;
}
.sidebar {
background: #f4f4f4;
padding: 20px;
border-radius: 10px;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
.header h1, .content .card {
animation: fadeIn 1s ease-in-out;
}
.content .card {
animation-delay: 0.5s;
animation-fill-mode: backwards;
}
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.prog2.ui.theme.Prog2Theme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
val nav_Controller = rememberNavController()
NavHost(navController = nav_Controller,
startDestination = "fragment1") {
composable("fragment1") {
Fragment1(nav_Controller)
}
composable("fragment2") {
Fragment2(nav_Controller) }
}
}
}
}
@Composable
fun Fragment1(navController: NavController){
Column {
Button(onClick={ navController.navigate("fragment2")}) {
Text(text = "Navigate to fragment2 ")
}
}
}
@Composable
fun Fragment2(navController: NavController) {
Row(horizontalArrangement = Arrangement.SpaceEvenly){
Button(onClick = { navController.navigateUp() }) {
Text(text = "Back to Fragment 1")
}
}
}
/////////*********** LOOPS FOR ARRAYS IN JS ////////////////
// for of
const arr = [1,3,3,4,5]
for(const n of arr){ // n is just a variable in which array elements is stored
console.log(n); // OUTPUT = 1 3 3 4 5
}
const greet = "hello world"
for(const greetings of greet){ // greetings is just a variable in which array elements is stored
console.log(`the value of greet ${greetings}`);
}
/// Maps (always take different values means no repetation and always print in the order they re saved ) maps are not itterable too
const map = new Map();
map.set('IN', "INDIA");
map.set('FR', "FRANCE");
map.set('US', "UNITED STATES OF AMERICA");
console.log(map);
for(const[key,value] of map){
console.log(key,":->",value)
}// OUTPUT = IN :-> INDIA FR :-> FRANCE US :-> UNITED STATES OF AMERICA
// MainActivity.kt
package com.example.dbtest
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.room.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
// Room Database-related code (User entity, DAO, and Database class)
// User data class representing the database table
@Entity(tableName = "users")
data class User(
@PrimaryKey(autoGenerate = true) val uid: Int = 0,
val username: String,
val phone: String
)
// DAO interface for database operations
@Dao
interface UserDAO {
@Insert
suspend fun insert(user: User)
}
// Room Database class
@Database(entities = [User::class], version = 1)
abstract class UserDatabase : RoomDatabase() {
abstract fun userDao(): UserDAO
companion object {
@Volatile
private var INSTANCE: UserDatabase? = null
fun getInstance(context: android.content.Context): UserDatabase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
UserDatabase::class.java,
"user_database"
).build()
INSTANCE = instance
instance
}
}
}
}
// Main Activity to set up the content and provide the database instance
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val database = UserDatabase.getInstance(this)
setContent {
InsertRecord(database)
}
}
}
// Composable function for inserting user data
@Composable
fun InsertRecord(database: UserDatabase) {
val context = LocalContext.current
val userDao = database.userDao()
var name by remember { mutableStateOf("") }
var phone by remember { mutableStateOf("") }
val scope = rememberCoroutineScope()
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
Text(text = "Enter your details here")
Spacer(modifier = Modifier.height(25.dp))
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text(text = "Enter your name") },
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(25.dp))
OutlinedTextField(
value = phone,
onValueChange = { phone = it },
label = { Text(text = "Enter your phone number") },
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(25.dp))
Button(onClick = {
scope.launch(Dispatchers.IO) {
// Insert user data in the database
userDao.insert(User(username = name, phone = phone))
// Display Toast on the main thread
withContext(Dispatchers.Main) {
Toast.makeText(context, "Record Inserted Successfully", Toast.LENGTH_LONG).show()
}
}
}) {
Text(text = "Insert Now")
}
}
}
//Plugins
//kotlin("kapt")
//Dependencies
//val room_version = "2.6.1"
// implementation("androidx.room:room-runtime:$room_version")
// kapt("androidx.room:room-compiler:$room_version")
// implementation("androidx.room:room-ktx:$room_version")
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> create database varshitha;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| varshitha |
+--------------------+
5 rows in set (0.00 sec)
mysql> use varshitha;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_varshitha |
+---------------------+
| students |
+---------------------+
1 row in set (0.02 sec)
mysql> desc students;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
| age | int(11) | YES | | NULL | |
| grade | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
mysql> select * from students;
+----+-------+------+-------+
| id | name | age | grade |
+----+-------+------+-------+
| 1 | Alice | 20 | A |
| 2 | Bob | 22 | B |
+----+-------+------+-------+
2 rows in set (0.00 sec)
mysql> DELIMITER //
mysql> CREATE PROCEDURE selectGradeAStudents()
-> BEGIN
-> SELECT * FROM Students WHERE grade = 'A';
-> END //
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION getAverageAgeByGrade(gradeInput VARCHAR(10))
-> RETURNS DOUBLE
-> BEGIN
-> DECLARE avgAge DOUBLE;
-> SELECT AVG(age) INTO avgAge FROM Students WHERE grade = gradeInput;
-> RETURN avgAge;
-> END //
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
package task11;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class metadata {
// Database URL, user, and password
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your username
static final String JDBC_PASSWORD = "root"; // Replace with your password
public static void main(String[] args) {
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD)) {
// Get database metadata
DatabaseMetaData dbMetaData = connection.getMetaData();
// Display general database information
System.out.println("Database Product Name: " + dbMetaData.getDatabaseProductName());
System.out.println("Database Product Version: " + dbMetaData.getDatabaseProductVersion());
System.out.println("Database Driver Name: " + dbMetaData.getDriverName());
System.out.println("Database Driver Version: " + dbMetaData.getDriverVersion());
// Retrieve and display table metadata
System.out.println("\nTables in the database:");
ResultSet tables = dbMetaData.getTables(null, null, "%", new String[] { "TABLE" });
while (tables.next()) {
String tableName = tables.getString("TABLE_NAME");
System.out.println("Table: " + tableName);
// Retrieve and display column metadata for each table
ResultSet columns = dbMetaData.getColumns(null, null, tableName, "%");
while (columns.next()) {
String columnName = columns.getString("COLUMN_NAME");
String columnType = columns.getString("TYPE_NAME");
int columnSize = columns.getInt("COLUMN_SIZE");
System.out.println(" Column: " + columnName + " - Type: " + columnType + " - Size: " + columnSize);
}
columns.close();
}
tables.close();
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task10;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class updandscroll {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
Statement statement = connection.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, // Scrollable ResultSet
ResultSet.CONCUR_UPDATABLE)) { // Updatable ResultSet
// Query to select all records from Students
String selectSQL = "SELECT id, name, age, grade FROM Students";
ResultSet resultSet = statement.executeQuery(selectSQL);
// Scroll to last row and display data
if (resultSet.last()) {
System.out.println("Last Row - ID: " + resultSet.getInt("id") +
", Name: " + resultSet.getString("name") +
", Age: " + resultSet.getInt("age") +
", Grade: " + resultSet.getString("grade"));
}
// Move to the first row and update the age and grade
resultSet.first();
resultSet.updateInt("age", resultSet.getInt("age") + 1); // Increase age by 1
resultSet.updateString("grade", "A"); // Set grade to 'A'
resultSet.updateRow(); // Commit the update
System.out.println("Updated first row age and grade.");
// Insert a new row into the ResultSet
resultSet.moveToInsertRow();
resultSet.updateInt("id", 101); // Example ID
resultSet.updateString("name", "New Student");
resultSet.updateInt("age", 20);
resultSet.updateString("grade", "B");
resultSet.insertRow();
System.out.println("Inserted new row.");
// Display all rows after the updates
resultSet.beforeFirst(); // Move cursor to the beginning
System.out.println("Updated Students Table:");
while (resultSet.next()) {
System.out.println("ID: " + resultSet.getInt("id") +
", Name: " + resultSet.getString("name") +
", Age: " + resultSet.getInt("age") +
", Grade: " + resultSet.getString("grade"));
}
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task9;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class callablefunctions {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
// SQL query to call the stored function
String callFunctionSQL = "{? = call getAverageAgeByGrade(?)}";
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
CallableStatement callableStatement = connection.prepareCall(callFunctionSQL)) {
// Register the output parameter (the average age)
callableStatement.registerOutParameter(1, java.sql.Types.DOUBLE);
// Set the input parameter (the grade for which we want the average age)
callableStatement.setString(2, "A"); // Change the grade as needed
// Execute the function
callableStatement.execute();
// Retrieve the output parameter
double averageAge = callableStatement.getDouble(1);
System.out.println("Average age of students with grade 'A': " + averageAge);
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task9;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class callableprocedures {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
// SQL query to call the stored procedure
String callProcedureSQL = "{call selectGradeAStudents()}";
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
CallableStatement callableStatement = connection.prepareCall(callProcedureSQL);
ResultSet resultSet = callableStatement.executeQuery()) {
System.out.println("Students with Grade A:");
while (resultSet.next()) {
// Assuming the Students table has columns: id, name, age, and grade
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
String grade = resultSet.getString("grade");
System.out.printf("ID: %d, Name: %s, Age: %d, Grade: %s%n", id, name, age, grade);
}
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
package task9;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class preparedstmt {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
// SQL query to insert data into the Students table
String insertSQL = "INSERT INTO Students (name, age, grade) VALUES (?, ?, ?)";
// Try with resources to automatically close the connection and statement
try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
PreparedStatement preparedStatement = connection.prepareStatement(insertSQL)) {
// Insert first student
preparedStatement.setString(1, "Alice");
preparedStatement.setInt(2, 20);
preparedStatement.setString(3, "A");
preparedStatement.executeUpdate();
System.out.println("Inserted first student: Alice");
// Insert second student
preparedStatement.setString(1, "Bob");
preparedStatement.setInt(2, 22);
preparedStatement.setString(3, "B");
preparedStatement.executeUpdate();
System.out.println("Inserted second student:s Bob");
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.getMessage());
}
}
}
package task8;
import java.sql.*;
public class jdbcex {
// Database credentials and URL
static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
static final String JDBC_USER = "root"; // Replace with your MySQL username
static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password
public static void main(String[] args) {
try {
// Load the MySQL JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
// Establish the connection
Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
System.out.println("Connected to the database.");
// Create a statement object to execute SQL commands
Statement statement = connection.createStatement();
// SQL query to create a table named "Students"
String createTableSQL = "CREATE TABLE IF NOT EXISTS Students (" +
"id INT AUTO_INCREMENT PRIMARY KEY, " +
"name VARCHAR(50) NOT NULL, " +
"age INT, " +
"grade VARCHAR(10)" +
");";
// Execute the SQL command to create the table
statement.executeUpdate(createTableSQL);
System.out.println("Table 'Students' created successfully.");
// Close the statement and connection
statement.close();
connection.close();
} catch (SQLException | ClassNotFoundException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Pricing Table</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
margin: 0;
}
.pricing-table {
display: flex;
justify-content: space-around;
width: 80%;
}
.card {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 10px;
padding: 20px;
text-align: center;
transition: transform 0.3s, box-shadow 0.3s;
width: 30%;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.card:hover {
transform: scale(1.05);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}
.card.selected {
background-color: #007bff;
color: white;
border: none;
}
.card.selected:hover {
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}
.price {
font-size: 2rem;
margin: 10px 0;
}
button {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
background-color: #007bff;
color: white;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="pricing-table">
<div class="card" onclick="selectCard(this)">
<h3>Basic Plan</h3>
<div class="price">$10/month</div>
<p>Basic features included.</p>
<button>Choose</button>
</div>
<div class="card" onclick="selectCard(this)">
<h3>Standard Plan</h3>
<div class="price">$20/month</div>
<p>Standard features included.</p>
<button>Choose</button>
</div>
<div class="card" onclick="selectCard(this)">
<h3>Premium Plan</h3>
<div class="price">$30/month</div>
<p>All features included.</p>
<button>Choose</button>
</div>
</div>
<script>
function selectCard(card) {
// Remove 'selected' class from all cards
const cards = document.querySelectorAll('.card');
cards.forEach(c => c.classList.remove('selected'));
// Add 'selected' class to the clicked card
card.classList.add('selected');
}
</script>
</body>
</html>
Sat Nov 02 2024 12:27:22 GMT+0000 (Coordinated Universal Time) https://www.stattutorials.com/SAS/TUTORIAL-SAS-FUNCTION-SYMPUT1.html
Sat Nov 02 2024 12:26:54 GMT+0000 (Coordinated Universal Time) https://sas.1or9.com/fru3oq9fam/59267/m10/m10_34.htm
Sat Nov 02 2024 08:52:41 GMT+0000 (Coordinated Universal Time) https://etherscan.io/verifyContract-solc?a
Sat Nov 02 2024 07:37:03 GMT+0000 (Coordinated Universal Time) https://medium.com/coinmonks/top-nft-marketplace-development-companies-3b2caed0cd45
@LilianAnderson #nftmarketplacedevelopment #nftbusinessgrowth #nftdevelopmentpartner #blockchaindevelopmentcompany #nftstartupsuccess
Sat Nov 02 2024 06:22:29 GMT+0000 (Coordinated Universal Time) https://www.programiz.com/python-programming/keyword-list
Fri Nov 01 2024 20:46:24 GMT+0000 (Coordinated Universal Time) https://myairdropinfocenterDaily-t.com


