Hướng dẫn làm bài Click để xem: hướng dẫn làm bài // Java Class Library Bước 1: Bước 2: tạo class nguyên tố Bước 3: nhập code CODE: Select All package rmi.libs;import java.rmi.Remote;import java.rmi.RemoteException;import java.util.ArrayList;public interface NguyenTo extends Remote{ public boolean kiemtraNT(int n) throws RemoteException; public ArrayList<Integer> ketqua(int n) throws RemoteException; } //Java Application Bước 1: tạo rmiserver Bước 2: Tạo class Tính Toán Bước 3: nhập code CODE: Select All package rmi.server;import java.rmi.RemoteException;import java.rmi.server.UnicastRemoteObject;import java.util.ArrayList;import rmi.libs.NguyenTo;public class TinhToan extends UnicastRemoteObject implements NguyenTo{ public TinhToan() throws RemoteException { } public boolean kiemtraNT(int n) throws RemoteException { if( n<2) return false; else{ if ( n==2|| n==3 ) return true; else { for( int i=2;i<=Math.sqrt(n);i++){ if(n%i==0){ return false; } } } return true; } } public ArrayList<Integer> ketqua(int n) throws RemoteException { ArrayList<Integer> arrList= new ArrayList<>(); for( int i=0;i<n;i++){ if ( kiemtraNT(i)==true){ arrList.add(i); } } return arrList; }} Bước 4: Tạo Class Server Bước 5: nhập code CODE: Select All package rmi.server;import java.net.MalformedURLException;import java.rmi.Naming;import java.rmi.RemoteException;import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;import java.util.logging.Level;import java.util.logging.Logger;public class Server { public static void main(String[] args) { new Server().run(); } private void run(){ int port= 6394; try { TinhToan tt=new TinhToan(); Registry registry=LocateRegistry.createRegistry(port); Naming.rebind("rmi://localhost:"+port+"/TinhToan", tt); System.out.println(" server dang chay...."); } catch (RemoteException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } }} Bước 6 : rmiserver kết nối với rmilibs Bước 7: Tạo rmiclient Bước 8 : tạo class Client CODE: Select All package rmi.client;import java.net.MalformedURLException;import java.rmi.Naming;import java.rmi.NotBoundException;import java.rmi.RemoteException;import java.util.Scanner;import java.util.logging.Level;import java.util.logging.Logger;import rmi.libs.NguyenTo;public class Client { public static void main(String[] args) { new Client().run(); } private void run(){ int port=6394; int n; try { NguyenTo nt=(NguyenTo) Naming.lookup("rmi://localhost:"+port+"/TinhToan"); System.out.println(" nhap gia tri cua n:"); do{ System.out.print(" n="); Scanner scn= new Scanner(System.in); n=scn.nextInt(); } while(n<2); System.out.println(" nhung so nguyen to thoa man la:"); for( int i=0; i<nt.ketqua(n).size();i++){ System.out.print(nt.ketqua(n).get(i)+" "); } System.out.print(" "); } catch (NotBoundException ex) { Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); } catch (RemoteException ex) { Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); } } } Bước 9: rmi client kết nối với rmilibs Kết quả: run file Server run file Client