Simple use of java -classpath command

xiaoxiao2021-04-04  278

A question of students always asked when class in the first two days: About compiling and executing the Java program, because they don't have administrator privileges, there is no way to add the system's classpath. So you can only use Javac and Java command to get parameters - ClassPath C: /a.java

Package love; public class a {public void f () {system.out.println ("AF ()");} public static void main (string args []) {a a1 = new a (); A1.f ( ); } } what! The class name is purely to knock! Good compilation: E: /> javac -dc: / c: /a.java explanation: E: /> java -classpath c: / love.a Result: AF () Simple! Pay attention to space A, many people are because they have not knocked the space! It's not good to make it! All right! Now in D: / build a B.java, lazy people can't do any way, but it is very effective! B.Java:

Import love.a; class b {public static void main (string args []) {a a1 = new a (); a1.f ();}} compile: E: /> javac -classpath C: / D: / B.Java Interpretation Execution: E: /> Java-ClassPath C: /; D: / B Results: AF () After the collection, in fact, whether it is Javac or java command, it is a Class in the Pacakge you want to use. Introducing in ClassPath, as for the principle, there are only people who can write books in the book, I feel too simple! All right! Withdraw! Also, I have to open Java & XML recently! I have to pay attention to it! what!

转载请注明原文地址:https://www.9cbs.com/read-131773.html

New Post(0)