Download - Java Lab
![Page 2: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/2.jpg)
Outline
- Lab 01: An introduction to Java- Lab 02: Java Language- Lab 03: Class and Relationship- Lab 04: Exception and debugging- Lab 05: Thread- Lab 06: Input/Output- Lab 07: Generic programming and Collections
![Page 3: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/3.jpg)
Github
https://github.com/leonguyen/JavaLab
![Page 4: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/4.jpg)
Lab 01
An introduction to Java
![Page 5: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/5.jpg)
Outline
- Download and install JDK- Write a Helloworld program- Install and use Eclipse to write a Java program- Debugging Programs in Eclipse
![Page 6: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/6.jpg)
Exercise 1
Download and install JDK
![Page 7: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/7.jpg)
JDK & JRE
![Page 8: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/8.jpg)
Task 1 - Download JDK
- Goto Java download site http://www.oracle.com/technetwork/java/javase/downloads/index.html
![Page 9: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/9.jpg)
Task 1 - Download JDK (cont)
- Select Java Platform (JDK), choose your operation platform (eg Window X86) and download it
![Page 10: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/10.jpg)
Task 2 - Install JDK
- Run the downloaded installer, which installs both the JDK (Java Development Kit) and JRE (Java Runtime). By default the JDK and JRE will be installed into directories C:\Program Files\Java
![Page 11: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/11.jpg)
Task 3 - Config PATH environment variables
- Windows Operating System searches the current directory and the directories listed in the PATH environment variable for executable programs invoked from the CMD shell. It helps programmer can compile Java code in CMD shell.- Click the "Start" button > "Control Panel" > "System" > (Vista/7 only) "Advanced system settings"
![Page 12: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/12.jpg)
Task 3 - Config PATH .. (cont)
![Page 13: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/13.jpg)
Task 4 - Verify the JDK Installation
- Launch a CMD shell > type java –version to check that JDK is properly installed and display its version, and javac to check Path work properly too.
![Page 14: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/14.jpg)
Exercise 2
Write a Helloworld program
![Page 15: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/15.jpg)
Task 1 - Open your editor
- For example: Notepad++
![Page 16: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/16.jpg)
Task 2 - Write your code
- Type this code bellow to editor window
![Page 17: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/17.jpg)
Task 2 - Write your code (cont)
- Save the code in a file with the name Helloworld.java- Note: File name must same as class name.
![Page 18: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/18.jpg)
Task 3 - Compile and run on command-line
- Launch a CMD shell > type javac to compile the source code and java to run the program using the JDK runtime
![Page 19: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/19.jpg)
Exercise 3
Install and use Eclipse to write a Java program
![Page 20: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/20.jpg)
Task 1 - Download Eclipse
- Download Eclipse from http://www.eclipse.org/downloads. For beginners, choose the minimal Eclipse IDE for Java Developers.- Unzip the downloaded file into a directory of your choice.
![Page 21: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/21.jpg)
Task 2 - Launch Eclipse
- Open eclipse.exe in the Eclipse installed directory- Choose an appropriate directory for your workspace
![Page 22: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/22.jpg)
Task 3 - Create a new Java Project
- Choose "File" menu > "New" > "Java project"
![Page 23: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/23.jpg)
Task 4 - Write a Java program
- In the "Package Explorer" (left panel) > Right-click on "JavaLab" (or use the "File" menu) > New > Class
![Page 24: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/24.jpg)
Task 4 - Write a Java program (cont)
- Enter the following codes
![Page 25: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/25.jpg)
Task 5 - Compile and Execute
- To run the program, right-click anywhere on the source file "HelloWorld.java" (or from the "Run" menu) > Choose "Run As" > "Java Application".
![Page 26: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/26.jpg)
Exercise 4
Debugging Programs in Eclipse
![Page 27: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/27.jpg)
Task 1 - Create project and write a simple program
- Create a new class named Debug and enter the following code.
![Page 28: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/28.jpg)
Task 2 - Set an Initial Breakpoint
- Set a breakpoint at main() method by double-clicking on the left-margin of the line containing main().
![Page 29: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/29.jpg)
Task 3 - Debug
- Right click anywhere on the source code (or from the "Run" menu) > "Debug As" > "Java Application" > choose "Yes" to switch into "Debug" perspective Step-Over and Watch the Variables and Outputs.
![Page 30: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/30.jpg)
Lab 02
Java Language 01
![Page 31: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/31.jpg)
Outline
- Relational & Logical Operators- Types- Scanner object- If/else- Switch case- Command-Line Arguments
![Page 32: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/32.jpg)
Outline (cont)
- OddEvenSum- Compute PI- Do While statement- Array- Loops and conditional statement- Nested loop- Break label- Continue label- Array Sort- Reverse String- Array of String
![Page 33: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/33.jpg)
Exercise 1
Relational & Logical Operators
![Page 34: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/34.jpg)
Task 1 - Create a RelationalLogicalOpTest class
- Enter the following code.
![Page 35: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/35.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 36: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/36.jpg)
Exercise 2
Types
![Page 37: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/37.jpg)
Task 1 - Create a TypesMinMax class
- Enter the following code.
![Page 38: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/38.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 39: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/39.jpg)
Exercise 3
Scanner object
![Page 40: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/40.jpg)
Task 1 - Create a ScannerTest class
- Enter the following code.
![Page 41: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/41.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 42: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/42.jpg)
Exercise 4
If/else
![Page 43: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/43.jpg)
Task 1 - Create a Mark class
- Enter the following code.
![Page 44: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/44.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 45: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/45.jpg)
Exercise 5
Switch case
![Page 46: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/46.jpg)
Task 1 - Create a Month class
- Enter the following code.
![Page 47: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/47.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 48: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/48.jpg)
Exercise 6
Command-Line Arguments
![Page 49: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/49.jpg)
Task 1 - Create a Arithemetic class
- Enter the following code.
![Page 50: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/50.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 51: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/51.jpg)
Lab 02 (cont)
Java Language 02
![Page 52: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/52.jpg)
Exercise 1
OddEvenSum
![Page 53: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/53.jpg)
Task 1 - Create a OddEvenSum class
- Enter the following code.
![Page 54: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/54.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 55: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/55.jpg)
Exercise 2
Compute PI
![Page 56: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/56.jpg)
Task 1 - Create a ComputePI class
- Enter the following code.
![Page 57: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/57.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 58: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/58.jpg)
Exercise 3
Do While statement
![Page 59: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/59.jpg)
Task 1 - Create a DoWhile class
- Enter the following code.
![Page 60: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/60.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 61: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/61.jpg)
Exercise 4
Array
![Page 62: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/62.jpg)
Task 1 - Create a Arraytest class
- Enter the following code.
![Page 63: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/63.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 64: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/64.jpg)
Exercise 5
Loops and conditional statement
![Page 65: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/65.jpg)
Task 1 - Create a PrimeList class
- Enter the following code.
![Page 66: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/66.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 67: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/67.jpg)
Exercise 6
Nested loop
![Page 68: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/68.jpg)
Task 1 - Create a PrintPattern class
- Enter the following code.
![Page 69: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/69.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 70: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/70.jpg)
Exercise 7
Break label
![Page 71: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/71.jpg)
Task 1 - Create a JavaGoto class
- Enter the following code.
![Page 72: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/72.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 73: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/73.jpg)
Exercise 8
Continue label
![Page 74: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/74.jpg)
Task 1 - Create a ContinueLabel class
- Enter the following code.
![Page 75: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/75.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 76: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/76.jpg)
Exercise 9
Array Sort
![Page 77: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/77.jpg)
Task 1 - Create a ArrayBubleSort class
- Enter the following code.
![Page 78: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/78.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 79: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/79.jpg)
Exercise 10
Reverse String
![Page 80: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/80.jpg)
Task 1 - Create a ReverString class
- Enter the following code.
![Page 81: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/81.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 82: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/82.jpg)
Exercise 11
Array of String
![Page 83: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/83.jpg)
Task 1 - Create a DayofWeek class
- Enter the following code.
![Page 84: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/84.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 85: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/85.jpg)
Lab 03
Class
![Page 86: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/86.jpg)
Outline
- Booking Room- Project assignment
![Page 87: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/87.jpg)
What is OOP
![Page 88: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/88.jpg)
Classes and Objects
![Page 89: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/89.jpg)
Lab 03 (cont)
Class
![Page 90: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/90.jpg)
Exercise 1
Booking Room
![Page 91: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/91.jpg)
Class diagram
![Page 92: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/92.jpg)
Task 1 - Create Date class
- Enter the following code.
![Page 93: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/93.jpg)
Task 2 - Create Time class
- Enter the following code.
![Page 94: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/94.jpg)
Task 3 - Create BookingRoomclass
- Enter the following code.
![Page 95: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/95.jpg)
Task 3 - Create BookingRoomclass (cont)
- Enter the following code.
![Page 96: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/96.jpg)
Task 3 - Create BookingRoomclass (cont)
- Enter the following code.
![Page 97: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/97.jpg)
Task 3 - Create BookingRoomclass (cont)
- Enter the following code.
![Page 98: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/98.jpg)
Task 4 - Write a Program class
- Enter the following code.
![Page 99: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/99.jpg)
Task 5 - Execute your program
- Enter the following code.
![Page 100: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/100.jpg)
Exercise 2
Project assignment
![Page 101: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/101.jpg)
Class diagram
![Page 102: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/102.jpg)
Task 1 - Create Teacher class
- Enter the following code.
![Page 103: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/103.jpg)
Task 1 - Create Teacher class (cont)
- Enter the following code.
![Page 104: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/104.jpg)
Task 2 - Create Student class
- Enter the following code.
![Page 105: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/105.jpg)
Task 2 - Create Student class (cont)
- Enter the following code.
![Page 106: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/106.jpg)
Task 3 - Write a Program class
- Enter the following code.
![Page 107: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/107.jpg)
Task 4 - Execute your program
- Enter the following code.
![Page 108: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/108.jpg)
Lab 04
Exception
![Page 109: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/109.jpg)
Outline
- Exception- Try-cath-finally- Creating Your Own Exception Classes- Assertion
![Page 110: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/110.jpg)
Exercise 1
Exception
![Page 111: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/111.jpg)
Diagram
- MobilePhone class to store mobile phone numbers and send a messages to one of of numbers store in the array.- PhoneTest class to demonstrate exception handling.
![Page 112: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/112.jpg)
Task 1 - Create MobilePhone class
- Enter the following code.
![Page 113: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/113.jpg)
Task 1 - Create MobilePhone class (cont)
- Enter the following code.
![Page 114: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/114.jpg)
Task 2 - Create PhoneTest program
- Enter the following code.
![Page 115: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/115.jpg)
Task 3 - Execute your program
- Enter the following code.
![Page 116: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/116.jpg)
Exercise 2
Try-cath-finally
![Page 117: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/117.jpg)
Task 1 - Create TryCatchFinally program
- Enter the following code.
![Page 118: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/118.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 119: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/119.jpg)
Exercise 3
Creating Your Own Exception Classes
![Page 120: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/120.jpg)
Task 1 - Create MyException class
- Enter the following code.
![Page 121: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/121.jpg)
Task 2 - Create MyExceptionTest program
- Enter the following code.
![Page 122: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/122.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 123: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/123.jpg)
Exercise 4
Assertion
![Page 124: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/124.jpg)
Task 1 - Create AssertionTest program
- Enter the following code.
![Page 125: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/125.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 126: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/126.jpg)
Exercise 5
Account in a Bank
![Page 127: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/127.jpg)
Diagram
![Page 128: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/128.jpg)
Diagram (cont)
The management of the A Bank is looking at automation as a means to save time and effort required in their work. In order to achieve this, the management has planned to computerize the following transactions:• Creating a new account• Withdrawing money from an account• Depositing money in an accountThe CEO of the company and a team of experts have chosen your company to provide a solution for the same. Consider yourself to be a part of the team that implements the solution for designing the application.
![Page 129: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/129.jpg)
Diagram (cont)
Create an application using exceptions and assertions to implement the transactions. The application should consist of the following classes.
1. Account.java
2. Account Test.java
3. InsufficientFundException.java
4. NegativeAmountException.java
Each class has a specific purpose and functionality. The descriptions of each class are as follows.
![Page 130: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/130.jpg)
Task 1 - Create Account class
(The Account class represents an actual bank account. It stores the following details of a bank account)• customerName• accountNumber• accountbalance• void displayAccountDetails() : This method displays the details of the account
![Page 131: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/131.jpg)
Task 1 - Create Account class (cont)
• void withdraw() : This method is used to withdraw money from an account. This method accepts the account number and the amount to be withdrawn from the account. The method then searches in the array of accounts for the account number. Use assertions for checking whether the account number and the amount to be withdrawn are positive. Also use an assertion to check if the array of accounts contains a minimum of one account record. The method also throws the user-defined exception InsufficientFund***ception in case the amount to be withdrawn exceeds• void deposit() :This method is used to deposit money in an account. The account number and the amount to be deposited in the account is accepted from the user. Use an assertion to check whether the account number is positive. The method searches for the account number and deposits the amount in the account if it exists. The displayAccountDetails() method is called if the operation succeeds. Use appropriate try catch blocks to handle all the possible exceptions that can be thrown due to the user inputs. A user-defined exception is thrown if the account number does not exist.
![Page 132: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/132.jpg)
Task 2 - Create AccountTest class
(The AccountTest class is a java main class used to test the Account class. It creates an instance of the Account class and displays the following menu of options to the user)· Create a new account· Withdraw Cash· Deposit cash· ExitThe user can select any of the options and a corresponding method is invoked on the instance of the Bank class. Use an assertion to check for the control-flow invariant in case the user types an invalid option. The application exits when the Exit option is selected.
![Page 133: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/133.jpg)
Task 3 - Create InsufficientFundException class
- This is a user-defined exception class derived from the base class Exception. This exception is thrown when the user tries to withdraw more money than the current account balance.
![Page 134: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/134.jpg)
Task 4 - Create NegativeAmountException class
- This is a user-defined exception class derived from the base class Exception. This exception is thrown when the user tries to withdraw or deposit a negative amount.
![Page 135: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/135.jpg)
Lab 05
Thread
![Page 136: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/136.jpg)
Outline
- Use the Thread class- Implement the Runable Interface- Using join() to wait for threads to finish- Thread priority- Synchronization- Dining Philosopher
![Page 137: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/137.jpg)
Exercise 1
Use the Thread class
![Page 138: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/138.jpg)
Task 1 - Create a RunThread class
- Enter the following code.
![Page 139: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/139.jpg)
Task 2 - Main program
- Enter the following code.
![Page 140: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/140.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 141: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/141.jpg)
Exercise 2
Implement the Runable Interface
![Page 142: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/142.jpg)
Task 1 - Create a RunThread1 class
- Enter the following code.
![Page 143: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/143.jpg)
Task 2 - Main program
- Enter the following code.
![Page 144: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/144.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 145: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/145.jpg)
Exercise 3
Using join() to wait for threads to finish
![Page 146: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/146.jpg)
Task 1 - Create a MyThread class
- Enter the following code.
![Page 147: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/147.jpg)
Task 2 - Main program
- Enter the following code.
![Page 148: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/148.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 149: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/149.jpg)
Exercise 4
Thread priority
![Page 150: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/150.jpg)
Task 1 - Create Clicker class
- Enter the following code.
![Page 151: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/151.jpg)
Task 2 - Main program
- Enter the following code.
![Page 152: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/152.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 153: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/153.jpg)
Exercise 5
Synchronization
![Page 154: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/154.jpg)
Unsynchronized and synchronized
![Page 155: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/155.jpg)
Task 1 - Create CountPrimesThread class
- Enter the following code.
![Page 156: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/156.jpg)
Task 2 - Main program
- Enter the following code.
![Page 157: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/157.jpg)
Task 2 - Main program (cont)
- Enter the following code.
![Page 158: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/158.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 159: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/159.jpg)
Exercise 6
Dining Philosopher
![Page 160: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/160.jpg)
Concept
![Page 161: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/161.jpg)
Task 1 - Create ChopStick class
- Enter the following code.
![Page 162: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/162.jpg)
Task 2 - Create Philosopher class
- Enter the following code.
![Page 163: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/163.jpg)
Task 2 - Create Philosopher class (cont)
- Enter the following code.
![Page 164: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/164.jpg)
Task 2 - Main program
- Enter the following code.
![Page 165: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/165.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 166: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/166.jpg)
Lab 06
Input / Output
![Page 167: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/167.jpg)
Stream
- Most fundamental I/O in Java is based on streams- Reading information into a program
- Writing information from a program
![Page 168: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/168.jpg)
java.io package
![Page 169: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/169.jpg)
Outline
- Read a file - BufferedReader- Write a file - BufferedWriter- Write a file - FileOutputStream- List the contents of a directory (Recursively)- Copying a file without Buffering- Copying a file with a Programmer-Managed Buffer- Copying a file with Buffered Streams- Best Copier- InputStreamReader and OutputStreamWriter- BufferedReader and BufferedWriter- PipedReader and PipedWriter- Serializable - ObjectOutputStream
![Page 170: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/170.jpg)
Exercise 1
Read a file - BufferedReader
![Page 171: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/171.jpg)
Task 1 - Create ReadFileBuffered program
- The simplest and most common-used method - BufferedReader.
![Page 172: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/172.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 173: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/173.jpg)
Exercise 2
Write a file - BufferedWriter
![Page 174: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/174.jpg)
Task 1 - Create WriteFileBuffered program
- BufferedWriter is a character streams class to handle the character data. Unlike bytes stream (convert data into bytes), you can just write the strings, arrays or characters data directly to file.
![Page 175: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/175.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 176: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/176.jpg)
Exercise 3
Write a file - FileOutputStream
![Page 177: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/177.jpg)
Task 1 - Create WriteFileStream program
- FileOutputStream is a bytes stream class that’s used to handle raw binary data. To write the data to file, you have to convert the data into bytes and save it to file.
![Page 178: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/178.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 179: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/179.jpg)
Exercise 4
List the contents of a directory (Recursively)
![Page 180: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/180.jpg)
Task 1 - Create ListDirectoryRecusive program
- Enter the following code.
![Page 181: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/181.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 182: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/182.jpg)
Exercise 5
Copying a file without Buffering
![Page 183: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/183.jpg)
Task 1 - Create FileCopyNoBuffer class
- Enter the following code.
![Page 184: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/184.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 185: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/185.jpg)
Exercise 6
Copying a file with a Programmer-Managed Buffer
![Page 186: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/186.jpg)
Task 1 - Create FileCopyUserBuffer class
- Enter the following code.
![Page 187: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/187.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 188: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/188.jpg)
Exercise 7
Copying a file with Buffered Streams
![Page 189: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/189.jpg)
Task 1 - Create FileCopyBuffered class
- Enter the following code.
![Page 190: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/190.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 191: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/191.jpg)
Exercise 8
Best Copier
![Page 192: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/192.jpg)
Task 1 - Create FileCopyUserBufferBest class
- Enter the following code.
![Page 193: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/193.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 194: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/194.jpg)
Exercise 9
InputStreamReader and OutputStreamWriter
![Page 195: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/195.jpg)
Task 1 - Create UnicodeFileIO program
- Enter the following code.
![Page 196: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/196.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 197: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/197.jpg)
Exercise 10
BufferedReader and BufferedWriter
![Page 198: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/198.jpg)
Task 1 - Create UnicodeFileIOBuffered program
- Enter the following code.
![Page 199: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/199.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 200: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/200.jpg)
Exercise 11
PipedReader and PipedWriter
![Page 201: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/201.jpg)
Task 1 - Create pReader class
- Enter the following code.
![Page 202: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/202.jpg)
Task 2 - Create pWriter class
- Enter the following code.
![Page 203: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/203.jpg)
Task 3 - Main program
- Enter the following code.
![Page 204: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/204.jpg)
Task 4 - Execute your program
- Choose "Run As" > "Java Application".
![Page 205: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/205.jpg)
Exercise 12
Serializable - ObjectOutputStream
![Page 206: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/206.jpg)
Task 1 - Create SerializedObject class
- Enter the following code.
![Page 207: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/207.jpg)
Task 2 - Create SerializedObject class
- Enter the following code.
![Page 208: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/208.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 209: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/209.jpg)
Lab 07
Generic
![Page 210: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/210.jpg)
Outline
- Generic class and Wildcard- Student List- ArrayList- Employee Management- LinkedList- Set- Map
![Page 211: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/211.jpg)
Exercise 1
Generic class and Wildcard
![Page 212: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/212.jpg)
Task 1 - Create Box class
- Enter the following code.
![Page 213: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/213.jpg)
Task 2 - Create the program
- Enter the following code.
![Page 214: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/214.jpg)
Task 3 - Execute your program
- Choose "Run As" > "Java Application".
![Page 215: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/215.jpg)
Task 4 - Create A, B, C class
- Enter the following code.
![Page 216: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/216.jpg)
Task 5 - Create BoxB, BoxC class
- Enter the following code.
![Page 217: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/217.jpg)
Task 6 - Create Test BoxB, BoxC program
- Choose "Run As" > "Java Application".
![Page 218: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/218.jpg)
Task 7 - Execute your program
- Choose "Run As" > "Java Application".
![Page 219: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/219.jpg)
Exercise 2
Student List
![Page 220: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/220.jpg)
Student List
![Page 221: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/221.jpg)
Task 1 - Create Student class
- Enter the following code.
![Page 222: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/222.jpg)
Task 2 - Create StudentList class
- Enter the following code.
![Page 223: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/223.jpg)
Task 3 - Create the program
- Enter the following code.
![Page 224: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/224.jpg)
Task 4 - Execute your program
- Choose "Run As" > "Java Application".
![Page 225: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/225.jpg)
Exercise 3
ArrayList
![Page 226: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/226.jpg)
Task 1 - Create ExArrayList program
- Enter the following code.
![Page 227: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/227.jpg)
Task 2 - Execute your program
- Choose "Run As" > "Java Application".
![Page 228: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/228.jpg)
Exercise 4
Employee Management
![Page 229: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/229.jpg)
Task 1 - Create Employee class
- Enter the following code.
![Page 230: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/230.jpg)
Task 2 - Create HREmpoyee class
- Enter the following code.
![Page 231: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/231.jpg)
Task 3 - Create the program
- Enter the following code.
![Page 232: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/232.jpg)
Task 4 - Execute your program
- Choose "Run As" > "Java Application".
![Page 233: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/233.jpg)
Task 5 - Create EmpoyeeDetail class
- Enter the following code.
![Page 234: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/234.jpg)
Task 6 - Edit the program
- Enter the following code.
![Page 235: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/235.jpg)
Task 7 - Execute your program
- Choose "Run As" > "Java Application".
![Page 236: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/236.jpg)
Exercise 5
LinkedList
![Page 237: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/237.jpg)
Task 1 - Create ExLinkedList program
- Enter the following code.
![Page 238: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/238.jpg)
Task 1 - Create ExLinkedList program (cont)
- Enter the following code.
![Page 239: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/239.jpg)
Task 1 - Create ExLinkedList program (cont)
- Enter the following code.
![Page 240: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/240.jpg)
Task 2 - Execute your program
- Enter the following code.
![Page 241: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/241.jpg)
Exercise 6
Set
![Page 242: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/242.jpg)
Task 1 - Create ListDirectoryRecusive class
- Enter the following code.
![Page 243: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/243.jpg)
Task 2 - Execute your program
- Enter the following code.
![Page 244: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/244.jpg)
Exercise 7
Map
![Page 245: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/245.jpg)
Task 1 - Create ExMap program
- Enter the following code.
![Page 246: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/246.jpg)
Task 1 - Create ExMap program (cont)
- Enter the following code.
![Page 247: Java Lab](https://reader033.vdocuments.net/reader033/viewer/2022060109/5557d5f5d8b42af2178b4d98/html5/thumbnails/247.jpg)
Task 2 - Execute your program
- Enter the following code.