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

前端 未结 10 903
挽巷
挽巷 2020-12-23 12:44

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

相关标签:
10条回答
  • 2020-12-23 12:58

    If you are anyone still looking for the solution :-

    OS X / Linux

    % javac -cp .:stdlib.jar MyProgram.java % java -cp .:stdlib.jar MyProgram

    Windows

    % javac -cp .;stdlib.jar MyProgram.java % java -cp .;stdlib.jar MyProgram

    For refrence :- https://introcs.cs.princeton.edu/java/stdlib/

    0 讨论(0)
  • 2020-12-23 12:59

    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

    0 讨论(0)
  • 2020-12-23 13:02

    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!

    0 讨论(0)
  • 2020-12-23 13:02

    I'm using Gradle. In this case the build.gradle file should have a dependency and can look like

    repositories {
        jcenter()
    }
    
    dependencies {
        compile 'edu.princeton.cs:algs4:1.0.3'
    }
    

    After this you can import anything from it in your class. For example:

    import edu.princeton.cs.algs4.StdIn;
    
    0 讨论(0)
  • 2020-12-23 13:03

    From their website: http://algs4.cs.princeton.edu/code/

    Eclipse (manual). 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.

    0 讨论(0)
  • All you should have to do in order to include the JARs is right click on the top of your project/object tree in the project explorer panel on the left, do "Build Path/Configure Build Path", click "Libraries" tab, and "add external jars", add them there.

    They should happily become available both while editing your source code and while building it in Eclipse after that.

    Also note that, assuming you have the class name right when you type, you should be able to hover over the class name in your code and the intelli-sense/auto-complete feature will suggest where you should import it from. You can add the import to the correct library that way with ease.

    0 讨论(0)
提交回复
热议问题