Assignments - PR 101 - Basic - Java
Assignments - PR 101 - Basic - Java
Assignments for
PR 101 J2EE Foundation Package
Jan 2008
COMPANY CONFIDENTIAL
Infosys Document Revision History
Ver.
Date Author(s) Reviewer(s) Description
Revision
3.1 Jan -2008 Amandeep Thind Rahul Ghali Baseline
Contents
Assignment 1:
Write the Java class CommandArg to accept the two numbers through
command line. Convert the numbers to integer type, perform the addition and print
the result on the screen.(Hint : Use Wrapper classes)
(Approx time : 10 min)
Assignment 2:
Create an applet MyApplet which takes User’s first name and last name from
the html file as parameter and displays it in the applet and the status bar of the
applet as a String.
(Approx time : 10 min)
Assignment 3:
Write a java program to accept a String from command line. Breakup the
above String into a char Array and print them one by one.
(Approx time : 10 min)
Assignment 4:
Create your own exception class. Write a constructor for this class that takes
a String argument and stores it. Write a method that prints out the stored String.
Use try-catch to practice the exception created by your class.
(Approx time : 10 min)
Assignment 5:
Create a class MySuper in a package MySuperpack. Create another class
MySub in another package MySubPackage. MySub overrides a method add() define
in MySuper. MySub should call MySuper’s version of add() and also the overridden
version.(Hint :Use super)
(Approx time : 15 min)
Assignment 5:
Create a JApplet in Swing to create a Course enrollment form with appropriate
components and event handlers.
(Approx time : 25 min)
Assignment 1:
Create a programmer defined thread class by extending the java.land.Thread
class. Override the run() method to print the message “Hello Threads”. Write
another program to create 5 instances of above thread which will run
simultaneously.
(Approx time : 15 min)
Assignment 2:
Write the above program using java.lang.Runnable interface.
(Approx time : 10 min)
Assignment 3:
Modify the above program to print the same message 5 times. Use the
sleep() method to sleep the thread for some time. Try with changing the priority of
the threads.
(Approx time : 10 min)
Assignment 5:
Write the Java program to store following string into BigJava.dat file.
“Welcome to the world of Java Programming”. Use the java.io.FileOutputStream
class for the writing the string.
(Approx time : 20 min)
Assignment 6:
Write another java program to copy the contents of file BigJava.dat to
SmallJava.dat file. Use java.io.FileInputStream class to perform the copy.
(Approx time : 10 min)
Assignment 7:
Modify the above assignment such that input and output operations are
performed with buffering using BufferedInputStream and BufferedOutputStream.
(Approx time : 10 min)
Assignment 8:
To write a program that read several types of information from files: binary,
Java objects, text, zipped files, etc.
HINT : Read text files using the classes FileReader, BufferedReader, FileWriter, and
BufferedWriter. It is without a graphical user interface, taking parameters from the
command line.
(Approx time : 15 min)
Assignment 9:
To write a program that uses BufferedReaderStream and its readLine()
method to count the number of white space characters in the input.
Database : For assignment no. 10 to 12, create a table Employee having the
following fields EmpID, EmpName and Age. Make the EmpID field as a sequence.
Insert valid data into the table like
Assignment 10:
To write a program to insert data into a table using java.sql.Statement
interface.
HINT: executeUpdate() method returns an int as to how many rows got affected.So if
the return value is 0 it indicates that insertion failed.
(Approx time : 20 min)
Assignment 11:
To write a program to insert data into a table using PreparedStatement.
Constraints
• The column names which have been underlined are the primary keys for the
tables.
• Employees can belong to only one section
• Customers can be of two types Regular and Ad-hoc
• Maximum credit limit allowed is Rs. 10000.
• Quantity of goods supplied cannot be less than 0 and cannot be greater than
10000 for a particular supply.
Description
• A department store has many sections such as Toys, Cosmetics, Clothing,
Household Items, Electronics etc.
• Each section has many employees
• Each section also has a head who is responsible for the section’s performance.
• The department store also has many customer who purchase goods from
various sections
2. Create the tables with all appropriate constraints. Use the constraints
UNIQUE, NOT NULL, CHECK , PRIMARY KEY, FOREIGN KEY etc.
wherever necessary. Add the tables Suppliers and Supliers_Products to
the cluster Supp_Product. Create an index on the cluster
Supp_Product.
4. Add data to the master tables and then to the other tables using
INSERT INTO statements.
5. Add at least 2 rows in each of the master tables, and 5 rows in the
other tables. While inserting into the product table use
Seq_Product.
7. Find all employees whose names begin with ‘A’ and end with ‘A’.
10. Display the section names and the names of the employees who
belong to that section.
11. Display the section name and the name of the person who heads the
section.
12. Display supplier names and cities. If the city is null, display ‘LOCAL’.
Use the NVL function for this.
13. Display the customer names and the customer type. If the customer
type is ‘R’ display ‘Regular’ , if the customer type is ‘A’ display ‘Ad-
hoc’. Use the DECODE function for this.
14. Try creating a view which when used, will display the supplier names,
product names , the quantity supplied and the date supplied for all
records in Supp_Products. The listing should be in alphabetical order of
supplier names.
17. List all suppliers who have not supplied any products. Use an outer
join to do this.
19. Display the customer no and the total number of products purchased
by him, for those customers who have purchased at least 2 or more
different products. Sort the listing in ascending order of customer
number.
20. Display the customer name and product names which have been
purchased by him. The customer and product names should be in
upper case.
21. Display the products that have been supplied more than a month ago.
22. Display employee names and the date joined for employees. Date
should be in the format ‘DD-MMM-YYYY’.
23. Display employee names and the number of months between today’s
date and the joining date.
24. Display product names and the price rounded to the nearest integer.
25. Find the product which has the greatest price in each category.
26. Write a PL/SQL block of code which will let you insert a record into the
Section table. Use variables to represent the values of section_no,
description and section_head_empno. Use anchored declarations for
these variables. What happens if you try to insert a value of
section_no which already exists in the section table?
27. Write a PL/SQL anonymous block which will insert 50 records into
test_table. Insert the current date value into the table. (Use SYSDATE
to get the system date). [To see the value of SYSDATE type the
following at the SQL Prompt: SELECT SYSDATE FROM DUAL;]. (create
a table called test_table, with 2 columns RecordNumber (type:
Number(3)) and CurrentDate(type: Date)).
29. At the SQL prompt, issue a ROLLBACK. Try displaying the records in
test_table. Can you see all the records? If not, how can you make sure
that the changes made by the block are permanent?
31. Write a PL/SQL anonymous block, which will display the product no ,
product_category code, product category description, product
description , price and quantity on hand of all products which have a
quantity_on_hand of 1000 or more. Use a cursor to obtain the values
from the tables. Use a LOOP…END LOOP to fetch the rows from the
cursor. Remember to give an EXIT WHEN condition in the loop. Display
the row number of each record as it is fetched (Hint: use
%ROWCOUNT for this)
32. Write a PL/SQL anonymous block which will increase the price of all
products by 10%, for those products which are in the product category
‘Cosmetics’. Use a FOR..UPDATE clause with the cursor declaration for
this.
34. Write a PL/SQL anonymous block which will retreive customer names
and assign the concatenated name(first_name + last_name) to a
PL/SQL table. Display the names from the PL/SQL table.
35. For each of the above blocks of code, add the appropriate exception
handlers. If you do not know of the exception which may occur, print
the sql error code and error message when an unknown exception
occurs.