JDK or JRE
The JRE (Java Runtime) is required to run a Java program. The JDK (Java Development Kit) contains JRE and development tools (such as compilers and debuggers) that are needed to write Java programs, which means that a Java program requires a JDK.
1. Installing Jdkstep on Windows 0 (a): Uninstalling older versions of JDK/JRE
Using the latest version of the JDK is recommended, and it can be messy to install multiple versions. "Control Panel" ⇒program and features⇒ Uninstall "Java SE development Kit" and "Java SE Runtime"
Step 0 (b): To understand Windows CMD shell
If you don't understand, see the way Windows programmers survive
Step 1: Download the JDK
- Download JDK, click here
- In the JDK in Java SE 8ux, click the Download button
- Don't forget to tick "agree."
- Select version x86 or x64
Step 2: Install the JDK and JRE
Double click on the downloaded EXE, all the way next, installation is complete
Step 3: Configure system Environment variables
Start⇒control panel⇒system⇒ (VISTA/7/8) Advanced System setting⇒environment variables⇒ Edit Path
Variable name:PATHVariable value:c:\Program Files\Java\jdk1.8.0_xx\bin;
Edit Java_home,jre_home,classpath (Dt.jar, Tools.jar)
Step 4: Verify the installation of the JDK
- Go to cmd and enter path return:
prompt> **path** PATH=**c:\Program Files\Java\jdk1.8.0_xx\bin;**[other entries]
Input java-version, javac-version
prompt> **java -version** java version "1.8.0_xx" Java(TM) SE Runtime Environment (build 1.8.0_xx-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) prompt> **javac -version** javac 1.8.0_xx
Step 5: Write the test program Hello.java /* * First Java program to say Hello */ public class Hello { // Save as "Hello.java" under "d:\myproject" public static void main(String[] args) { System.out.println("Hello, world!"); } }
Run it:
**javac Hello.java** **java Hello** Hello, world!
Step 6: Download the JDK API documentation demos and samplesHttp://www.oracle.com/technetwork/java/javase/downloads/index.html
2. Install JDK on UbuntuSee: Installing JDK on Ubuntu
The above is just a simple explanation, there is no dry goods, the following is what I want
3. Use of local libraries and external jar filesExternal Java packages, such as Servlets, MySQL, connector, are typically published in a jar package (Jar:java Archive, a single package containing multiple Java classes) and may be accompanied by a local library (". Lib" and ". dll" under Windows), Linux/mac under ". A" and ". So")
External jar file (". Jar")
If the external jar file is not properly introduced:
- During the compile phase, you will receive a compilation error that the "can not find Symbol" class belongs to the external package
- Run phase, you will receive a run-time error "Could not find or Load main class xxx" or "noclassdeffounderror"
You can do this with a jar file:
Copy all the external jar files into the Java extension directory.
- This directory on Windows is "<java_home>\jre \lib\ext".
- The directory on the Mac is "/library/java/extensions" and "/system/library/java/extensions".
- Ubuntu This directory is in "<java_home>\jre \lib\ext" and "/usr/java/packages/lib/ext"
The Java extension directory is stored in the Java System Properties "Java.ext.dirs" and can be printed using the following code:
System.out.println (System.getproperty ("Java.ext.dirs")).
With the CLASSPATH environment variable containing the jar file, the classpath can contain directories (directories containing Java classes) or jar files. If you set Classpath, you must also include the current directory (using "." Identification).
- Under Windows, Control panel⇒system⇒advanced System settings⇒advanced⇒environment variables⇒system variables⇒new⇒ in "Variable name", enter "CLASSPATH" ⇒ "enter" in "Variable value".; Path1\xxx.jar;path2\yyy.jar ".
- Under Linux and Mac, edit ~/.profile or ~/.bash_profile (or/etc/profile system-wide settings) to add the following code at the end of the file:
Export classpath=.:p Ath1/xxx.jar:path2/yyy.jar
When using the command, add the jar file via-CP classpath, as follows:
// Compile Java source code > javac -cp .:path1/xxx.jar:path2/yyy.jar ClassName.java // Run Java class > java -cp .:path1/xxx.jar:path2/yyy.jar ClassName
External local libraries (. dll,. lib,. So,. a)Some external packages may provide a static or dynamic local package, and the directory where the local library resides is available through the JRE attribute "Java.library.path", which generally contains all the directories in the PATH environment variable but is not required.
Java does not introduce a local library at compile time, but if it is not set correctly, it will error "Java.lang.UnsatisfiedLinkError:no xxx in Java.library.path" at run time.
You can include a local library like this:
- Copy the local library to the system library directory, such as: C:\Windows \system32 (Windows),/usr/lib or/usr/local/lib (Linux, Mac)
- The runtime uses-djava.library.path=xxx, such as:
> java -Djava.library.path=xxx ClassName
Article See here
How to install JDK 7/8 and Java programming