In this part, you need to discuss in detail the three following topics:
- File management
- Memory management
- Threads or Task/Process Scheduling (you can select either topic)
You must discuss each topic in terms of concepts, issues, solutions, usage, real work examples, etc.
In the implementation part, you must implement the pervious discussed topics in Java:
- File management
- Memory management
- Threads or Task/Process Scheduling (you can select either topic)
Note:
You must screenshot and illustrate your results for each part/topic. You also must submit your Java codes on the Blackboard.
Topic 1 – File Management:
You are given a text file “namesList,” which contains a list of names. You need to read the file, store the names in a list, and then count the number of each name (Ahmed Ali, and Muhammad). Next, you need to create a new text file using Java, order the names alphabetically, and print the name to the new created file named “newNameList.”
Hint 1:
You can read the file using Java built-in classes (e.g., BufferedReader class, Scanner class. File Reader class). To read the file, you must do the following
- Create a new function named “readFile.” Inside the function, you must write your code. Here is an example to create a list:
List<String> list = new ArrayList<>();
- Once you stored the data on the list, you now can print/show the list’s data using a Java Foor Loop.
for(int i = 0; i < 5; i++){ System.out.println(i);}
Topic 2 – Memory Management:
As memory in any operating system is a scarce resource (limited capacity), programmers must be able to write a code that uses the memory efficiently to improve application performance. In this topic, you must illustrate the following:
- Write bad codes that will use the memory inefficiently, which will result in bad performance (e.g., creating unnecessary objects, lists, etc.). Give at least 5 bad examples.
- Write good codes that will use the memory efficiently, which will result in optimal performance. In here, you can fix the bad codes you created.
There are many memories monitoring tools that you can use to view and visualize memory and CPU utilization (e.g., VisualVM). Use a tool of your choice to show memory usage statistics you obtain from running/executing your bad and good codes.
The following tutorial might be very helpful:
https://www.youtube.com/watch?v=pRwvx4QpUfo
https://www.youtube.com/watch?v=AHLkbqcVLvY&t=404s
Topic/question 3: Threads or Task Scheduling
In this topic, you can choose to implement either thread techniques or task scheduling. Note, we discussed threads and process scheduling in slides week 3 & 4.
Threads (choice 1):
Threads can be used to make your Java applications faster. They allow you to run multiple things at the same time. You must think of a good scenario for using threads in real-world, and then implement the scenario in Java. You must discuss your scenario. To create a thread in Java, you can either:
- Extend Thread class, or
- Implement the Runnable interface
You can follow the below steps to create threads:
- Create a class named MultiThreads. Inside the class, write your thread logic (variables, functions, etc.). You must create a thread ID for each thread.
- Now in the main class, create three threads and illustrate the difference between using one thread and three threads (screenshots and discuss your results).
- You need to show a case where two threads run in parallel, where each thread tries to modify a common variable at the same time (screenshots and illustrate your results). Next, try to find a way to fix this issue so that the two threads do not modify the common variable at the same time.
Task Scheduling (choice 2):
A single-core CPU executes its processes/tasks one by one based on a given scheduling criteria. Let us say that we have more than one task to be executed. We learned that for any task to be executed, it must be put into a Ready queue. The CPU must choose which task to execute first. As such, you are asked to code two task scheduling algorithms. The first algorithm is First come first serve (FCFS). You must screenshot and illustrate your results. The second algorithm would be either:
- Shorter Job First (SJF).
- Round Robin.
Choose one from the two above algorithms (1 or 2). For simulating/creating tasks, you can use a factorial function or a Fibonacci sequence function. You can follow the below steps to do the ask scheduling:
- Create a new class named “TaskScheduling” and place the function of your choice inside as a method/function.
- In the main class (the class you use to run the code), create two objects of your class where each object would run the same method (factorial/ Fibonacci) at the same time. Note: the objects would be assumed as tasks.
- You might use system time provided by Java libraries to keep track of time for each task (running time, waiting time, etc.). You can also use this time to properly implement SJF and Round Robin. To obtain the time in java, you can import “time.LocalDate.”
- Demonstrate your scheduling algorithms using the two objects/tasks. You need to show your results (e.g., running time for each task, waiting time, etc.).
- Hint: A queue can be implemented in java using
You will present your project in class. You must create PowerPoint slides that summarize your work. For each group, all student members must present part of the work.