Question: can you explain this java code and how it works and why was hash set and hash maps used: package javaapplication 3 0 ; import
can you explain this java code and how it works and why was hash set and hash maps used: package javaapplication; import java.util.; @author public class JavaApplication @param args the command line arguments public static void mainString args TODO code application logic here Scanner scanner new ScannerSystemin; System.out.printEnter the number of frames: ; int capacity scanner.nextInt; System.out.printEnter the page string commaseparated: ; scanner.nextLine; Consume newline String pages scanner.nextLinesplit; int pageFaultsLRU simulateLRUpages capacity; System.out.printlnNumber of page faults: pageFaultsLRU; int pageFaultsFifo simulateFIFOpages capacity; System.out.printlnNumber of page faults: pageFaultsFifo; public static int simulateLRUString pages, int capacity Set frameSet new LinkedHashSetcapacity; Map pageLastUsed new HashMap; int pageFaults ; for String page : pages if frameSet.containspage pageFaults; if frameSetsize capacity String leastRecentlyUsedPage null; int minLastUsed Integer.MAXVALUE; for String framePage : frameSet if pageLastUsedgetframePage minLastUsed leastRecentlyUsedPage framePage; minLastUsed pageLastUsed.getframePage; frameSet.removeleastRecentlyUsedPage; pageLastUsed.removeleastRecentlyUsedPage; frameSet.addpage; pageLastUsed.putpage pageFaults; System.out.printlnMemory State: frameSet; return pageFaults; public static int simulateFIFOString pages, int capacity Queue frameQueue new LinkedList; Set frameSet new HashSet; int pageFaults ; for String page : pages if frameSet.containspage pageFaults; if frameQueuesize capacity String removedPage frameQueue.poll; frameSet.removeremovedPage; frameQueue.offerpage; frameSet.addpage; System.out.printlnMemory State: frameQueue; return pageFaults;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
