Difference between revisions of "Summer 2022: Programming in Java Lab"

From MKWiki
Jump to navigation Jump to search
 
(36 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
==''' Resources'''==
 
==''' Resources'''==
 
*  [http://www.mkbhandari.com/mkwiki/Summer_2021:_Programming_in_Java_Lab Summer 2021 wiki page]
 
*  [http://www.mkbhandari.com/mkwiki/Summer_2021:_Programming_in_Java_Lab Summer 2021 wiki page]
 +
*  [http://www.mkbhandari.com/mkwiki/Spring_2020:_Programming_in_Java_Lab Spring 2020 wiki page]
 
* Basic building blocks(syntax) [https://introcs.cs.princeton.edu/java/11cheatsheet/ tutorial] from cs.princeton.edu
 
* Basic building blocks(syntax) [https://introcs.cs.princeton.edu/java/11cheatsheet/ tutorial] from cs.princeton.edu
  
Line 52: Line 53:
 
b) Multiply two complex numbers. <br>
 
b) Multiply two complex numbers. <br>
 
c) toString() method to display complex numbers in the form: x + i y.
 
c) toString() method to display complex numbers in the form: x + i y.
| style="width: 15%" | Lab Exercise No. 1 || Read about toString( ) from javatpoint.com [https://www.javatpoint.com/understanding-toString()-method]
+
| style="width: 15%" | '''Lab Exercise No. 1''' || Read about toString( ) from javatpoint.com [https://www.javatpoint.com/understanding-toString()-method]
 
|-
 
|-
| 2 || WAPJava program to read data of various types using Scanner class || Practice Set No. 1 ||  Read about Scanner class from javatpoint.com [https://www.javatpoint.com/Scanner-class]
+
| 2 || WAP to read data of various types using Scanner class || Practice Set No. 1 ||  Read about Scanner class from javatpoint.com [https://www.javatpoint.com/Scanner-class]
 
|-
 
|-
 
| 3 || WAP to find the n<sup>th</sup> largest number and n<sup>th</sup> samallest number in an array || Practice Set No. 2 ||
 
| 3 || WAP to find the n<sup>th</sup> largest number and n<sup>th</sup> samallest number in an array || Practice Set No. 2 ||
Line 61: Line 62:
 
|}
 
|}
  
'''Lab 1b:''' ( week of 16<sup>th</sup> May 2022 ) - completing all the previous programs.
+
'''Lab 1b:''' ( week of 16<sup>th</sup> May 2022 ) - complete all the previous programs.
  
 
== '''Lab 2:''' ( week of 23<sup>rd</sup> May 2022 ) ==
 
== '''Lab 2:''' ( week of 23<sup>rd</sup> May 2022 ) ==
Line 110: Line 111:
 
|| Practice Set No. 2 || Read about strings in Java from javatpoint.com [https://www.javatpoint.com/java-string]
 
|| Practice Set No. 2 || Read about strings in Java from javatpoint.com [https://www.javatpoint.com/java-string]
 
|-
 
|-
| 3 || WAP to demonstrate the Variable Argument (Varargs) in Java|| Practice Set No. 3 || Read about Varargs in Java from  <br> (1) GFG [https://www.geeksforgeeks.org/variable-arguments-varargs-in-java/]  <br>  (2) javatpoint.com [https://www.javatpoint.com/varargs]
+
| 3 || WAP to demonstrate the Variable Argument (Varargs) in Java|| Practice Set No. 3 || Read about Varargs in Java from: <br> (1) GFG [https://www.geeksforgeeks.org/variable-arguments-varargs-in-java/]  <br>  (2) javatpoint.com [https://www.javatpoint.com/varargs]
 +
|}
 +
 
 +
== '''Lab 4:''' ( week of 06<sup>th</sup> June 2022 ) ==
 +
{| class="wikitable" style="text-align: left; width: 100%";
 +
|-
 +
! Q. NO. 
 +
! Program 
 +
! Lab Exercise No. 
 +
! Remarks
 +
|-
 +
| style="width: 8%"  | 1
 +
| style="width: 60%" | WAP to demostrate the single inheritance concept  (chapter 8 ppt.,  slide no. 7-8)
 +
| style="width: 15%" | Practice Set No. 1 ||
 +
|-
 +
| 2 || WAP to demonstrate Member Access and Inheritance (chapter 8 ppt.,  slide no. 10)
 +
|| Practice Set No. 2 ||
 +
|-
 +
| 3 || WAP to demonstrate the single inheritance using Box and BoxWeight example  (chapter 8 ppt.,  slide no. 11-12)  || Practice Set No. 3 ||
 +
|-
 +
| 4 || WAP to demonstrate how A Superclass Variable Can Reference a Subclass Object  (chapter 8 ppt.,  slide no. 15)  || Practice Set No. 4 ||
 +
|-
 +
| 5 || WAP to demonstrate how to use Super to Call Superclass Constructors - A complete implementation of BoxWeight. (chapter 8 ppt.,  slide no. 21-24)  || Practice Set No. 5 ||
 +
|-
 +
| 6 || WAP to demonstrate Using Super to access member of Superclass. (chapter 8 ppt.,  slide no. 28)  || Practice Set No. 5 ||
 +
|}
 +
 
 +
== '''Lab 5:''' ( week of 13<sup>th</sup> June 2022 ) ==
 +
{| class="wikitable" style="text-align: left; width: 100%";
 +
|-
 +
! Q. NO. 
 +
! Program 
 +
! Lab Exercise No. 
 +
! Remarks
 +
|-
 +
| style="width: 8%"  | 1
 +
| style="width: 60%" | Create a class TwoDim which contains private members as x and y coordinates in package P1. Define the default constructor, a parameterized constructor and override toString() method to display the co-ordinates. Now reuse this class and in package P2 create another class ThreeDim, adding a new dimension as z as its private member. Define the constructors for the subclass and override toString() method in the subclass also. Write appropriate methods to show dynamic method dispatch. The main() function should be in a package P.
 +
| style="width: 15%" | '''Lab Exercise No. 2''' ||  Read about packages in java from javatpoint.com [https://www.javatpoint.com/package] 
 +
|-
 +
| 2 || WAP to demonstrate Multi-level hierarchy in Inheritance|| Practice Set No. 1 ||
 +
|-
 +
| 3 || WAP to demonstrate the use of Dynamic Method Dispatch ( slide no. 48, ppt no. 6)  || Practice Set No. 2 ||
 +
|-
 +
|4 || WAP to demonstrate the use of Abstract classes (slide no. 58, ppt no. 6) || Practice Set No. 3 ||
 +
|}
 +
 
 +
== '''Lab 6:''' ( week of 20<sup>th</sup> June 2022 ) ==
 +
{| class="wikitable" style="text-align: left; width: 100%";
 +
|-
 +
! Q. NO. 
 +
! Program 
 +
! Lab Exercise No. 
 +
! Remarks
 +
|-
 +
| style="width: 8%"  | 1
 +
| style="width: 60%" | Define an abstract class Shape in package P1. Inherit two more classes: Rectangle in package P2 and Circle in package P3. Write a program to ask the user for the type of shape and then using the concept of dynamic method dispatch, display the area of the appropriate subclass. Also write appropriate methods to read the data. The main() function should not be in any package.
 +
| style="width: 15%" | '''Lab Exercise No. 3''' ||  Read about Inheritance from javatpoint [http://www.javatpoint.com/inheritance-in-java] <br> Read about Abstract class from javatpoint.com [https://www.javatpoint.com/abstract-class-in-java]
 +
|-
 +
| 2 || WAP to demonstrate the concept of interfaces  (slides no. 25-29)....|| Practice Set No. 1 ||
 +
|-
 +
| 3 || WAP to demonstrate the Multiple implementations of an interface through an interface reference variable (slides no. 36)|| Practice Set No. 2 ||
 +
|-
 +
|4 || WAP to demonstrate the concept of Extending Interfaces (slides no 41-42) || Practice Set No. 3 ||
 +
|-
 +
|5 || WAP to demonstrate the concept of Default interface Method  || Practice Set No. 4 ||
 +
|-
 +
|6 || WAP to demonstrate how to achieve the concept of Multiple Inheritance  || Practice Set No. 5 ||
 +
|}
 +
 
 +
== '''Lab 7:''' ( week of 27<sup>th</sup> June 2022 ) ==
 +
{| class="wikitable" style="text-align: left; width: 100%";
 +
|-
 +
! Q. NO. 
 +
! Program 
 +
! Lab Exercise No. 
 +
! Remarks
 +
|-
 +
| style="width: 8%"  | 1
 +
| style="width: 60%" | WAP to demonstrate multiple catch statements. Also show the example of unreachable catch clause. (Slide no. 19-21)
 +
| style="width: 15%" | Practice Set No. 1 || 
 +
|-
 +
| 2 || WAP to demonstrate nested try statements. ( Slide no. 23-25) || Practice Set No. 2 ||
 +
|-
 +
| 3 || Create an Exception subclass UnderAge, which prints “Under Age” along with the age value when an object of UnderAge class is printed in the catch statement. Write a class exceptionDemo in which the method test() throws UnderAge exception if the variable age passed to it as argument is less than 18. Write main() method also to show working of the program.|| '''Lab Exercise No. 4''' || Read about Exception Handling from javatpoint.com [https://www.javatpoint.com/exception-handling-in-java]
 +
|-
 +
| 4 || Write a program to implement stack. Use exception handling to manage underflow and overflow conditions. || '''Lab Exercise No. 5''' ||
 +
|}
 +
 
 +
== '''Lab 8:''' ( week of 04<sup>th</sup> July 2022 ) ==
 +
{| class="wikitable" style="text-align: left; width: 100%";
 +
|-
 +
! Q. NO. 
 +
! Program 
 +
! Lab Exercise No. 
 +
! Remarks
 +
|-
 +
| style="width: 8%"  | 1
 +
| style="width: 60%" | Write a program that copies content of one file to another. Pass the names of the files through command-line arguments.
 +
| style="width: 15%" | '''Lab Exercise No. 6''' ||  Read about Java I/O and File Handling from javatpoint.com [https://www.javatpoint.com/java-io]
 +
|-
 +
| 2 || Write a program to read a file and display only those lines that have the first two characters as '//' (Use try with resources). ||  '''Lab Exercise No. 7''' || Read about Try with Resources statement from javatpoint.com [https://www.javatpoint.com/java-try-with-resources]
 +
|-
 +
| 3 || Write a program to handle mouse events(Clicked, Entered, Exited, Presses, and Released). || '''Lab Exercise No. 8''' || Read about mouselistener from javatpoint.com [http://www.javatpoint.com/java-mouselistener]
 +
|-
 +
| 4 || Write a program to handle key events(Pressed, Released, and Typed). || '''Lab Exercise No. 9''' || Read about keylistener from javatpoint.com [http://www.javatpoint.com/java-keylistener]
 +
|}
 +
 
 +
 
 +
== '''Lab 9:''' ( week of 11<sup>th</sup> July 2022 ) ==
 +
{| class="wikitable" style="text-align: left; width: 100%";
 +
|-
 +
! Q. NO. 
 +
! Program 
 +
! Lab Exercise No. 
 +
! Remarks
 +
|-
 +
| style="width: 8%"  | 1
 +
| style="width: 60%" | Using AWT, write a program to display a string in frame window with pink colour as background.
 +
| style="width: 15%" | '''Lab Exercise No. 10''' ||  Read about Adapter Classes from javatpoint.com [https://www.javatpoint.com/java-adapter-classes]
 +
|-
 +
| 2 || Using AWT, write a program to create two buttons named “Red” and “Blue”. When a button is pressed the background color should be set to the color named by the button’s label.  ||  '''Lab Exercise No. 11''' ||
 +
|-
 +
| 3 || Using AWT, write a program which responds to KEY_TYPED event and updates the status window with message (“Typed character is: X”). Use adapter class for other two events. ||  '''Lab Exercise No. 12''' ||
 +
|-
 +
| 4 || Using AWT, write a program to create two buttons labelled ‘A’ and ‘B’. When button ‘A’ is pressed, it displays your personal information (Name, Course, Roll No, College) and when button ‘B’ is pressed, it displays your CGPA in previous semester. ||  '''Lab Exercise No. 13'''
 +
|}
 +
 
 +
 
 +
== '''Final Lab:''' ( week of 18<sup>th</sup> July 2022 ) ==
 +
{| class="wikitable" style="text-align: left; width: 100%";
 +
|-
 +
! Q. NO. 
 +
! Program 
 +
! Lab Exercise No. 
 +
! Remarks
 +
|-
 +
| style="width: 8%"  | 1 -4
 +
| style="width: 60%" | Rewrite all the above GUI programs(Lab 9) using Swing.
 +
| style="width: 15%" | '''Lab Exercise No. 14''' ||  Read about Swing from javatpoint.com [https://www.javatpoint.com/java-swing]
 
|}
 
|}

Latest revision as of 13:40, 8 November 2022

Instructions

  • Please be on time to avoid the Attendance Penalty.
  • Please sign on the Attendance Register before your take a seat.
  • Please put your mobile phone in the Silent Mode.
  • Each lab assignment needs to be submitted in the Google Classroom for the evaluation(will be notified in the GC lab-wise, submit before the deadline).
  • Turn off(shut down) your assigned computer and arrange the chair before you leave the lab.

Resources

Lab 0: Getting Started ( week of 18th April 2022 )

Spring 2020 Lab 1

Q. NO. Program Lab Exercise No. Remarks
1 WAP to display your details like Name, Roll Number, Course, and College Name on the computer screen. Practice Set No. 1
2 WAP to check whether the given year is a Leap Year or not? Practice Set No. 2
3 WAP to find the sum of any number of integers entered as command line arguments Practice Set No. 3
4 WAP to find the factorial of a given number. Practice Set No. 4
5 WAP to print the following pattern using nested for loop:
1
2  3
4  5  6
7  8  9  10 
Practice Set No. 5

Lab 0b: ( week of 25th April 2022 ) - Explaination of Complex class program by Mr. Mahesh Saini sir.

Lab 1: ( week of 09th May 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 Design a class Complex having a real part (x) and an imaginary part (y). Provide methods to perform the following on complex numbers:

a) Add two complex numbers.
b) Multiply two complex numbers.
c) toString() method to display complex numbers in the form: x + i y.

Lab Exercise No. 1 Read about toString( ) from javatpoint.com [1]
2 WAP to read data of various types using Scanner class Practice Set No. 1 Read about Scanner class from javatpoint.com [2]
3 WAP to find the nth largest number and nth samallest number in an array Practice Set No. 2
4 WAP to find the sum of all odd numbers at the even indexes in an array Practice Set No. 3

Lab 1b: ( week of 16th May 2022 ) - complete all the previous programs.

Lab 2: ( week of 23rd May 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 Design a class named MobilePhone consisting of three members: name, company, and price. Create four objects and initialized them with four different ways (as discussed in the theory class). Show the usage of This keyword in creating any of the mentioned objects. Finally display all the four objects as output.
Practice Set No. 1
2 WAP to demonstrate the method overloading Practice Set No. 2
3 WAP to demonstrate the automatic type conversion in method overloading Practice Set No. 3
4 WAP to demonstrate the constructor overloading, also show how copy constructor is applied in Java Practice Set No. 4
5 WAP to demonstrate the difference between public and private access control in java Practice Set No. 5


Lab 3: ( week of 30th May 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 WAP to demostrate the concept/use of Java static keyword:
  1. static variable
  2. static method
  3. static block
Practice Set No. 1 Read about static keyword in Java from javatpoint.com [3]
2 WAP to perform following string operations:
  1. Find the length of a string
    input: "Delhi University" , output: 16
  2. Find the location(index) of a specific character
    input string: "Delhi University", location of U? , output: 6
  3. Find the character at a specific location
    input string: "Delhi University", character at 7? , output: n
  4. Compare two strings
    (1) input string: "Pushpa" and "KGF" , output: 5
    (2) input string: "Pushpa" and "Pushpa" , output: 0
    (3) input string: "KGF" and "Pushpa" , output: -5
  5. If the string contains a substring:
    (1) input string: "Acharya Narendra Dev College" and "Dev" , output: true
    (2) input string: "Acharya Narendra Dev College" and "Deshbandhu" , output: false
  6. Replace a part of the string with another string
    input string: "Acharya Narendra Dev College" , replace "Acharya Narendra Dev", with "AND", output: "AND College"
  7. Convert a string into lowercase and uppercase
    input string: "New Delhi", output: "new delhi" and "NEW DELHI"
Practice Set No. 2 Read about strings in Java from javatpoint.com [4]
3 WAP to demonstrate the Variable Argument (Varargs) in Java Practice Set No. 3 Read about Varargs in Java from:
(1) GFG [5]
(2) javatpoint.com [6]

Lab 4: ( week of 06th June 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 WAP to demostrate the single inheritance concept (chapter 8 ppt., slide no. 7-8) Practice Set No. 1
2 WAP to demonstrate Member Access and Inheritance (chapter 8 ppt., slide no. 10) Practice Set No. 2
3 WAP to demonstrate the single inheritance using Box and BoxWeight example (chapter 8 ppt., slide no. 11-12) Practice Set No. 3
4 WAP to demonstrate how A Superclass Variable Can Reference a Subclass Object (chapter 8 ppt., slide no. 15) Practice Set No. 4
5 WAP to demonstrate how to use Super to Call Superclass Constructors - A complete implementation of BoxWeight. (chapter 8 ppt., slide no. 21-24) Practice Set No. 5
6 WAP to demonstrate Using Super to access member of Superclass. (chapter 8 ppt., slide no. 28) Practice Set No. 5

Lab 5: ( week of 13th June 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 Create a class TwoDim which contains private members as x and y coordinates in package P1. Define the default constructor, a parameterized constructor and override toString() method to display the co-ordinates. Now reuse this class and in package P2 create another class ThreeDim, adding a new dimension as z as its private member. Define the constructors for the subclass and override toString() method in the subclass also. Write appropriate methods to show dynamic method dispatch. The main() function should be in a package P. Lab Exercise No. 2 Read about packages in java from javatpoint.com [7]
2 WAP to demonstrate Multi-level hierarchy in Inheritance Practice Set No. 1
3 WAP to demonstrate the use of Dynamic Method Dispatch ( slide no. 48, ppt no. 6) Practice Set No. 2
4 WAP to demonstrate the use of Abstract classes (slide no. 58, ppt no. 6) Practice Set No. 3

Lab 6: ( week of 20th June 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 Define an abstract class Shape in package P1. Inherit two more classes: Rectangle in package P2 and Circle in package P3. Write a program to ask the user for the type of shape and then using the concept of dynamic method dispatch, display the area of the appropriate subclass. Also write appropriate methods to read the data. The main() function should not be in any package. Lab Exercise No. 3 Read about Inheritance from javatpoint [8]
Read about Abstract class from javatpoint.com [9]
2 WAP to demonstrate the concept of interfaces (slides no. 25-29).... Practice Set No. 1
3 WAP to demonstrate the Multiple implementations of an interface through an interface reference variable (slides no. 36) Practice Set No. 2
4 WAP to demonstrate the concept of Extending Interfaces (slides no 41-42) Practice Set No. 3
5 WAP to demonstrate the concept of Default interface Method Practice Set No. 4
6 WAP to demonstrate how to achieve the concept of Multiple Inheritance Practice Set No. 5

Lab 7: ( week of 27th June 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 WAP to demonstrate multiple catch statements. Also show the example of unreachable catch clause. (Slide no. 19-21) Practice Set No. 1
2 WAP to demonstrate nested try statements. ( Slide no. 23-25) Practice Set No. 2
3 Create an Exception subclass UnderAge, which prints “Under Age” along with the age value when an object of UnderAge class is printed in the catch statement. Write a class exceptionDemo in which the method test() throws UnderAge exception if the variable age passed to it as argument is less than 18. Write main() method also to show working of the program. Lab Exercise No. 4 Read about Exception Handling from javatpoint.com [10]
4 Write a program to implement stack. Use exception handling to manage underflow and overflow conditions. Lab Exercise No. 5

Lab 8: ( week of 04th July 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 Write a program that copies content of one file to another. Pass the names of the files through command-line arguments. Lab Exercise No. 6 Read about Java I/O and File Handling from javatpoint.com [11]
2 Write a program to read a file and display only those lines that have the first two characters as '//' (Use try with resources). Lab Exercise No. 7 Read about Try with Resources statement from javatpoint.com [12]
3 Write a program to handle mouse events(Clicked, Entered, Exited, Presses, and Released). Lab Exercise No. 8 Read about mouselistener from javatpoint.com [13]
4 Write a program to handle key events(Pressed, Released, and Typed). Lab Exercise No. 9 Read about keylistener from javatpoint.com [14]


Lab 9: ( week of 11th July 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 Using AWT, write a program to display a string in frame window with pink colour as background. Lab Exercise No. 10 Read about Adapter Classes from javatpoint.com [15]
2 Using AWT, write a program to create two buttons named “Red” and “Blue”. When a button is pressed the background color should be set to the color named by the button’s label. Lab Exercise No. 11
3 Using AWT, write a program which responds to KEY_TYPED event and updates the status window with message (“Typed character is: X”). Use adapter class for other two events. Lab Exercise No. 12
4 Using AWT, write a program to create two buttons labelled ‘A’ and ‘B’. When button ‘A’ is pressed, it displays your personal information (Name, Course, Roll No, College) and when button ‘B’ is pressed, it displays your CGPA in previous semester. Lab Exercise No. 13


Final Lab: ( week of 18th July 2022 )

Q. NO. Program Lab Exercise No. Remarks
1 -4 Rewrite all the above GUI programs(Lab 9) using Swing. Lab Exercise No. 14 Read about Swing from javatpoint.com [16]