Small knowledge of Java se -- how to export and use the jar toolkit written by yourself

Article catalog

The road to becoming a God is long and lonely. Today, I share a little knowledge about how to export and use the toolkit I wrote through the tool Eclipse into classes

preface

Tip: Here you can add the general contents to be recorded in this article:
For example, with the continuous development of artificial intelligence, machine learning technology is becoming more and more important. Many people have started learning machine learning. This paper introduces the basic content of machine learning.

Tip: the following is the main content of this article. The following cases can be used for reference

1, The necessity of writing jar packages

Speaking of toolkit, it is used all the time in today's java programming language, jdk1 Many toolkits are provided in version 8, which are made by Jar end file, Our developers have given a unified name "jar package", which is a term for a tool. The purpose is that when you write code, you can import it through the import keyword, and then use the tools inside to complete the project writing. However, not all rack packages can be applicable to your needs (it's still applicable most of the time. I say this to continue my next topic ~ ~). Therefore, developers with certain development experience will finally write some of their own toolkits to facilitate their future project writing. Today, through learning, I learned to use eclipse tools to export their own array tool class jar package, which will be discussed here Share it with you.

2, Writing steps

1. Open the development tool eclipse and create

I believe everyone has downloaded this development tool, so I won't explain it too much

As above, create the corresponding package after creating the project. The package name can be determined by yourself, and then create the class [MyArrays.java] under this package. The source code is as follows:

package com.yzy.array;

/**
 * Write basic and commonly used array tool classes independently
 * @author Yong Zhongyang
 * @version 1.0
 *
 */
public class MyArrays {
	/**
	 * Sorting method
	 * bubble sort 
	 * @param is An array needs to be passed in
	 * @author Yong Zhongyang
	 */	
	public static void sort(int[] is) {
		for (int i = 0; i < is.length - 1; i++) {
			for (int j = 0; j < is.length-1 - i; j++) {
				if (is[j] > is[j + 1]) {
					int temp = is[j];
					is[j] = is[j + 1];
					is[j + 1] = temp;
				}
			}
		}
		for (int i : is) {
			System.out.print(i+",");
		}
	}
	
	/**
	 * Method of copying array
	 * @param is target array
	 * @param newLenth New length
	 * @return Returns a new array
	 */
	public static int[] copyOf(int[]is,int newLenth) {
		
		int [] newIs=new int[newLenth];
		for(int i=0;i<is.length;i++) {
			newIs[i]=is[i];
		}
		
		return newIs;
	}
	
	/**
	 * Gets the maximum value of the array
	 * @param is
	 * @return
	 */
	public static int getMax(int [] is) {
		int max=is[0];
		for (int i=1;i<is.length;i++) {
			if(max<is[i]) {
				max=is[i];
			}
			
		}
		return max;
	}
	/**
	 * Get minimum value
	 * @param is
	 * @return
	 */
	public static int getMin(int [] is) {
		int min =is[0];
		for(int i=1;i<is.length;i++) {
			if(min>is[i]) {
				min=is[i];
			}
		}
		return min;
	}
	/**
	 * Gets the string representation of the character
	 * @param is
	 * @return
	 */
	public static String toString(int[]is) {
		String str="[";
		
		for(int num:is) {
			if(str.length()!=1) {
				str+=",";
			}
		}
		str+="]";
		return str;
	}
}

2. Export operation

Right click Util project--->Exportant-->java-->JAR file-->Util-->Select save path (custom)-->Select Save name

The specific operations are as follows:




2. How to use your own jar package

First, you need to select a project file, create an array class, and import the package we wrote ourselves
The specific operations are as follows:

Create the lib project file under the target file and drag the written jar package into it

//Test item code
package com.yzy.test01;

import com.yzy.array.MyArrays;

/**
 * 
 * @author Yong Zhongyang
 *
 */

public class Test01 {
	public static void main(String[] args) {
		/**
		 * Test your own jar toolkit
		 */
		int [] num= {1,5,3,4,2};
		//Use the method sort (bubble sort) under MyArrays
		MyArrays.sort(num);
			
	}

}


4. Summary

We can see that our operation is successful. We can use our own jar package. In the future, we can use this method more when writing projects to improve our ability. In order to become stronger, we must learn some small technologies. Don't just know to write code and be a code farmer. It's meaningless for development. Climbing up step by step is the key.

summary

Recently, due to my physical discomfort, I may delay the work and fill it in the future.

Keywords: Java Eclipse

Added by luv2sd on Sat, 25 Dec 2021 08:53:42 +0200