WT
Tue Nov 19 2024 06:09:21 GMT+0000 (Coordinated Universal Time)
Saved by @cseb26
1. Create a web page using the advanced features of CSS Grid. Apply transitions and animations to the contents of the web page. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Minimal CSS Grid</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: Arial, sans-serif; background: #f4f4f4; color: #333; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 80%; max-width: 800px; } .item { background: #ffffff; border: 1px solid #ddd; border-radius: 5px; padding: 20px; text-align: center; transition: transform 0.3s ease, background-color 0.3s ease; } .item:hover { transform: scale(1.05); background-color: #f0f8ff; } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } .container { animation: fadeIn 1s ease-in-out; } </style> </head> <body> <div class="container"> <div class="item">Item 1</div> <div class="item">Item 2</div> <div class="item">Item 3</div> <div class="item">Item 4</div> <div class="item">Item 5</div> <div class="item">Item 6</div> </div> </body> </html> 2. Create a web page using the advanced features of CSS Flexbox. Apply transitions and animations to the contents of the web page. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Basic Flexbox with Animation</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { display: flex; justify-content: center; align-items: center; height: 100vh; background: #f0f0f0; font-family: Arial, sans-serif; } .container { display: flex; flex-wrap: wrap; justify-content: space-around; gap: 20px; } .card { background: #fff; padding: 20px; text-align: center; border-radius: 8px; width: 200px; transition: transform 0.3s ease; } .card:hover { transform: scale(1.05); } </style> </head> <body> <div class="container"> <div class="card"> <h3>Card 1</h3> <p>Some interesting text.</p> </div> <div class="card"> <h3>Card 2</h3> <p>More details here.</p> </div> <div class="card"> <h3>Card 3</h3> <p>Additional content.</p> </div> </div> </body> </html> 3. Demonstrate pop-up box alerts, confirm, and prompt using JavaScript. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>JavaScript Pop-ups</title> </head> <body> <button onclick="showAlert()">Show Alert</button> <button onclick="showConfirm()">Show Confirm</button> <button onclick="showPrompt()">Show Prompt</button> <script> function showAlert() { alert("This is a simple alert box!"); } function showConfirm() { const result = confirm("Do you want to proceed?"); if (result) { alert("You chose to proceed!"); } else { alert("You chose to cancel."); } } function showPrompt() { const name = prompt("What is your name?"); if (name) { alert(`Hello, ${name}! Welcome!`); } else { alert("You didn't enter a name."); } } </script> </body> </html> 4. Demonstrate Responsive Web Design using Media Queries to create a webpage. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Simple Media Query</title> <style> body { color: black; } @media (max-width: 600px) { body { color: blue; } } </style> </head> <body> Resize the browser to see the text color change! </body> </html> 5. Write a JavaScript program to demonstrate the working of callbacks, promises, and async/await. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>JavaScript Callbacks, Promises, Async/Await</title> </head> <body> <h1>JavaScript Callbacks, Promises, and Async/Await Demo</h1> <script> // Callback Example function doSomething(callback) { setTimeout(() => { callback("Callback done!"); }, 1000); } doSomething(console.log); // Promise Example let promise = new Promise((resolve, reject) => { setTimeout(() => resolve("Promise resolved!"), 1000); }); promise.then(console.log); // Async/Await Example async function asyncFunction() { let result = await promise; console.log(result); } asyncFunction(); </script> </body> </html> 6. Write an XML file that displays book information with the following fields: Title of the book, Author Name, ISBN number, Publisher name, Edition, and Price. Define a Document Type Definition (DTD) to validate the XML document created above. Book.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE books SYSTEM "books.dtd"> <books> <book> <title>The Great Gatsby</title> <author>F. Scott Fitzgerald</author> <isbn>9780743273565</isbn> <publisher>Scribner</publisher> <edition>1st</edition> <price>10.99</price> . </book> <book> <title>1984</title> <author>George Orwell</author> <isbn>9780451524935</isbn> <publisher>Signet Classic</publisher> <edition>Revised</edition> <price>9.99</price> </book> </books> Book.dtd <!ELEMENT books (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)> 7. Write an XML file that displays book information with the following fields: Title of the book, Author Name, ISBN number, Publisher name, Edition, and Price. Define an XML schema to validate the XML document created above. Books.xml <?xml version="1.0" encoding="UTF-8"?> <books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example.com/books books.xsd"> <book> <title>The Great Gatsby</title> <author>F. Scott Fitzgerald</author> <isbn>9780743273565</isbn> <publisher>Scribner</publisher> <edition>1st</edition> <price>10.99</price> </book> <book> <title>1984</title> <author>George Orwell</author> <isbn>9780451524935</isbn> <publisher>Signet Classic</publisher> <edition>Revised</edition> <price>9.99</price> </book> </books> Books.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/books" targetNamespace="http://example.com/books" elementFormDefault="qualified"> <!-- Define the root element --> <xs:element name="books"> <xs:complexType> <xs:sequence> <!-- The 'book' element can occur one or more times --> <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. Write a Java application to validate the XML document using the DOM parser. import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.SAXException; import java.io.File; public class DOMDTDValidator { public static void main(String[] args) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); factory.setNamespaceAware(false); DocumentBuilder builder = factory.newDocumentBuilder(); File xmlFile = new File("books.xml"); builder.parse(xmlFile); System.out.println("The XML document is valid."); } catch (SAXException e) { System.out.println("Validation error: " + e.getMessage()); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } books.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE books SYSTEM "books.dtd"> <books> <book> <title>The Great Gatsby</title> <author>F. Scott Fitzgerald</author> <isbn>9780743273565</isbn> <price>10.99</price> </book> <book> <title>1984</title> <author>George Orwell</author> <isbn>9780451524935</isbn> <price>9.99</price> </book> </books> Books.dtd <!ELEMENT books (book+)> <!ELEMENT book (title, author, isbn, price)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT isbn (#PCDATA)> <!ELEMENT price (#PCDATA)> 9. Write a Java application to validate the XML document using the SAX parser. Java code import org.xml.sax.SAXException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.File; public class SAXValidationExample { public static void main(String[] args) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); factory.setNamespaceAware(true); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(new File("example.xml"), new SimpleHandler()); System.out.println("XML is valid."); } catch (SAXException e) { System.out.println("Validation error: " + e.getMessage()); } catch (Exception e) { e.printStackTrace(); } } } books.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE books SYSTEM "books.dtd"> <books> <book> <title>The Great Gatsby</title> <author>F. Scott Fitzgerald</author> <isbn>9780743273565</isbn> <price>10.99</price> </book> <book> <title>1984</title> <author>George Orwell</author> <isbn>9780451524935</isbn> <price>9.99</price> </book> </books> Books.dtd <!ELEMENT books (book+)> <!ELEMENT book (title, author, isbn, price)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT isbn (#PCDATA)> <!ELEMENT price (#PCDATA)> All three in same folder complie and run the java file 10. Write a Java program to access the metadata of an SQL database. import java.sql.*; public class DatabaseMetadataDemo { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/your_database_name"; // Replace with your DB name String user = "root"; // Replace with your DB username String password = "your_password"; // Replace with your DB password try (Connection conn = DriverManager.getConnection(url, user, password)) { DatabaseMetaData metaData = conn.getMetaData(); System.out.println("Database: " + metaData.getDatabaseProductName()); System.out.println("Version: " + metaData.getDatabaseProductVersion()); System.out.println("\nTables:"); ResultSet tables = metaData.getTables(null, null, "%", new String[]{"TABLE"}); while (tables.next()) { System.out.println("- " + tables.getString("TABLE_NAME")); } } catch (SQLException e) { e.printStackTrace(); } } } 11.Java script scientific Calculator <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Simple Calculator</title> </head> <body> <h2>Simple Calculator</h2> <input type="text" id="result" disabled> <br> <button onclick="appendToResult('1')">1</button> <button onclick="appendToResult('2')">2</button> <button onclick="appendToResult('3')">3</button> <button onclick="appendToResult('+')">+</button> <br> <button onclick="appendToResult('4')">4</button> <button onclick="appendToResult('5')">5</button> <button onclick="appendToResult('6')">6</button> <button onclick="appendToResult('-')">-</button> <br> <button onclick="appendToResult('7')">7</button> <button onclick="appendToResult('8')">8</button> <button onclick="appendToResult('9')">9</button> <button onclick="appendToResult('*')">*</button> <br> <button onclick="appendToResult('0')">0</button> <button onclick="clearResult()">C</button> <button onclick="calculateResult()">=</button> <button onclick="appendToResult('/')">/</button> <script> function appendToResult(value) { document.getElementById('result').value += value; } function clearResult() { document.getElementById('result').value = ''; } function calculateResult() { const resultField = document.getElementById('result'); try { resultField.value = eval(resultField.value); } catch (e) { resultField.value = 'Error'; } } </script> </body> </html> 12.Demonstrate Servlet Lifecyle by implementing Servlet Interface import javax.servlet.*; import java.io.IOException; import java.io.PrintWriter; public class MyServlet implements Servlet { public void init(ServletConfig config) throws ServletException {} public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { PrintWriter out = res.getWriter(); out.println("Hello Servlet Lifecycle!"); } public void destroy() {} public ServletConfig getServletConfig() { return null; } public String getServletInfo() { return null; } } 13.Demonstrate Creation of Servlet program using Http Servlet class. import javax.servlet.*; import javax.servlet.http.*; import java.io.IOException; import java.io.PrintWriter; public class HelloServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello from HttpServlet!"); } } 14.Write a java program to establish a connection to a database and execute simple SQL queries. import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class SimpleDatabaseConnection { public static void main(String[] args) { // Database credentials String url = "jdbc:mysql://localhost:3306/your_database_name"; // Replace 'your_database_name' String user = "root"; // Replace 'root' with your username String password = "your_password"; // Replace 'your_password' // SQL query String query = "SELECT * FROM your_table_name"; // Replace 'your_table_name' // Establish connection and execute query try (Connection conn = DriverManager.getConnection(url, user, password); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query)) { System.out.println("Connected to the database!"); // Process the result set while (rs.next()) { int id = rs.getInt("id"); // Replace 'id' with your column name String name = rs.getString("name"); // Replace 'name' with your column name System.out.println("ID: " + id + ", Name: " + name); } } catch (Exception e) { e.printStackTrace(); } } } 15.Write a java program to demonstrate the usage of JDBC in performing various DML statements using prepared statements. import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class JdbcDmlDemo { public static void main(String[] args) { // Database connection details String url = "jdbc:mysql://localhost:3306/your_database_name"; // Replace with your DB name String user = "root"; // Replace with your DB username String password = "your_password"; // Replace with your DB password // SQL queries String insertQuery = "INSERT INTO users (name, email) VALUES (?, ?)"; String updateQuery = "UPDATE users SET email = ? WHERE id = ?"; String deleteQuery = "DELETE FROM users WHERE id = ?"; try (Connection conn = DriverManager.getConnection(url, user, password)) { System.out.println("Connected to the database!"); // INSERT operation try (PreparedStatement insertStmt = conn.prepareStatement(insertQuery)) { insertStmt.setString(1, "John Doe"); insertStmt.setString(2, "john.doe@example.com"); int rowsInserted = insertStmt.executeUpdate(); System.out.println(rowsInserted + " row(s) inserted."); } // UPDATE operation try (PreparedStatement updateStmt = conn.prepareStatement(updateQuery)) { updateStmt.setString(1, "john.newemail@example.com"); updateStmt.setInt(2, 1); // Assuming user with ID 1 exists int rowsUpdated = updateStmt.executeUpdate(); System.out.println(rowsUpdated + " row(s) updated."); } // DELETE operation try (PreparedStatement deleteStmt = conn.prepareStatement(deleteQuery)) { deleteStmt.setInt(1, 1); // Assuming user with ID 1 exists int rowsDeleted = deleteStmt.executeUpdate(); System.out.println(rowsDeleted + " row(s) deleted."); } } catch (SQLException e) { e.printStackTrace(); } } } 16.Write a java based application to demonstrate the Scrollable Result sets. import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ScrollableResultSetDemo { public static void main(String[] args) { // Database connection details String url = "jdbc:mysql://localhost:3306/your_database_name"; // Replace with your DB name String user = "root"; // Replace with your DB username String password = "your_password"; // Replace with your DB password // SQL query String query = "SELECT * FROM users"; try (Connection conn = DriverManager.getConnection(url, user, password); Statement stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, // Allows scrolling ResultSet.CONCUR_READ_ONLY // Read-only ResultSet ); ResultSet rs = stmt.executeQuery(query)) { System.out.println("Connected to the database!"); // Move to the last row if (rs.last()) { System.out.println("Last Record:"); System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name")); } // Move to the first row if (rs.first()) { System.out.println("\nFirst Record:"); System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name")); } // Move to a specific row (e.g., second row) if (rs.absolute(2)) { System.out.println("\nSecond Record:"); System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name")); } // Iterate backward from the end System.out.println("\nIterating Backward:"); rs.afterLast(); // Move to after the last row while (rs.previous()) { System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name")); } } catch (SQLException e) { e.printStackTrace(); } } } 17.Write a program to accept request parameters from a form and generate the response. <!DOCTYPE html> <html> <head> <title>Form Example</title> </head> <body> <h1>Enter Your Details</h1> <form action="FormHandler" 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> 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; // Map the servlet to a URL @WebServlet("/FormHandler") public class FormHandler extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set the response content type response.setContentType("text/html"); // Retrieve form parameters String name = request.getParameter("name"); String email = request.getParameter("email"); // Generate the response PrintWriter out = response.getWriter(); out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head><title>Form Response</title></head>"); out.println("<body>"); out.println("<h1>Form Submitted Successfully</h1>"); out.println("<p>Name: " + name + "</p>"); out.println("<p>Email: " + email + "</p>"); out.println("</body>"); out.println("</html>"); } } Jdbc folder->settings icon->commad pallete->in search bar java: create project..->no build tools->a window will be opend selcr the option “select project location”->type project name(click enter new window will be opened)->in src folder you’ll have app.java file->rename the file and give the java code here (in app.java)->id run not suitable exception found error(mysql is not connected)->in search “mysql 8.0 command client”->java projects in vs code palette->select reference libraries->this pc,program files*86,my sql foler,connector (select t he jar file)->run the java code
Comments