Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

eclipse

ide

I've started Coursera Algorythms course. Practice assignments must be done on Java and they suggest using DrJava as IDE, but it's really unconvenient. So I'd like to use Eclipse, but the problem is that I couldn't use 2 libraries(algs4.jar and stdlib.jar), which are provided for this course. After doing steps from this guide I was able to include them in my project:

enter image description here

but when I try to use their classes in my project, Eclipse doesn't allow to do it, and I couldn't import them by Ctrl + Space:

enter image description here

And even when I am trying directly import class like import stdlib.StdRandom; it still doesn't work.

What can I do to make it work properly?

like image 418
Seekeer Avatar asked Feb 21 '13 17:02

Seekeer


People also ask

How to add algs4 JAR to the Java?

Download stdlib. jar and algs4. jar to a folder and add each jar >file to the classpath variable to the build path of a project via Project -> >Properties -> Java Build Path -> Libaries -> Add External JARs.

Are coursera algorithms good?

Simply awesome, the slides, lecture and assignments are very good. The assignments are challenging and difficult, but just enough for you to finish them and improve yourself. I would definitely recommend this course to every programmer I know.

How do I install algs4?

Log in to the user account in which you will be programming. Your account must have Administrator privileges and you must be connected to the Internet. Download algs4.exe and double-click it to perform the installation.


2 Answers

Why don't 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 can't 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 my test success

like image 195
MorningFung Avatar answered Sep 22 '22 10:09

MorningFung


You can't access the APIs because the authors have defined them in the default package and Java doesn't 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!

like image 37
OVB Avatar answered Sep 26 '22 10:09

OVB