Skip to content

Commit 96f8944

Browse files
Update README.md
1 parent 7b2f68c commit 96f8944

File tree

1 file changed

+221
-1
lines changed

1 file changed

+221
-1
lines changed

README.md

Lines changed: 221 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,221 @@
1-
# Java-Lab-Work
1+
# **Java Lab Work - UPES**
2+
3+
This respository contains all the assignments that I have performed in my Java lab.
4+
5+
## **Experiment 1 : Basics of Java**
6+
7+
1. Write program to print the kth digit from last. e.g. input 23617 and k=4 output 3.
8+
2. Write a program to print first digit. e.g. input 23516 output 2.
9+
3. Write program to print the second digit. e.g. input 23516 the output is 3.
10+
4. Write program to find sum of all digits. Input 23617 output 2+3+6+1+7=19.
11+
5. Write program, which will find sum of product to consecutive digits. e.g. when the input is 23145 the output is 2x3 + 3x1 + 1x4 + 4x5 = 33.
12+
6. Write program, which reads two number (assume that both have same number of digits). The program outputs the sum of product of corresponding digits. Input 327 and 539 output 3x5+2x3+7x9=84.
13+
7. Write program to print positional values of digits. Input 21463 output 3, 60, 400, 1000 and 20000.
14+
8. Modify first example for taking input through command line arguments.
15+
9. Modify second example for taking input through command line arguments.
16+
10. Define fa. If point p is (x,y) then p.fa() will make it (x+y,2y). (20,4) (24,8)
17+
11. Define fb. If point p is (x,y) then p.fb() will make it (2x,x+y). (20,4) (40,24)Define fc. If point p is (x,y) then p.fc() will make it (x+y,x*y). (20,4) (24,80)
18+
19+
## **Experiment 2 : Basics of Java Programming**
20+
21+
1. Write a program to find the largest of 3 numbers.
22+
2. Write a program to implement a command line calculator. (Try for Add sub Mul Division in same program for 2 digits.)
23+
Integer.parseInt will be used<br>
24+
For e.g. java calc 20 + 30<br>
25+
Output should be Sum of 20 and 30 is 50
26+
java calc 50 * 30<br>
27+
Output should be Product of 50 and 30 is 1500
28+
3. Write a program to accept 10 student's mark in an array, arrange it into ascending order, convert it into the following grades and print marks and grades in the tabular form.<br>
29+
Between 40 and 50 : PASS<br>
30+
Between 51 and 75 : MERIT<br>
31+
and above : DISTINCTION<br>
32+
for example:<br>
33+
Enter Marks: 50<br>
34+
30<br>
35+
50<br>
36+
50<br>
37+
30<br>
38+
50<br>
39+
Output should be sorted array with Grade like:<br>
40+
55 Merit<br>
41+
41 Pass<br>
42+
29 Fail<br>
43+
4. WAP to Take input as DD MM YYYY(04 08 2021) in command line and calculate number of days since 1 January 1970.
44+
45+
## **Experiment 3 :**
46+
47+
1. Write a program to accept three digits (i.e., 0 - 9) and print all its possible combinations.<br>
48+
(For example if the three digits are 1, 2, 3 than all possible combinations are : 123, 132,
49+
213, 231, 312, 321.)
50+
2. Write a Java Program to accept 10 numbers in an array and compute the square of each number. Print the sum of these numbers.
51+
3. Write a program to input a number of a month (1 - 12) and print its equivalent name of
52+
the month. ( e.g 1 to Jan, 2 to Feb. 12 to Dec.)
53+
4. Write a program to find the sum of all integers greater than 40 and less than 250 that are divisible by 5.
54+
55+
## **Experiment 4 : Inheritance**
56+
57+
1. Write a Java program to show that private member of a super class cannot be accessed from derived classes.
58+
2. Write a program in Java to create a Player class. Inherit the classes Cricket _Player, Football _Player and Hockey_ Player from Player
59+
class.
60+
3. Write a class Worker and derive classes DailyWorker and SalariedWorker from it. Every worker has a name and a salary rate. Write
61+
method ComPay (int hours) to compute the week pay of every worker. A Daily Worker is paid on the basis of the number of days
62+
he/she works. The Salaried Worker gets paid the wage for 40 hours a week no matter what the actual hours are. Test this program to
63+
calculate the pay of workers. You are expected to use the concept of polymorphism to write this program.
64+
4. Consider the trunk calls of a telephone exchange. A trunk call can be ordinary, urgent or lightning. The charges depend on the duration
65+
and the type of the call. Write a program using the concept of polymorphism in Java to calculate the charges.
66+
5. Design a class employee of an organization. An employee has a name, empid, and salary. Write the default constructor, a constructor
67+
with parameters (name, empid, and salary) and methods to return name and salary. Also write a method increaseSalary that raises the
68+
employee’s salary by a certain user specified percentage. Derive a subclass Manager from employee. Add an instance variable named
69+
department to the manager class. Supply a test program that uses theses classes and methods
70+
71+
## **Experiment 5 : Interface**
72+
73+
1. Write a program to create interface named test. In this interface the member function is square. Implement this interface in arithmetic
74+
class. Create one new class called ToTestInt. In this class use the object of arithmetic class.
75+
2. Write a program to create interface A, in this interface we have two method meth1 and meth2. Implements this interface in another
76+
class named MyClass.
77+
3. Write a program in Java to show the usefulness of Interfaces as a place to keep constant value of the program
78+
4. Write a program to create an Interface having two methods division and modules. Create a class, which overrides these methods.
79+
5. Write program to create an interface StackInterface having methods push (), pop () and display (). StackClass implements
80+
StackInterface. Class StackClass contains the main method which is having a switch case for selecting the particular operation of the
81+
stack
82+
83+
## **Experiment 6 : Packages**
84+
85+
1. Write a Java program to implement the concept of importing classes from user defined package and created packages.
86+
2. Write a program to make a package Balance. This has an Account class with Display_Balance method. Import Balance package in
87+
another program to access Display_Balance method of Account class.
88+
3. WAP to create a package p with class A with 4 types of access protected methods. How we will use these methods in different packages
89+
class i.e. there is main() in class B in package Q and 4 methods are in Class A in package p.
90+
91+
## **Experiment 7 : Exceptions**
92+
93+
1. Write a program in Java to display the names and roll numbers of students. Initialize respective array variables for 10 students. Handle
94+
ArrayIndexOutOfBoundsExeption, so that any such problem doesn’t cause illegal termination of program.
95+
2. Create an exception class, which throws an exception if operand is nonnumeric in calculating modules. (Use command line arguments).
96+
3. Write a code to create your own exception class. Create another class, inside main method prompt user to enter a number if number is
97+
less than 500 throw instances of your custom exception class.
98+
4. You are given two integers, a and b as input, you have to compute a/b: If a and b are not bit signed integers or if is zero, exception
99+
will occur and you have to report it. Read sample Input/Output to know what to report in case of exception. <br>
100+
Sample Input 0:<br>
101+
10<br>
102+
3<br>
103+
Sample Output 0: <br>
104+
3<br>
105+
Sample Input 1:<br>
106+
10<br>
107+
Hello<br>
108+
Sample Output 1 :<br>
109+
java.util.InputMismatchException<br>
110+
Sample Input 2:<br>
111+
10<br>
112+
0<br>
113+
Sample Output 2:<br>
114+
java.lang.ArithmeticException: / by zero<br>
115+
Sample Input 3:<br>
116+
23.323<br>
117+
0<br>
118+
Sample Output 3:<br>
119+
java.util.InputMismatchException<br>
120+
121+
5. You are required to compute the power of a number by implementing a calculator. Create a class Calc which consists of a single
122+
method long power(int, int). This method takes two integers, a and b, as parameters and finds a
123+
b
124+
. If either a or b is negative, then
125+
the method must throw an exception which says "a and b should not be negative". Also, if both a and b are zero, then the method
126+
must throw an exception which says "a and b should not be zero"<br>
127+
For example, -4 and -5 would result in java.lang.Exception: a and b should not be negative.<br>
128+
Complete the function power in class Calc and return the appropriate result after the power operation or an appropriate exception as
129+
detailed above.<br>
130+
<b>Input Format</b><br>
131+
Each line of the input contains two integers, a and b. The code must read the input and send the values to the method as
132+
parameters.<br>
133+
Constraints<br>
134+
* -10 <= a<= 10<br>
135+
* -10 <= b<= 10<br>
136+
137+
<b>Output Format</b><br>
138+
Each line of the output contains the result, if both a and b are positive. If either a or b is negative, the output contains "a and b
139+
should be non-negative". If both a and b are zero, the output contains "a and b should not be zero."<br>
140+
<b>Sample Input 0 :</b><br>
141+
3 5<br>
142+
2 4<br>
143+
0 0<br>
144+
-1 -2<br>
145+
-1 3<br>
146+
<b>Sample Output 0 :</b><br>
147+
243<br>
148+
16<br>
149+
java.lang.Exception: n and p should not be zero.<br>
150+
java.lang.Exception: n or p should not be negative.<br>
151+
java.lang.Exception: n or p should not be negative<br>
152+
153+
## **Experiment 8 : String Handling and Exceptions**
154+
155+
1. Write a program for searching strings for the first occurrence of a character or substring and for the last occurrence of a character or
156+
substring.
157+
2. Write a program that converts all characters of a string in capital letters. (Use StringBuffer to store a string). Don’t use inbuilt function.
158+
3. Write a program in Java to read a statement from console, convert it into upper case and again print on console. (Don’t use inbuilt
159+
function)
160+
4. Write a program in Java to create a String object. Initialize this object with your name. Find the length of your name using the
161+
appropriate String method. Find whether the character ‘a’ is in your name or not; if yes find the number of times ‘a’ appears in your
162+
name. Print locations of occurrences of ‘a’ .Try the same for different String objects
163+
164+
5. Write a Java code that converts int to Integer, converts Integer to String, converts String to int, converts int to String, converts String
165+
to Integer converts Integer to int.
166+
6. Write a Java code that converts float to Float converts Float to String converts String to float converts float to String converts String
167+
to Float converts Float to float.
168+
169+
## **Experiment 9 : Threads**
170+
171+
1. Write a program to implement the concept of threading by extending Thread Class and Runnable interface.
172+
2. Write a program for generating 2 threads, one for printing even numbers and the other for printing odd numbers.
173+
3. Write a program to launch 10 threads. Each thread increments a counter variable. Run the program with synchronization.
174+
4. Write a Java program to create five threads with different priorities. Send two threads of the highest priority to sleep state. Check the
175+
aliveness of the threads and mark which thread is long lasting
176+
177+
## **Experiment 10 : Collections**
178+
179+
1. Write a program for the following<br>
180+
* Read all elements from ArrayList by using Iterator.
181+
* Create duplicate object of an ArrayList instance.
182+
* Reverse ArrayList content.
183+
2. Write a program for the following HashMap
184+
* find whether specified key exists or not.
185+
* find whether specified value exists or not
186+
* get all keys from the given HashMap
187+
* get all key-value pair as Entry objects
188+
3. Write a program for the following HashSet
189+
* copy another collection object to HashSet object.
190+
* delete all entries at one call from HashSet
191+
* search user defined objects from HashSet<br>
192+
193+
## **Experiment 11 : JDBC**
194+
195+
1. Create a database table to store the records of employee in a company. Use getConnection function to connect the database. The
196+
statement object uses executeUpdate function to create a table.
197+
2. Create a database of employee of company in mysql and then use java program to access the database for inserting information of
198+
employees in database. The SQL statement can be used to view the details of the data of employees in the database.
199+
3. Create a table Meeting having columns (NameOfParticipant, MeetingID, ScheduledTime, Email, Mobile), Populate with random data
200+
and perform following operations. READ COMPLETE QUESTION TO POPULATE DATABASE.<br>
201+
a) Using JaveCode determine the names of the columns in the MEETING table and display the column names on the console.<br>
202+
b) Write a query to find the names of all participants for the meeting with ID 1144. Display the names on the console, preceded by
203+
the message, “Names of participants in meeting 1144”.<br>
204+
c) Insert a new participant with using only the participant’s name. Don’t specify the participant ID - let the ID be determined by the
205+
database. Determine the ID that was assigned to the new participant and display it on the console (the statement that displays the
206+
ID should display the name of the new participant as well).<br>
207+
d) Count the number of people participating in the meeting with ID 1105. Display a message on the console that gives both the
208+
meeting name and the number of participants.<br>
209+
e) Determine the names of all people who participate in meetings that meet on Tuesdays. Display the names, preceded by the
210+
message, “Participants attending Tuesday meetings”.<br>
211+
212+
## **Experiment 12 : Servlet**
213+
214+
1. Servlet : <br>a) ServletContext interface<br> b) getParameterValues() of Servlet Request<br>
215+
2) Write a Servlet page to display current date of the server.<br>
216+
3) Write a Servlet page to which include the two other Servlet page through of include directives feature provided in Servlet.
217+
4) Write a Servlet page to create a simple calculator.
218+
219+
220+
221+

0 commit comments

Comments
 (0)