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

  • Home
  • SEARCH
  • 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 8453727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:50:10+00:00 2026-06-10T11:50:10+00:00

This might be a very simple problem indeed, but I am absolutely new to

  • 0

This might be a very simple problem indeed, but I am absolutely new to Java, and not getting how to resolve it.

I have a stdlib.jar file which has some Classes defined like StdRandom and I have to to use them in my program. I read, that to use files like stdlib.jar I have to use the default package. So I removed the “package algs4” from my program below. But it didn’t work.

package algs4;
public class PercolationStats
{
   //Some method declarations
   public static void main(String[] args)
   {
      //Some code
      for(int counter=0; counter<T; counter++)
      {
        while(!p.percolates())
        {
            iIndex = StdRandom.uniform(N);
            jIndex = StdRandom.uniform(N);
            ...
        }
      }



} 

Every time I compile this program using:

javac -cp . algs4/PercolationStats.java

I get the error:

algs4/PercolationStats.java:30: cannot find symbol
symbol  : variable StdRandom
location: class algs4.PercolationStats
                iIndex = StdRandom.uniform(N);

I also tried to compile using:

javac -cp .:stdlib.jar algs4/PercolationStats.java

But the error remains same.

Though it is not a good practice, I also extracted the files from the .jar file, which gave me the StdRandom.java file, but it still doesn’t work.

All my files including the stdlib.jar are in the same directory.

How should I go about it?

EDIT: Just to make the question more elaborate for any future references: stdlib.jar used in the program was in a “default” package.

  • 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-10T11:50:12+00:00Added an answer on June 10, 2026 at 11:50 am

    EDIT: If StdRandom isn’t in a package, then you may indeed need to take your code out of a package too. (I’ll give it a try – it’s a long time since I’ve had to work with a class which wasn’t in a package.)

    In general, it would be much better to get a version of stdlib.jar which had the classes in packages.


    We don’t know what package StdRandom is in. You probably just want an import statement:

    import foo.bar.StdRandom;
    

    … where foo.bar is the package containing StdRandom. Alternatively, you can import all the classes in a package with a wildcard:

    import foo.bar.*;
    

    See the “Creating and using packages” part of the Java tutorial for more details.

    You’ll definitely need to have stdlib.jar in your classpath though, so stick to your second compilation approach.

    You might also want to consider using an IDE (e.g. Eclipse) which can make all of this easier for you, and even work out import statements on demand.

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

Sidebar

Related Questions

This might be a very simple thing for you gurus, but I'm not familiar
This might be a very simple question, but I could not find the answer
I know this might be very easy to some,, I have a simple string
I know it might be a very simple solution for this, but I am
I know, this might be a very basic question but I am not 100%
I'm not very used to javascript's prototyping syntax so this might be very simple.
I suspect this might be a very simple mistake but I've spent 3 hours
It might be very simple but I think I am missing something. I have
maybe this might be a simple problem but after a long while at Google
This might be very simple; I don't know Rails very well. I have a

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.