java – How to use libraries for Algorithms part I Coursera course in Eclipse

java – How to use libraries for Algorithms part I Coursera course in Eclipse

Why dont you use these two JARs—— stdlib-package.jar and algs4-package.jar.

And below the code page(http://algs4.cs.princeton.edu/code/)

Q. If I use a named package to structure my code, the compiler can no longer access the libraries in stdlib.jar or algs4.jar. Why not?

A. The libraries in stdlib.jar and algs4.jar are in the default package. In Java, you cant access classes in the default package from a named package. If you need to use our libraries with a named package, you can use these package versions: stdlib-package.jar and algs4-package.jar.

Warning: if you are taking Princeton COS 226 or Coursera, Algorithms, Part I or II, you must use the default package verison of our libraries to facilitate grading.

Showing my test success:
Showing

You cant access the APIs because the authors have defined them in the default package and Java doesnt recognize these. The authors mention on their website (http://algs4.cs.princeton.edu/code/) that if you are using these in named packages, configure your build path to include the jar from http://algs4.cs.princeton.edu/code/algs4.jar.

HTH!

java – How to use libraries for Algorithms part I Coursera course in Eclipse

Follow the below steps

Right click on your project > Properties. It will open the following window

enter

Select Java Build Path from the left side. Now select Libraries tab from the right side

enter

Click on Add External Jars

enter

Add the Jar files.

Now you are done

Leave a Reply

Your email address will not be published.