JAR File Creation

You might also like

You are on page 1of 3

JAR File creation

Aim:
To write a java program to demonstrate JAR file creation

Algorithm:
Step 1: Start the program
Step 2: Create a few utility classes and Main Program, with packages, whose conglomeration
would be the JAR file, which is bound to be created.
Step 3: In driver code, utilize the facilities that are being available.
Step 4: Create the JAR file, which is conducive for the productive environment, by
annihilating the noise of the files through aggregating them into single entity, by using “jar -
cf name.jar PackageName”.
Step 5: “jar -uf name.jar PackageName” can be used to update the JAR File.
Step 6: Register the classpath of the jar file in the terminal to use the Files inside and run the
drive code.
Step 7: Stop.

Source code:
Sine.java:
package trigFun;
public class Sine {
static double z=0.0,thir=0.5,ff=0.707,sixty=0.75,nty=1.0;
public static double getValueForAngle(int ang){
switch (ang){
case 0: return z;
case 30: return thir;
case 45: return ff;
case 60: return sixty;
case 90: return nty;
default: return 0.0;
}
}
public static double calcOtherSide(Double hyp,int ang){
return (getValueForAngle(ang)*hyp);
}
}

PythagorasFun.java:
package Theorems;
public class PythagorasFun{
public static double calcValue(Double c,Double a){
return (c*c - a*a);
}
}
DriverCode.java:

package MainPackage;
import trigFun.Sine;
import Theorems.PythagorasFun;
import java.util.Scanner;
public class DriverCode {
public static void main(String[] args){
int angle;
double hyp=0.0,sideA=0.0,SideB=0.0;
Scanner inp = new Scanner(System.in);
System.out.println("This program is intended to find the perimeter of a Right-angled
Triangle with Hypotenuse and other known Values...!");
System.out.println("\n1.Hypotenuse and an otherside are known\n2.Hypotenuse and
an angle are known.\nEnter your choice:");
switch (inp.nextInt()){
case 1: System.out.println("Enter the values:");
hyp = inp.nextDouble();
sideA = inp.nextDouble();
sideB=Math.sqrt(PythagorasFun.calcValue(hyp,sideA));
break;
case 2: System.out.println("Enter the values:");
hyp = inp.nextDouble();
angle = inp.nextInt();
sideA = Sine.calcOtherSide(hyp,angle);
SideB = Math.sqrt(PythagorasFun.calcValue(hyp,sideA));
break;
} System.out.println("Perimeter:"+(hyp+sideA+SideB)+" units.");
output:

Result: Thus, the Java program to demonstrate JAR file creation, was successfully done
and output was obtained.

You might also like