Nitin Gupta - WT - LABFILE
Nitin Gupta - WT - LABFILE
Internal Assessment
Name – Nitin Gupta
CSE AIML - 6th Sem. (2022-2025)
Roll No.- 2200291539004
1. https://www.hackerrank.com/challenges/java-exception-handling-try-catch/problem
2. https://www.hackerrank.com/challenges/java-exception-handling/problem
3. https://www.hackerrank.com/challenges/java-inheritance-1/problem
4. https://www.hackerrank.com/challenges/java-abstract-class/problem
6. Write a Java program that throws an exception and catch it using a try-catch block.
7. Write a Java program to create a method that takes an integer as a parameter and throws an
exception if the number is odd.
11. Write a servlet program for servlet login and logout using cookies. Perform a
comparative analysis between Session and Cookies.
12. Write a Java program to create a method that reads a file and throws an exception if the file
is not found.
ANSWERS
ANS 1
ANS 2
ANS 3
ANS 4
ANS 11
ANS 12
Lab 1
https://www.geeksforgeeks.org/problems/kth-smallest-
element5635/1?page=1&sortBy=submissions
https://www.geeksforgeeks.org/problems/sum-of-digit-is-pallindrome-or-
not2751/1?itm_source=geeksforgeeks&itm_medium=article&itm_campaign=bottom_sticky_on_ar
ticle
https://www.geeksforgeeks.org/problems/need-some-change/1
https://www.geeksforgeeks.org/problems/rotate-array-by-n-elements-
1587115621/1?page=2&category=Arrays&sortBy=submissions
ANS 1
Ans 2
Ans 3
Ans 4
Lab 2
Write a Java program that throws an exception and catch it using a try-catch block.
Write a Java program to create a method that takes an integer as a parameter and throws an
exception if the number is odd.
Write a Java program to create a method that reads a file and throws an exception if the file is not
found.
Write a Java program that reads a list of integers from the user and throws an exception if any
numbers are duplicates.
Write a Java program to create a method that takes a string as input and throws an exception if the
string does not contain vowels.
Java
try {
} catch (Exception e) {
if (number % 2 != 0) {
} else {
try {
checkEven(3);
checkEven(8);
} catch (ValueError e) {
Java
try {
} catch (FileNotFoundException e) {
}
}
try {
} catch (FileNotFoundException e) {
Java
try {
if (seen.contains(num)) {
} else {
seen.add(num);
} catch (ValueError e) {
} catch (ValueError e) {
5. Vowel check:
Java
try {
boolean hasVowel =
false;
if (vowels.indexOf(ch) != -1) {
hasVowel = true;
break;
if (!hasVowel) {
} else {
} catch (ValueError e) {
}
public static void main(String[] args) {
try {
checkVowels("Hello world!");
checkVowels("hvnmmng");
} catch (ValueError e) {
Lab 4
Problem Statement:
You are tasked with creating a simple online recipe book using HTML, CSS, XML, and JavaScript.
The recipe book should allow users to view recipes, add new recipes, and search for recipes based on
ingredients. Additionally, it should utilize dynamic HTML (DHTML) to enhance user interactions and
AJAX for asynchronous loading of recipe data.
Requirements:
HTML Basics:
Create a webpage layout for the recipe book, including headers, navigation menus, and content areas.
Implement HTML lists to display categories of recipes.
Use HTML tables to organize recipe details such as ingredients and instructions.
Incorporate images to visually represent each recipe.
Utilize frames or iframes to separate different sections of the webpage.
CSS Styling:
Apply CSS styles to HTML elements to improve the visual appearance of the recipe book.
Use CSS to define fonts, colors, margins, padding, and borders for various elements.
Implement CSS selectors to target specific elements for styling.
Ensure responsive design to adapt the layout for different screen sizes.
Implement dynamic effects using JavaScript and CSS, such as hover effects on recipe images or
interactive buttons.
Use JavaScript to dynamically update content on the webpage without reloading the entire page.
Create interactive forms for adding new recipes or searching for recipes by ingredients.
XML Basics:
Define an XML schema for storing recipe data, including elements for recipe name, ingredients,
instructions, etc.
Use XML to represent recipe data in a structured format.
Apply XML namespaces and document type definition (DTD) to ensure data integrity and validation.
Integrate JavaScript to enhance user interactions, such as form validation and event handling.
Use JavaScript to parse and manipulate XML data, dynamically generating HTML content based on
the XML structure.
Implement AJAX requests to asynchronously load additional recipe data when users browse or search
for recipes.
Learning Objectives:
Development Phases:
HTML and CSS:
Page Layout:
Create an HTML document with a clear structure using headers, navigation bar, and
content sections.
Implement HTML lists to categorize recipes (e.g., Appetizers, Main Courses, Desserts).
Use HTML tables to organize recipe details (ingredients with quantities, step-by-step instructions).
Include images for each recipe to enhance visual appeal. (Consider copyright or use free image
sources)
Styling:
Define fonts, colors, margins, padding, and borders for different elements.
Utilize CSS selectors to target specific elements for styling (e.g., headers, lists, tables).
Ensure responsive design to adapt the layout for various screen sizes (mobile, desktop).
XML Schema:
Include elements for recipe name, ingredients (with quantity and unit), instructions (separate
steps), and optional elements like image URL, category, etc.
Recipe Data:
Create XML files with recipe data following the defined schema.
Consider storing these files on the server or locally within the web project structure.
Interactivity:
Implement forms for adding new recipes (using appropriate input fields).
Create a search functionality where users can search recipes by ingredients using a search bar.
XML Parsing:
Utilize JavaScript libraries like DOM (Document Object Model) or third-party libraries to parse the
XML data.
Use JavaScript to dynamically generate HTML content based on the parsed XML data.
For example, populate a list of recipes on the main page or display the details of a specific recipe
when selected.
AJAX:
Implement AJAX requests to load recipe data asynchronously without full page reloads.
This can be used for faster navigation, searching, or loading detailed recipe information when a
user clicks on a recipe.
Additional Considerations:
Implement error handling and validation for user input and data retrieval.
Ensure proper organization of HTML, CSS, JavaScript, and XML files for maintainability.
Structured Data: XML provides a clean and organized way to store recipe data.
Dynamic Updates: JavaScript and AJAX enable user interactions and dynamic content updates
without refreshing.
Separation of Concerns: HTML defines structure, CSS styles the appearance, and JavaScript adds
interactivity, promoting cleaner code.
By combining these technologies, you can create a user-friendly and interactive online recipe book,
offering a dynamic experience for users to explore and manage recipes.
Lab 7
Problem Statement:
You are tasked with developing a simple online student management system using Java Server Pages
(JSP) for dynamic web content generation. The student management system should allow
administrators to view, add, update, and delete student records. Additionally, it should utilize JSP
features such as implicit objects, scripting, standard actions, directives, and custom tag libraries for
efficient web development.
Requirements:
Create JSP pages to serve as the user interface for the student management system.
Understand the lifecycle of a JSP page and its role in generating dynamic content.
Utilize implicit objects such as request, response, session, and application to access and manipulate
HTTP request data.
Implement scripting elements (scriptlets, expressions, and declarations) to embed Java code within JSP
pages.
Use standard actions such as jsp:include, jsp:forward, and jsp:useBean for common tasks like
including other JSP pages, forwarding requests, and managing JavaBeans.
Explore JSP directives such as page, include, and taglib to define page-specific settings and include
external resources.
Define custom tag libraries to encapsulate reusable functionality and simplify complex operations
within JSP pages.
Review all topics covered in the JSP module, including implicit objects, scripting, standard actions,
directives, and custom tag libraries.
Provide guidance and assistance for the final project, where students will develop a complete student
management system using JSP.
Conduct a presentation session where students showcase their projects and receive feedback from peers
and instructors.
This breakdown outlines the development process for a student management system using Java
Server Pages (JSP).
Learning Objectives:
Development Phases:
Create JSP pages for the user interface (UI) with forms for data input.
Understand the JSP lifecycle: request processing, page translation, and response generation.
Leverage implicit objects like request, response, session, and application to access and manipulate
user data submitted through forms.
Scriptlets: Embed Java code blocks for complex logic (<% ... %>).
Declarations: Declare variables within the JSP page (<%! ... %>).
<%@ page ... %>: Set page attributes like content type, error handling.
<%@ include ... %>: Include external files like headers or footers.
<%@ taglib ... %>: Define custom tag libraries for reusability.
Develop custom tag libraries to encapsulate frequently used functionalities, improving code
organization and maintainability.
Develop a complete student management system as a final project, utilizing the learned concepts:
Present your project to peers and instructors for feedback and evaluation.
Problem Statement:
You are tasked with developing a simple online bookstore application using Java Servlets and JDBC for
database connectivity. The bookstore application should allow users to browse books, add them to their
cart, and proceed to checkout. Additionally, it should utilize JDBC to retrieve book data from a
database, handle transactions during checkout, and use servlets for session management.
Requirements:
JDBC Basics:
Establish a database connection using JDBC and retrieve book data from a database table.
Implement SQL queries to merge data from multiple tables using JOIN operations.
Handle transaction processing during checkout, ensuring atomicity and consistency of database
operations.
Utilize stored procedures to encapsulate complex database operations, such as updating inventory levels
after a purchase.
Servlets:
Define servlets to handle different stages of the bookstore application, such as browsing books, adding
to cart, and checkout.
Understand the servlet life cycle and implement methods to handle HTTP requests, such as doGet() and
doPost().
Implement session tracking mechanisms using Cookies and HttpSession to maintain user sessions
across multiple requests.
Lab 5
Here's a breakdown of developing a simple online bookstore application using Java Servlets and
JDBC:
Learning Objectives:
JDBC Basics:
Database Setup:
Create a database (e.g., MySQL) with tables for books (title, author, price, etc.) and potentially
another for user information (optional).
JDBC Connectivity:
Data Retrieval:
Write SQL queries to fetch book data from the database table.
Implement JOIN operations to retrieve data from multiple tables (e.g., join books with categories).
Transactions:
Create stored procedures in the database to encapsulate complex operations like updating
inventory after a purchase.
Servlets:
Servlet Creation:
Understand the servlet lifecycle (init, service, destroy) and implement corresponding methods.
Request Handling:
Implement doGet() and doPost() methods to handle HTTP GET and POST requests from the user.
Session Management:
Utilize HttpSession to maintain user sessions across multiple requests.
Store cart items and user information (if applicable) in the session object.
Consider using cookies as an alternative or in conjunction with sessions for specific scenarios.
Additional Considerations:
Implement security measures to prevent unauthorized access and protect user data.
Design a user-friendly interface (HTML forms, CSS for styling) for user interaction with the
bookstore application.
Error handling should be implemented to gracefully manage potential exceptions during database
operations or user input validation.
Server-side Processing: Servlets allow for robust and secure processing of user requests and
database interactions.
Database Connectivity: JDBC provides a standard way to connect and interact with various
databases.
Scalability: Servlets are scalable and can handle a high volume of users with efficient session
management.
By following these steps and incorporating best practices, you can develop a functional online
bookstore application leveraging Java Servlets and JDBC. Remember, this is a general outline,
and specific implementation details will depend on your chosen database schema, chosen UI
framework, and desired security features.