JAVA learning step 2 - project creation and package import

1 JAVA execution principle

Running java is actually very simple, 3 steps: 1 you write the code, 2 compile it directly with the compiler, 3 execute it with the virtual machine; just these 3 steps are enough, the editor just embeds the virtual machine, so your code It can be run directly, and there is actually a compilation step.

1.1 Project organization

1 The organization method of java project is: project-folder-package-class
Insert image description here

2. The jar package is a third-party library. You can directly use the classes written by them in the editing tool.

1.2 From creation to execution (6 steps)

1 Use idea or eclipse to create a project
2 Introduce the required jar package
3 Write java class
4 Test
5 Package into a JAR package
6 Run the jar package directly on Linux through the command java -jar jar package name

1.3 Cross-platform

1 Java is a cross-platform language and requires only two steps. First, javac compiles the .java source code into a .class file; second, it can be executed directly using the java virtual machine.

2 Whether on Windows, Linux or Mac, you only need to download the corresponding JDK tool package and virtual machine, and it can run your .class file or JAR package. It’s just that the Java virtual machines on different platforms are different. The virtual machine is equivalent to a converter that is proficient in different platform languages, so that the code you write can run on different platforms. Your code does not need to be modified.

2 5 ways to create Java projects

2.1 Write directly in writing

2.2 Using Eclipse

1 Create project
2 Create module
3 Import JAR package
4 Create package
5 Write class

2.3 Using IDEA

Insert image description here

2.4 Eclipse creates maven project

2.5 IDEA creates maven project

3 JAR package (a class written by someone else)

A JAR package is a compressed package composed of classes written by others and compiled into .class files and some dependent files.
A JAR package can be composed of one class or multiple classes and configuration files.

3.1 Import the JAR package (all 4 methods are acceptable)

3.1.1 Normally put the jar package directly into a directory

This is not recommended, you don’t need to know

3.1.2 Eclipse imports JAR package

3 ways to import external jar packages under Eclipse Jar
package import and source folder creation

3.1.3 IDEA manually imports JAR packages

(1) Create a folder
(2) Add the jar package to the folder
(3) Right-click the folder and select Add as Library
to add the configuration jar package to IDEA
Intellij IDEA Three ways to add jar packages

3.1.4 MAVEN project organization JAR package

The JAR package in maven has a local warehouse, and the remote warehouse can store the JAR package.
Several ways to import jar packages under Maven

Create a maven project and use it in pom.xml
Insert image description here

3.2 Package into JAR package

3.2.1 Pack the jar package using ordinary commands

Several ways to package jar packages in Java. Detailed explanation of
how to package jar packages in Java.

3.2.2 Eclipse package jar package

I used the third method in the first link below, which is to install the Eclipse packaging plug-in Fat Jar, and completed the packaging, which was very convenient.

1 How to create Jar package in Eclipse - Qin Shimingyue 0515 - Blog Park

2 Three ways to package eclipse projects

3.2.3 IDEA packaging JAR package

1 Detailed graphic tutorial on using IDEA to build jar packages

3.2.4 MAVEN packaging

Hadoop_MapReduce_WordCount case cluster operation

(1) Directly package the environment without a third-party JAR package
(2) Package the supporting JAR package and environment together, and introduce the packaging plug-in file in pom.xml. In this way, the supporting environment can be packaged together

3.3 Run the JAR package

How to create Jar package with Eclipse and run it

Java uses the command to run the main method under the specified class of the jar package_Fengfeng's Blog-CSDN Blog_java runs the jar package to specify main

java -jar package name will do
Insert image description here

4 WAR packages

5 shortcut keys

1 Eclipse common shortcut keys | Novice tutorial
2 IDEA common shortcut keys collection (very detailed)
3 IDEA common shortcut keys collection - yanggb - Blog Park
4 IDEA shortcut keys collection

Guess you like

Origin blog.csdn.net/xiaotiig/article/details/126894128