Revision for “NM Dev Setup Guide” created on June 28, 2021 @ 05:47:42
NM Dev Setup Guide |
<h1 id="SetupGuide">Setup Guide</h1> This tutorial is on how to set up the development environment for programming with the NM Dev library (the Java version). In order to use the NM Dev library, you need to know some Java programming. Sun (or Oracle) provides excellent online tutorials on learning Java. You can find a lot of easy-to-read-and-follow lessons in <a class="ext-link" href="http://java.sun.com/docs/books/tutorial/"><span class="icon"></span>Sun’s Java Tutorials</a>. <h2 id="IDE">IDE</h2> You will need an Integrated Development Environment (IDE) to program NM Dev. Although you may choose any IDE you like, we recommend Netbeans. You can download it from <span class="icon"></span><a href="https://netbeans.apache.org/download/nb124/nb124.html">here</a>. <img class="aligncenter size-full wp-image-18554" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.02.51-PM.png" alt="" width="2622" height="1226" /> To learn about how to use <a href="http://numericalmethod.com/up/netbeans/" target="_blank" rel="noopener noreferrer">NetBeans</a>, you will find a quick start tutorial <a class="ext-link" href="http://netbeans.org/kb/docs/java/quickstart.html"><span class="icon"></span>here</a>. The most important skill for you to learn is debugging. This is especially true for those who are converting from Matlab and R and are used to printing out values. <a href="http://numericalmethod.com/up/netbeans/" target="_blank" rel="noopener noreferrer">NetBeans</a> debugger allows you to easily inspect values, place conditional breakpoints, pause and resume your program and much more. A quick Google search gives these articles. Hotkey is another tool that will increase your programming productivity. My favorite hotkey is <tt>Ctrl+Shift+F</tt> (or <span style="font-family: ‘andale mono’, monospace">Alt+Shift+f</span> if you are using windows). It makes my code look pretty and neat. A list of hotkeys is found <a class="ext-link" href="http://netbeanside61.blogspot.com/2008/04/top-10-netbeans-ide-keyboard-shortcuts.html"><span class="icon"></span>here</a>. You can customize them to your own taste by going to Netbeans -> Preferences -> Keymap (or Tools -> Options -> Keymap for Windows/Linux). <img class="aligncenter size-full wp-image-18556" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.18.33-PM.png" alt="" width="1560" height="1334" /> This section walks you through how to set up a NM Dev project. You may skip this section if you want to start programming NM Dev right away using the <a href="https://nm.dev/s2/">S2 IDE</a> which comes in-built with NM Dev. Please read our <a href="http://numericalmethod.com/up/suanshu/tutorial/" target="_blank" rel="noopener noreferrer">Basic Trails</a> to get started. If in the future you would like to update the NM Dev library for a newer version, you will need to come back to this section. <img class="aligncenter size-full wp-image-18557" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.28.14-PM.png" alt="" width="1428" height="1020" /> In ‘Project Name’, type whatever you like, e.g., HelloNMDev. In ‘Project Location’, type where you would like to save your project. Make sure the box ‘Use dedicated Folder for Storing Libraries’ is checked.Then click ‘Finish’. <img class="aligncenter size-full wp-image-18558" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.30.51-PM.png" alt="" width="1428" height="1020" /> We need to tell this Java project that we will be calling the NM Dev library. To do so, right click on the ‘Libraries’ Folder in the project tab and click ‘Add JAR/Folder’ <img class="aligncenter size-full wp-image-18560" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.41.59-PM.png" alt="" width="980" height="570" /> Browse to where you saved nmdev.jar. Select nmdev.jar and then hit ‘Open’. <img class="aligncenter size-full wp-image-18561" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.46.21-PM.png" alt="" width="1324" height="938" /> To install the NM Dev javadoc in <a href="http://numericalmethod.com/up/netbeans/" target="_blank" rel="noopener noreferrer">NetBeans</a>, we need to associate the nmdev.jar with its javadoc. Right click the nmdev.jar file you just added and select ‘Edit’. <img class="aligncenter size-full wp-image-18562" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.48.42-PM.png" alt="" width="962" height="560" /> In the popup window, under the ‘javadoc’ section, click ‘Browse’ and select the nmdev-javadoc.jar file. Then click ‘Open’. <img class="aligncenter size-full wp-image-18563" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.52.43-PM.png" alt="" width="1038" height="390" /> Now, you have created an empty NM Dev project. Copy and paste these lines under "<tt>// TODO code application logic here</tt>". [box type="shadow"] System.out.println("Hello NM Dev"); Matrix A1 = new DenseMatrix(new double[][]{//create a matrix {1, 2, 1}, {4, 5, 2}, {7, 8, 1} }); System.out.println(A1); Matrix B = new Inverse(A1);//compute the inverse of A1 Matrix I = A1.multiply(B);//this should be the identity matrix System.out.println(String.format("%s * %s = %s (the identity matrix)", A1, B, I)); [/box] <img class="aligncenter size-full wp-image-18564" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-2.58.07-PM.png" alt="" width="1734" height="1488" /> Hit <tt>Command+Shift+I </tt>(or <tt>Ctrl+Shift+I</tt> on Windows/Linux) to fix the necessary imports. Make sure these statements appear at the top of your program. Else you can input them manually. [box type="shadow"] <span style="font-family: -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, Oxygen-Sans, Ubuntu, Cantarell, ‘Helvetica Neue’, sans-serif">import dev.nm.algebra.linear.matrix.doubles.Matrix; <span style="font-family: -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, Oxygen-Sans, Ubuntu, Cantarell, ‘Helvetica Neue’, sans-serif">[/box]</span> Hit <tt>Alt+Shift+F</tt> to beautify your code. Your code should look something like this. <img class="aligncenter size-full wp-image-18566" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-3.05.50-PM.png" alt="" width="1734" height="1510" /> Before you can run your code you will have to place your license file by doing [box type="shadow"] <span style="font-family: -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, Oxygen-Sans, Ubuntu, Cantarell, ‘Helvetica Neue’, sans-serif">import dev.nm.misc.license.License;</span> License.setLicenseFile(new java.io.File("your license path")); <span style="font-family: -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, Oxygen-Sans, Ubuntu, Cantarell, ‘Helvetica Neue’, sans-serif">[/box]</span> <img class="aligncenter size-full wp-image-18567" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-3.13.15-PM.png" alt="" width="1734" height="1568" /> Right click on the project name, e.g., HelloNMDev, and click ‘Run’ (or simply press <tt>F6</tt> if you make this project your main project). Voila! You should see this in your output window (<tt>Ctrl+4</tt>). <img class="aligncenter size-full wp-image-18568" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-3.15.51-PM.png" alt="" width="1504" height="872" /> Congratulations! <img class="aligncenter size-full wp-image-18569" src="https://nm.dev/wp-content/uploads/2015/04/Screenshot-2021-06-17-at-3.19.22-PM.png" alt="" width="1572" height="1396" /> To get more information about programming NM Dev, please consult our <a href="https://nm.dev/wiki/tutorials/">tutorials</a>. |