Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Just Need Some quick help with code

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Just Need Some quick help with code

    Ok,

    Here goes im pretty new to java, but need to compile and run the following code. It's basicially a RMI Client Server which generates prime numbers


    Here is the source Code

    CLIENT

    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.net.MalformedURLException;
    import java.rmi.NotBoundException;
    import java.io.*;
    public class PrimesClient
    {
    public static void main(String[] args)
    {
    try
    {
    if (args.length != 3)
    {
    System.out.println("Error usage: java PrimesClient host "
    +" min max");
    System.exit(0);
    }
    //look up the service in the registry
    Primes c = (Primes) Naming.lookup("rmi://" + args[0] +
    "/PrimesServd");
    int ct;
    int lct = 0;
    int min = Integer.parseInt(args[1]);
    int max = Integer.parseInt(args[2]);
    int[] p = c.findPrimes(min, max);
    ct = p[0];
    for (int i = 1; i < ct; i++)
    {
    lct++;
    if (lct == 12)
    {
    lct = 0;
    System.out.println();
    }
    System.out.print(" " + p[i]);
    }
    System.out.println();
    }
    catch (Exception e)
    {
    System.out.println("Exception" + e);
    System.out.println(e);
    }
    }
    }

    This is the error I receive in JCreator for Client Part
    C:\Users\Tevez aka Ratman\Desktop\PrimesClient.java:19: cannot find symbol
    symbol : class Primes
    location: class PrimesClient
    Primes c = (Primes) Naming.lookup("rmi://" + args[0] +
    ^
    C:\Users\Tevez aka Ratman\Desktop\PrimesClient.java:19: cannot find symbol
    symbol : class Primes
    location: class PrimesClient
    Primes c = (Primes) Naming.lookup("rmi://" + args[0] +
    ^
    2 errors

    Process completed.


    SERVER

    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.rmi.RMISecurityManager;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.registry.LocateRegistry;
    public class PrimesServd extends UnicastRemoteObject implements
    Primes
    {
    int[] p;
    public PrimesServd() throws RemoteException
    {
    super();
    p = new int[1000];
    }
    public int[] findPrimes(int min, int max) throws
    java.rmi.RemoteException
    {
    int ct = 1;
    for (int i = min; i < max; i++)
    {
    if (isPrime(i))
    {
    p[ct] = i;
    ct++;
    }
    }
    p[0] = ct;
    return p;
    }
    private static boolean isPrime(int n)
    {
    int i;
    for (i = 2; i * i <= n; i++)
    {
    if ((n % i) == 0)
    {
    return false;
    }
    }
    return true;
    }
    public static void main(String args[])
    {
    if (args.length != 1)
    {
    System.out.println("Error! correct usage java
    PrimesServd server-host");
    }
    else
    {
    try
    {
    // Create and install a security manager
    //if (System.getSecurityManager() == null) {
    //System.setSecurityManager(new
    RMISecurityManager());
    // }
    PrimesServd sc = new PrimesServd();
    Naming.rebind("rmi://" + args[0] + "/PrimesServd",
    sc);
    System.out.println("PrimesServd bound in registry");
    }
    catch (Exception e)
    {
    System.out.println(" Server err: " +
    e.getMessage());
    }
    }
    }
    }

    This is error I receive for client part

    C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:46: unclosed string literal
    System.out.println("Error! correct usage java
    ^
    C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:46: ';' expected
    System.out.println("Error! correct usage java
    ^
    C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:47: unclosed string literal
    PrimesServd server-host");
    ^
    C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:47: not a statement
    PrimesServd server-host");
    ^
    C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:56: ';' expected
    RMISecurityManager());
    ^
    5 errors

    Process completed.



    Please could someone please tell me why its not functioning


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Just Need Some quick help with code

    Those compiler errors tell you exactly what line they are on and are simple java syntax errors. For example
    System.out.println("Error! correct usage java
    PrimesServd server-host");
    should be
    System.out.println("Error! correct usage java " + 
    "PrimesServd server-host");

Similar Threads

  1. Quick Intro...
    By chris2332 in forum Member Introductions
    Replies: 2
    Last Post: January 25th, 2010, 08:50 AM
  2. Quick JComboBox Event Question
    By -tr in forum AWT / Java Swing
    Replies: 2
    Last Post: December 12th, 2009, 05:35 PM
  3. Quick binary tree question.
    By Sinensis in forum Java Theory & Questions
    Replies: 1
    Last Post: November 15th, 2009, 09:28 PM
  4. Replies: 6
    Last Post: April 14th, 2009, 08:02 AM