0% found this document useful (0 votes)
19 views

Procedures Advance Java

Uploaded by

Kesavan Kesavan
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)
19 views

Procedures Advance Java

Uploaded by

Kesavan Kesavan
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/ 9

1.

classes and objects


Aim: to write a Java program for classes and objects
Procedure
Step 1 start the process
Step 2 import the necessary packages
Step 3 define the class ‘box’ with instance variable width, height, and depth and create
constructor for initialising the box with given dimensions
Step 4 define the method ‘volume’ to calculate and return the volume of the ‘box ‘
Step 5 define main class main and get the input using scanner function.
Step 6 Print the volume of the ‘box’.
Steps 7 Stop the process.
Result
thus, the program using classes and objects has been executed successfully and output
verified.

2. Implementing classes
Aim to write a Java program for implementing classes
Procedure
Step 1 start the process
Step 2 import the necessary packages
Step 3 define a class ‘overloading’ with instance variables square, rect, and circle.
Step 4 define methods to calculate area of square rectangle and circle
Step 5 define the main class main and the read input using scanner function
Step 6 print the area of square, rectangle, and circle.
Step 7 stop the process
Result
thus, the program to implement classes has been executed successfully and output verified

3. Strings
Aim to write a Java program to implement string and string buffer methods
Procedure
Step 1 start the process
Step 2 import necessary packages
Step 3 define a class ‘example’ to implement string and string buffer methods such as
charAt(),getchars(),regionmatches(), startswith(), endswith(), touppercase(), tolowercase(),
length(), reverse(), replace(), insert(), substring() and append ().
Step 4 print the results of string and string buffer methods
Step 5 stop the process
Result
thus, the various methods in string and string buffer classes has been executed successfully
and the output verified

4. Collections
Aim to write a Java program to implement collection classes
Procedure
Step 1 start the process
Step 2 import necessary packages
Step 3 define a class ‘collections’ to implement collection classes
Step 4 create an array and convert the array into array list using aslist() method
Step 5 create and linked list and compare with array list to see if both having a same
minimum value Step 6 convert the arraylist into into array using toarray() method and find
total and average for that array
Step 7 create treeset and hashset and print them
Step 8 stop the process
Result
thus, the program collections has been executed successfully and the output verified

5. Date and calendar


Aim to write a Java program to implement methods in date and calendar classes
Procedure
Step 1 start the program
Step 2 import the necessary packages
Step 3 define a class date and calendar and use date class to print current date and time and
implement after(), before(), compareTo() and equals date class methods
Step 4 Create calendar class object to print current date and time as well
Step 5 stop the process
Result thus, the program using date and calendar classes has been executed successfully and
output verified

6. Packages
Aim to write a Java program to implement packages
Procedure
Step 1 start the process
Step 2 define package named ‘mypackage’
Step 3 in the package create a class ‘customer’ and define methods show(), deposit(), and
withdrawal().
Step 4 create a class ‘package’ and import the package ‘mypackage’ to access the ‘customer’
class properties
Step 5 print the results
Step 6 Stop the process.
Result thus the program using packages has been executed successfully and the output
verified

7. Exception handling
Aim to write a java program to implement exception handling
Procedure
Step 1 start the process
Step 2 import necessary packages
Step 3 Create a class ‘exception’ to implement exception handling
Step 4 use try catch blocked to handle the arithmetic, arrayIndexOutOfBounce,
negativeArraySize exceptions
Step 5 stop the process
Result
thus, the various exceptions are handled successfully and output verified

8.threads
Aim to write a Java program to implement threads
Procedure
Step 1 start the process
Step 2 import the necessary packages
Step 3 Create the ‘Any’ class with variables n, valueSet, count, max
to manage shared data between the producer and consumer threads.
Step 3 Implement synchronized get() and put() methods in the Any class for inter-thread
communication.
Step 4 Create two classes named ‘producer’ and ‘consumer’ and create a thread for each
class.
Step 5 Get the input of the maximum number of items to be produced and consumed using a
Scanner function.
Step 6 Start both the Producer and Consumer threads by creating instances of the respective
classes and passing the Any object.
Step 7 The producer will produce values, and the consumer will consume them in
synchronization, with proper inter-thread communication using wait() and notify() methods.
Step 8 Stop the process.
Result thus, the thread concept has been executed successfully and output verified

9. JDBC (Java Database Connectivity)


Aim To write a Java program to implement jdbc(Java database connectivity).
Procedure
Step 1 start the process
Step 2 created database in mySQL, create a table student1 with attributes of ID, name, and
dept and insert values.
Step 3 import necessary packages
Step 4 create a class ‘db’ and load mySQL driver
Step 5 Establish the connection with database and execute queries
Step 6 print the results and disconnect the mySQL database connection
Step 7 stop the process
Result thus the jdbc has been executor successfully and output verified

10 . Applets
Aim to write a Java program to implement applet class.
Procedure
Step 1 start the process
Step 2 import the necessary packages
Step 3 add applet tag with the needed dimensions
Step 4 create a class simple banner that extend applet class
Step 5 initialise the applet window with the colour dimensions
Step 6 start the applet and run to display a moving text in the window
Step 7 stop the applet
Step 8 stop the process
Result
thus , the applet program has been executed successfully and output verified

11. Event handling


Aim to write a Java program to implement even handling
Procedure
Step 1 start the process
Step 2 Import necessary libraries
Step 3 define a class ‘text’ that extends applet class and implement the action listener
interface
Step 4 add two text fields and a button in the window
Step 5 define a method action performed to calculate the sum of two numbers entered in the
text field
Step 6 print the results
Step 7 stop the applet
Step 8 stop the process
Result
thus, the even handling concept has been executed successfully and output verified

12. Simple web applications.


Aim: To write a Servlet program to develop a simple web application.
Step 1: Start the process.
Step 2: Import necessary packages.
Step 3: Create the class ‘VoteServlet’ that extends HttpServlet and Override the doPost()
method to handle the POST request from the form.
Step 4: Create the HTML form ‘index’ with fields for Name and Age and Use the POST
method to submit the form data to the servlet class ‘VoteServlet’.
Step 4: Retrieve form data using request.getParameter().
Step 5: Check if the age is less than 18.
If true, display that the person is not eligible to vote.
If false, display that the person is eligible to vote.
Step 6: Print the result inside an HTML structure using out.println().
Step 7: Stop the process.
Result
Thus, the simple web application has been executed successfully and output verified.

13. Using sessions and cookies


Aim: To write a Servlet program to implement sessions and cookies.
Procedure:
Step 1: Start the process.
Step 2: Import necessary packages.
Step 3: Create the servlet class ‘LoginServlet’ that extends HttpServlet and override the
doPost() method to handle the POST request from the form.
Step 4: Create the HTML form ‘index’ with a field for Name and use the POST method to
submit the form data to ‘LoginServlet’ class.
Step 5: Retrieve form data using request.getParameter().
Step 6: Create a session and store the username, then create a cookie for the username.
Step 7: Create the servlet class ‘WelcomeServlet’ and retrieve the username from the session
or cookie.
Step 8: If the username is found, display a welcome message; if not, show an error and link to
the login page.
Step 9: Print the result inside an HTML structure using out.println().
Step 10: Stop the process.
Result
Thus, the program using session and cookies has been executed successfully and output
verified.

14. Forwarding requests and redirecting responses.


Aim: To write a Servlet program to implement request forwarding and response redirection in
a web application using servlets.
Procedure:
Step 1: Start the process.
Step 2: Import necessary packages.
Step 3: Create the HTML form ‘Homepage’with fields for Name and Age. Use the POST
method to submit the form data to ‘NewServlet’ class.
Step 4: Create the servlet class ‘NewServlet’ that extends HttpServlet, and override doPost()
and doGet() methods to handle the form submission.
Step 5: In NewServlet, retrieve the form data using request.getParameter().
Step 6: Check if the age is 18 or older:
If true, forward the request to ‘Welcome’ class using RequestDispatcher, passing the
username as an attribute.
If false, redirect the user to ‘Error’ html.
Step 7: Create the HTML page ‘Error’ to display the message that the user is not eligible to
vote. Include a link to return to HTML ‘Homepage’.
Step 8: Create the servlet class ‘Welcome’ that extends HttpServlet, and If the user is eligible,
display the welcome message in the processRequest() method.
Step 9: Stop the process.
Result
Thus, the program for forwarding requesting and redirecting responses has been executed
successfully and output verified.

15. Web application using database.


Aim: To write a Servlet program to develop a Web Application using Database.
Procedure:
Step 1: Start the process.
Step 2: Import necessary packages.
Step 3: Create the HTML form ‘Home’ with fields for Username and Password. Use the
POST method to submit the form data to ‘LoginServlet’ class.
Step 4: Create the ‘DatabaseConnection’ class to handle database connection using
DriverManager.getConnection(). Set the database URL, username, and password. Load the
JDBC driver using Class.forName().
Step 5: Create the servlet class ‘LoginServlet’, override the doPost() method to handle form
submission. Retrieve the username and password from the form using request.getParameter().
Step 7: Establish a database connection using the DatabaseConnection.initializeDatabase()
method.
Step 8: Use a SQL query to verify if the username and password exist in the database.
Step 9: Execute the query and check if the user exists
If the credentials are valid, display a Success message.
If invalid, display an error message.
Step 11: Stop the process.
Result
Thus, the web application using database has been executed successfully and output verified.

16. Developing simple beans.


Aim: To write a Java program for developing simple beans
Procedure:
Step 1: Start the process.
Step 2: Declare the package named ‘student’.
Step 3: Inside the ‘student’ package define the ‘Student’ class with two variables name and
id.
Step 4: Create a default constructor ‘Student()’ that initializes an empty Student object.
Step 5: Define a getter methods getName() and getid() to retrieve the value of the name and
id variables.
Step 6: Define a setter methods setName() and setid()to update the name and id variables.
Step 7: In the ‘Teststudent’ java file, Import the student package to access the ‘Student’ class.
Step 8: Define the ‘Teststudent’ class with a main method.
Step 9: Create an object ‘s1’ of the Student class and Use the setName(), setid() methods to
assign the name and id values.
Step 10: Print the name and id of the student by calling the getName() and getid() methods.
Step 11: Stop the process.
Result
thus, the simple bean program has been executed successfully and output verified.

17. Use Beans with JSP tags


Aim: To write a Servlet program to implement JavaBeans and access the bean properties
using JSP.
Procedure:
Step 1: Start the process.
Step 2: Declare the package named ‘student’.
Step 3: Inside the ‘student’ package define the ‘Student’ class with two variables name and
id.
Step 4: Create a default constructor ‘Student()’ that initializes an empty Student object.
Step 5: Define a getter methods getName() and getid() to retrieve the value of the name and
id variables.
Step 6: Define a setter methods setName() and setid() to update the name and id variables.
Step 7: In the ‘beanJSP’ JSP file, Import the student package to access the ‘Student’ class
Step 8: Inside the JSP scriptlet, create an instance of the ‘Student’ class and use the setter
methods to assign values to name and id.
Step 9: Set the student object as an attribute in the request using request.setAttribute().
Step 10: Access the name and id fields of the student object and display them inside the
HTML structure.
Step 11: Stop the process.
Result thus, the program beans with JSP tags has been executed successfully and output
verified.

You might also like