0% found this document useful (0 votes)
4 views6 pages

Wtfile

Web Tech File

Uploaded by

Vansh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Wtfile

Web Tech File

Uploaded by

Vansh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT 4

OBJECTIVE : Writing program in XML for creation of DTD, which specifies


set of rules. Create a style sheet in CSS/XSL & display the document in
internet explorer.

XML:-

<!DOCTYPE products [
<!ELEMENT products (product+)>
<!ELEMENT product (name, price, description)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT description (#PCDATA)>
]>
<products>
<product>
<name>Product A</name>
<price>$19.99</price>
<description>A high-quality product</description>
</product>
<product>
<name>Product B</name>
<price>$29.99</price>
<description>An advanced product</description>
</product>
</products>

CSS:-

products {
font-family: Arial, sans-serif;
}

product {
border: 1px solid #ccc;
margin-bottom: 10px;
padding: 10px;
}
name {
font-size: 18px;
font-weight: bold;
}

price {
font-weight: bold;
color: #28a745;
}

description {
color: #6c757d;
}
EXPERIMENT 8

OBJECTIVE : Write a Java program that implements a multi-thread


application that has three threads. First thread generates random integer
every 1 second and if the value is even, second thread computes the
square of the number and prints. If the value is odd, the third thread will
print the value of cube of the number.

import java.util.Random;

class RandomNumberGenerator implements Runnable {


public void run() {
Random rand = new Random();
try {
while (true) {
int randomNumber = rand.nextInt(100);
System.out.println("Generated Number: " + randomNumber);

if (randomNumber % 2 == 0) {
synchronized (Main.squareThread) {
Main.squareThread.setNumber(randomNumber);
Main.squareThread.notify();
}
} else {
synchronized (Main.cubeThread) {
Main.cubeThread.setNumber(randomNumber);
Main.cubeThread.notify();
}
}

Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
class SquareThread implements Runnable {
private int number;

public synchronized void setNumber(int number) {


this.number = number;
}

public void run() {


try {
while (true) {
synchronized (this) {
wait();
System.out.println("Square of " + number + ": " + (number * number));
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

class CubeThread implements Runnable {


private int number;

public synchronized void setNumber(int number) {


this.number = number;
}

public void run() {


try {
while (true) {
synchronized (this) {
wait();
System.out.println("Cube of " + number + ": " + (number * number *
number));
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

public class Main {


static SquareThread squareThread;
static CubeThread cubeThread;

public static void main(String[] args) {


squareThread = new SquareThread();
cubeThread = new CubeThread();

Thread generatorThread = new Thread(new RandomNumberGenerator());


Thread squareThread = new Thread(Main.squareThread);
Thread cubeThread = new Thread(Main.cubeThread);

generatorThread.start();
squareThread.start();
cubeThread.start();
}
}
EXPERIMENT 6

OBJECTIVE : Create a Java Program to find out the IP address of your


machine.

import java.net.*;

public class IPAddressFinder {


public static void main(String[] args) {
try {
InetAddress myIP = InetAddress.getLocalHost();
System.out.println("My IP Address is: " + myIP.getHostAddress());
} catch (UnknownHostException e) {
System.out.println("Unable to determine IP address: " + e.getMessage());
}
}
}

You might also like