Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8428681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:07:22+00:00 2026-06-10T05:07:22+00:00

I am absolutely new to Java and having trouble referencing a class that I

  • 0

I am absolutely new to Java and having trouble referencing a class that I have declared in another .java file. I read a lot about it on the Oracle Website and also many stackoverflow questions, but couldn’t solve the problem. Here are the steps I have taken:

Set the class path.
I am running this on UNIX. So I typed in
% java -classpath /users/myUserName/algs4/assignment1. Instead of changing the class path it gives me a long list of other options.

Include the ‘package name’ in each of my .java files which have class definitions I want to refer to.

I also ensured that all my files that I want to refer are in the same directory.
Here is some of my code:

package assignment1;
public class Percolation
{
    private int[][] grid;
    ....
    //Other method definitions etc.
   public Percolation(int N)
   {
      uf = new WeightedQuickUnionUF(N);
      grid = new int[N][N];
      ...
      //Other code

   }

 }

My WeightedQuickUnionUF class is also defined as:

package assignment1;
public class WeightedQuickUnionUF {
    private int[] id;    // id[i] = parent of i
    private int[] sz;    // sz[i] = number of objects in subtree rooted at i
    private int count;   // number of components

    //Create an empty union find data structure with N isolated sets.
    public WeightedQuickUnionUF(int N) {
        count = N;
        id = new int[N];
        sz = new int[N];
        for (int i = 0; i < N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
     }
}

But now when I compile using javac Percolation.java. It gives me the errors:

Percolation.java:7: cannot find symbol
symbol  : class WeightedQuickUnionUF
location: class assignment1.Percolation
WeightedQuickUnionUF uf;
^

I get it that it is because the compiler doesn’t know what is the class WeightedQuickUnionUF. It cannot refer it. But how do I do it then? I have already tried the popular solutions.

I am not using any IDE. Just a text editor and then compiling it on the terminal.

(algs4 folder has files like stdlib.jar and others)

EDIT: I missed the ‘new’ keyword. I have added that. Also I am compiling my WeightedQuickUnionUF class before Percolation.java

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:07:23+00:00Added an answer on June 10, 2026 at 5:07 am

    The java command is not setting the classpath but trying to run a java class. That’s why the long option list.

    You can specify the classpath upon compilation: run javac -classpath . assignment1/Percolation.java from the algs4 directory. Pay attention to the dot it means current directory.

    There is no need to compile the files in order.

    To run your program: java -cp . assignment1.Percolation from the algs4 directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application written in Java that uses a jar file(it uses more
I have a voice input class that works absolutely great. However, I want the
Instead of absolutely positioning (I have to do that, don't ask why) elements over
Java lets you create an entirely new subtype of Throwable , e.g: public class
I have a java web app that makes back-end use of a third-party web
I'm new to creating apps on Android with Eclipse and having a little trouble
I'm absolutely new to GWT, java and eclipse, but I'm an experienced MS programmer.
I'm fairly new to Java & Android, so I have little idea what I
I'm new to Java. I use Eclipse IDE. I have such structure of packages
So in Java I had a class that contained a HashMap that used the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.