
Create JAR-Based Java Library for Math Utilities
Learn how to create a JAR-based Java library for math utilities using Java 5 APIs, Eclipse, and JDK. Follow a step-by-step guide to develop a simple MathUtils class with static methods like factorial. Integrate the library into Eclipse IDE and Android projects for efficient mathematical operations.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Working with Libraries UNIT UNIT - - V V
Creating Java Library JARs Creating Java Library JARs Create a JAR-based library that accesses only Java 5 (and earlier) APIs via JDK command-line tools or Eclipse. Suppose you plan to create a simple library of math-oriented utilities. This library will consist of a single MathUtils class with various static methods. // MathUtils.javapublic class MathUtils { public static long factorial(long n) { if (n <= 0) return 1; else return n*factorial(n-1); } }
MathUtils currently consists of a single static factorial() method for computing and returning factorials (perhaps for use in calculating permutations and combinations). You might eventually expand this class to support fast Fourier transforms and other math operations not supported by the java.lang.Math class. To Developing a JAR-based library with the JDK is trivial. Perform the following steps to create a mathutils.jar file that contains the MathUtils class:
1. start Eclipse IDE if not already running. 2. Select New from the File menu and Java Project from the resulting popup menu. 3. On the resulting New Java Project dialog box, enter mathutils into the Project name textfield and click the Finish button. 4. Expand Package Explorer s mathutils node. 5. Right-click the src node (underneath mathutils) and select New, followed by Package from the resulting pop-up menus. 6. On the resulting New Java Package dialog box, enter com.sjc.mathutils into the Name field and click Finish. 7. Right-click the resulting com.sjc.mathutils node and select New, followed by Class on the resulting pop-up menus.
8. On the resulting New Java Class dialog box, enter MathUtils into the Name field and click Finish. 9. Type your Code then save. 10. Right-click the mathutils project node and select Build Project from the resulting pop-up menu. (You might have to deselect Build Automatically from the project menu first.) 11. Right-click the mathutils project node and select Export from the resulting pop-up menu. 12. On the resulting Export dialog box, select JAR file under the Java node and click the Next button. 13. On the resulting JAR Export pane, keep the defaults but enter mathutils.jar in the JAR file textfield. Click Finish. The resulting mathutils.jar file is created in your Eclipse workspace s root directory.
Using Java Library JARs Using Java Library JARs You ve successfully built mathutils.jar and want to learn how to integrate this JAR file into your Eclipse-based Android projects. You ll need an Android app to try out this library Use your platform s file manager program (such as Windows XP s Windows Explorer) to select and drag the previously created mathutils.jar file to the libs node available on your Application folder Right-click mathutils.jar and select Build Path followed by Configure Build Path on the resulting pop-up menus. On the resulting Properties for UseMathUtils dialog box, select the Libraries tab and click the Add Jars button. On the resulting JAR Selection dialog box, expand the UseMathUtils node followed by the libs node. Select mathutils.jar and click OK to close JAR Selection. Click OK a second time to close Properties for your Application